<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm" @search="handleRequestData">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :sm="6" :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="6" :xs="24">
          <a-form-item label="注册日期" field="tdate">
            <a-range-picker class="w-full" v-model="searchForm.tdate" :show-time="false" mode="date" />
          </a-form-item>
        </a-col>
        <a-col :sm="6" :xs="24">
          <a-form-item label="媒体类型" field="media_id">
            <media-select v-model="searchForm.media_id" />
          </a-form-item>
        </a-col>
        <a-col :sm="6" :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="6" :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="6" :xs="24">
          <a-form-item label="负责人" field="auth_id">
            <auth-select v-model="searchForm.auth_id" multiple />
          </a-form-item>
        </a-col>
        <a-col :sm="6" :xs="24">
          <a-form-item label="分组" field="group">
            <a-select v-model="searchForm.group" placeholder="请选择分组" allow-clear>
              <a-option value="">按渠道ID</a-option>
              <a-option :value="1">按游戏ID</a-option>
              <!-- <a-option :value="4">按游戏组</a-option> -->
              <a-option :value="2">按负责人</a-option>
              <a-option :value="3">按渠道组</a-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :sm="6" :xs="24">
          <a-form-item label="忽略" field="filter">
            <a-checkbox-group v-model="searchForm.filter">
              <a-checkbox value="igz">忽略0投入</a-checkbox>
              <a-checkbox value="fak">忽略后台录入</a-checkbox>
            </a-checkbox-group>
          </a-form-item>
        </a-col>
      </template>
      <!-- Table 自定义渲染 -->
    </sa-table>
  </div>
</template>

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

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

const total = ref({
  reg_cost: 0,
  roi: 0,
  p_cost: 0,
  p_per: 0,
})

// 搜索表单
const searchForm = ref({
  game_id: '',
  media_id: '',
  auth_id: '',
  agent_id: '',
  site_id: '',
  tdate: [],
  group: '',
  filter: [],
})

// SaTable 基础配置
const options = reactive({
  api: api.getCwAgentList,
  pk: 'id',
  showSort: false,

  operationColumn: false,
})

// SaTable 列配置
const columns = reactive([
  { title: 'ID', dataIndex: 'akey', width: 100, fixed: 'left' },
  { title: '支出', dataIndex: 'cost', width: 100 },

  { title: '当天回本率', dataIndex: 'da_per', width: 100 },

  { title: '7天实际回本率', dataIndex: 're_amount_per_7', width: 100 },

  { title: '渠道名称', dataIndex: 'name', width: 100 },
  { title: '负责人', dataIndex: 'auth_name', width: 100 },
])

// 页面数据初始化
const initPage = () => {
  searchForm.value.tdate = [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
}

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

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

const handleRequestData = () => {
  const res = crudRef.value.getResponseData()
  console.log('res====>', res)
  total.value = res.totalData
}
</script>

<script>
export default { name: 'v1/reconciliation/channel_summary' }
</script>
