<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :sm="8" :xs="24">
          <a-form-item label="游戏" field="game_id">
            <game-select v-model="searchForm.game_id" multiple />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item label="注册日期" field="reg_date">
            <a-date-picker class="w-full" v-model="searchForm.reg_date" :show-time="false" mode="date" />
          </a-form-item>
        </a-col>
      </template>

      <!-- Table 自定义渲染 -->
    </sa-table>
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import api from '../../api/gameLog/analyse'
import dayjs from 'dayjs'
import GameSelect from '@/components/game-select/index.vue'
import MediaSelect from '@/components/media-select/index.vue'
import AuthSelect from '@/components/auth-select/index.vue'

// 引用定义
const crudRef = ref()
const gameList = ref([])

// 搜索表单
const searchForm = ref({
  game_id: '',
  reg_date: '',
})

// SaTable 基础配置
const options = reactive({
  api: api.getIncomeAnalysis,
  pk: 'date',
  showSort: false,
  showSummary: true,
  operationColumn: false,
  summary: [
    {
      action: 'totalRow',
      dataIndex: 'tdate',
    },
    {
      action: 'totalRow',
      dataIndex: 'game_id',
    },
    {
      action: 'totalRow',
      dataIndex: 'login_total',
    },
    {
      action: 'totalRow',
      dataIndex: 'pay_total',
    },
    {
      action: 'totalRow',
      dataIndex: 'pay_num',
    },
    {
      action: 'totalRow',
      dataIndex: 'pay_arpu',
    },
    {
      action: 'totalRow',
      dataIndex: 'pay_ratio',
    },
    {
      action: 'totalRow',
      dataIndex: 'yestoday_pay_total',
    },
    {
      action: 'totalRow',
      dataIndex: 'pay_increase_yestoday',
    },
    {
      action: 'totalRow',
      dataIndex: 'pay_increase_week',
    },
  ],
})

// SaTable 列配置
const columns = reactive([
  { title: '游戏ID', dataIndex: 'game_id', width: 70, fixed: 'left' },
  { title: '游戏名', dataIndex: 'game_name', width: 140, fixed: 'left' },
  {
    title: 'DAU',
    dataIndex: 'login_total',
    width: 90,
  },
  {
    title: '付费人数',
    dataIndex: 'pay_num',
    width: 90,
  },
  {
    title: '付费金额',
    dataIndex: 'pay_total',
    width: 90,
  },
  {
    title: 'ARPU',
    dataIndex: 'pay_arpu',
    width: 90,
  },
  {
    title: '收入比例',
    dataIndex: 'pay_ratio',
    width: 90,
  },
  {
    title: '昨日充值',
    dataIndex: 'yestoday_pay_total',
    width: 90,
  },
  {
    title: '昨日增长',
    dataIndex: 'pay_increase_yestoday',
    width: 90,
  },
  {
    title: '上周增长',
    dataIndex: 'pay_increase_week',
    width: 90,
  },
])

// 页面数据初始化
const initPage = async () => {
  searchForm.value.reg_date = dayjs().subtract(1, 'day').format('YYYY-MM-DD')
}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>

<script>
export default { name: 'v1/analyse/pay' }
</script>
