<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">
            <!-- <a-tree-select
              v-model="searchForm.game_id"
              :data="gameListTree"
              tree-checked-strategy="child"
              :tree-checkable="false"
              :max-tag-count="2"
              :fieldNames="{ title: 'name', key: 'id' }"
              allow-search
              allow-clear
              placeholder="请选择游戏"
            /> -->
            <game-select v-model="searchForm.game_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>
      </template>

      <template #site_id="{ record }"> [{{ record.site_id }}] {{ record.site_name }} </template>

      <template #agent_id="{ record }"> [{{ record.agent_id }}] {{ record.agent_name }} </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 api from '../../api/advert/gamePackageLog'
import commonApi from '../../api/common'
import GameSelect from '@/components/game-select/index.vue'

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

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

// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  operationColumn: false,
  add: {
    show: false,
    auth: ['/v1/gameLog/GamePackLog/save'],
    func: async () => {
      editRef.value?.open()
    },
  },
  edit: {
    show: false,
    auth: ['/v1/gameLog/GamePackLog/update'],
    func: async (record) => {
      editRef.value?.open('edit')
      editRef.value?.setFormData(record)
    },
  },
  delete: {
    show: false,
    auth: ['/v1/gameLog/GamePackLog/destroy'],
    func: async (params) => {
      const resp = await api.destroy(params)
      if (resp.code === 200) {
        Message.success(`删除成功！`)
        crudRef.value?.refresh()
      }
    },
  },
})

// SaTable 列配置
const columns = reactive([
  { title: '广告位ID', dataIndex: 'site_id', width: 120 },
  { title: '渠道ID', dataIndex: 'agent_id', width: 120 },
  { title: '游戏', dataIndex: 'game_name', width: 160 },

  { title: '目录', dataIndex: 'letter', width: 180 },
  { title: 'icon', dataIndex: 'icon', type: 'image', width: 120 },
  {
    title: '状态',
    dataIndex: 'status',
    type: 'dict',
    dict: 'package_status',
    width: 180,
  },
  { title: '创建时间', dataIndex: 'create_time', width: 180, type: 'date' },
  { title: '更新时间', dataIndex: 'update_time', width: 180, type: 'date' },
])

// 页面数据初始化
const initPage = async () => {}

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

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