<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-range-picker class="w-full" v-model="searchForm.reg_date" :show-time="false" mode="date" />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item label="媒体类型" field="media_id">
            <media-select v-model="searchForm.media_id" />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item label="渠道ID" field="agent_id">
            <a-input v-model="searchForm.agent_id" placeholder="请输入渠道ID" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item label="广告位ID" field="site_id">
            <a-input v-model="searchForm.site_id" placeholder="请输入广告位ID" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item label="负责人" field="auth_id">
            <auth-select v-model="searchForm.auth_id" multiple />
          </a-form-item>
        </a-col>
      </template>

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

<script setup>
import { onMounted, ref, reactive } from 'vue'
import api from '../../api/gameLog/channelAnalysis'
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: '',
  media_id: '',
  auth_id: '',
  agent_id: '',
  site_id: '',
  reg_date: [],
})

// SaTable 基础配置
const options = reactive({
  api: api.getActiveList,
  pk: 'id',
  rowSelection: { showCheckedAll: true },
  showSort: false,

  operationColumn: false,
})

// SaTable 列配置
const columns = reactive([
  { title: '日期', dataIndex: 'tdate', width: 120, fixed: 'left' },
  { title: '注册数', dataIndex: 'reg', width: 120, fixed: 'left' },
  { title: '1', dataIndex: 'd1', width: 120 },
  { title: '2', dataIndex: 'd2', width: 120 },
  { title: '3', dataIndex: 'd3', width: 120 },
  { title: '4', dataIndex: 'd4', width: 120 },
  { title: '5', dataIndex: 'd5', width: 120 },
  { title: '6', dataIndex: 'd6', width: 120 },
  { title: '7', dataIndex: 'd7', width: 120 },
  { title: '8', dataIndex: 'd8', width: 120 },
  { title: '9', dataIndex: 'd9', width: 120 },
  { title: '10', dataIndex: 'd10', width: 120 },
  { title: '11', dataIndex: 'd11', width: 120 },
  { title: '12', dataIndex: 'd12', width: 120 },
  { title: '13', dataIndex: 'd13', width: 120 },
  { title: '14', dataIndex: 'd14', width: 120 },
  { title: '15', dataIndex: 'd15', width: 120 },
  { title: '16', dataIndex: 'd16', width: 120 },
  { title: '17', dataIndex: 'd17', width: 120 },
  { title: '18', dataIndex: 'd18', width: 120 },
  { title: '19', dataIndex: 'd19', width: 120 },
  { title: '20', dataIndex: 'd20', width: 120 },
  { title: '21', dataIndex: 'd21', width: 120 },
  { title: '22', dataIndex: 'd22', width: 120 },
  { title: '23', dataIndex: 'd23', width: 120 },
  { title: '24', dataIndex: 'd24', width: 120 },
  { title: '25', dataIndex: 'd25', width: 120 },
  { title: '26', dataIndex: 'd26', width: 120 },
  { title: '27', dataIndex: 'd27', width: 120 },
  { title: '28', dataIndex: 'd28', width: 120 },
  { title: '29', dataIndex: 'd29', width: 120 },
  { title: '30', dataIndex: 'd30', width: 120 },
  { title: '45', dataIndex: 'd45', width: 120 },
  { title: '60', dataIndex: 'd60', width: 120 },
  { title: '90', dataIndex: 'd90', width: 120 },
  { title: '120', dataIndex: 'd120', width: 120 },
])

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

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

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

<script>
export default { name: 'v1/channelAnalysis/active' }
</script>
