<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>
      </template>

      <template #game_id="{ record }"> [{{ record.game_id }}]:{{ record.game_name }} </template>

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

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

<script setup>
import { onMounted, ref, reactive } from 'vue'
import EditForm from './edit.vue'
import api from '../../api/center/gamePayChannel'
import GameSelect from '@/components/game-select/index.vue'

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

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

// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  showSort: false,
  add: {
    show: true,
    auth: ['/v1/center/GamePayChannel/save'],
    func: async () => {
      editRef.value?.open()
    },
  },
  edit: {
    show: true,
    auth: ['/v1/center/GamePayChannel/update'],
    func: async (record) => {
      editRef.value?.open('edit')
      editRef.value?.setFormData(record)
    },
  },
})

// SaTable 列配置
const columns = reactive([
  { title: '游戏', dataIndex: 'game_id', width: 180 },
  { title: '内购', dataIndex: 'inapp_name', width: 180 },
  { title: '微信wap', dataIndex: 'wechat_wap_name', width: 180 },
  { title: '支付宝wap', dataIndex: 'alipay_wap_name', width: 180 },
  { title: '微信扫码', dataIndex: 'wechat_scan_name', width: 180 },
  { title: '微信公众号', dataIndex: 'wechat_jsapi_name', width: 180 },
])

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

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

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

<script>
export default { name: 'v1/center/gamePayChannel' }
</script>
