<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="user_name">
            <a-input v-model="searchForm.user_name" placeholder="请输入用户名" allow-clear />
          </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="reg_time">
            <a-date-picker class="w-full" v-model="searchForm.reg_time" mode="date" />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item label="上报日期" field="create_time">
            <a-date-picker class="w-full" v-model="searchForm.create_time" mode="date" />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item label="上报类型" field="step">
            <sa-select v-model="searchForm.step" dict="callback_step" placeholder="请选择上报类型" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item label="媒体类型" field="media_id">
            <a-select v-model="searchForm.media_id" placeholder="请选择媒体类型" allow-clear allow-search>
              <a-option
                v-for="item in mediaOptions"
                :key="item.id"
                :value="item.id"
                :label="`${item.id}:${item.name}`" />
            </a-select>
          </a-form-item>
        </a-col>
      </template>

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

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import EditForm from './edit.vue'
import commonAdvertApi from '../../api/common'
import api from '../../api/advert/callbackPushLog'
import dayjs from 'dayjs'

// 引用定义
const crudRef = ref()
const editRef = ref()
const mediaOptions = ref()

// 搜索表单
const searchForm = ref({
  user_name: '',
  agent_id: '',
  site_id: '',
  reg_time: '',
  create_time: '',
  step: '',
  media_id: '',
})

// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  rowSelection: { showCheckedAll: true },
  operationColumn: false,
})

// SaTable 列配置
const columns = reactive([
  {
    title: '类型',
    dataIndex: 'step',
    type: 'dict',
    dict: 'callback_step',
    width: 120,
  },
  { title: '用户名', dataIndex: 'user_name', width: 120 },
  { title: '上报游戏', dataIndex: 'game_id', width: 120 },
  { title: '上报渠道', dataIndex: 'agent_id', width: 120 },
  { title: '上报广告位', dataIndex: 'site_id', width: 120 },
  { title: '上报时间', dataIndex: 'create_time', width: 120 },

  { title: '注册游戏', dataIndex: 'reg_game_id', width: 120 },
  { title: '注册渠道', dataIndex: 'reg_agent_id', width: 120 },
  { title: '注册广告位', dataIndex: 'reg_site_id', width: 120 },
  { title: '注册时间', dataIndex: 'reg_time', width: 120 },

  { title: '上报金额', dataIndex: 'money', width: 180 },
  { title: '上报设备号', dataIndex: 'imei', width: 280 },
  { title: '上报IP', dataIndex: 'ip', width: 180 },

  { title: '系统版本', dataIndex: 'system_version', width: 120 },
  { title: 'sdk版本', dataIndex: 'sdk_version', width: 120 },
  { title: '包名', dataIndex: 'packname', width: 120 },
  {
    title: '接口',
    dataIndex: 'media_type',
    type: 'dict',
    dict: 'callback_media_type',
    width: 120,
  },
])

// 获取媒体类型
const getMediaOptions = async () => {
  const resp = await commonAdvertApi.getMediaOptionsApi()
  if (resp.code === 200) {
    mediaOptions.value = resp.data
  }
}

// 页面数据初始化
const initPage = async () => {
  await getMediaOptions()
  searchForm.value.create_time = dayjs().format('YYYY-MM-DD')
}

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

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

<script>
export default { name: 'v1/advert/callbackPushLog' }
</script>
