<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="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="用户UID" field="uid">
            <a-input v-model="searchForm.uid" placeholder="请输入用户UID" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item label="角色ID" field="role_id">
            <a-input v-model="searchForm.role_id" placeholder="请输入角色ID" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item label="角色名" field="role_name">
            <a-input v-model="searchForm.role_name" placeholder="请输入角色名" allow-clear />
          </a-form-item>
        </a-col>
      </template>

      <!-- Table 自定义渲染 -->
      <template #game_id="{ record }">
        <span>[{{ record.game_id }}] {{ record.game_name }}</span>
      </template>
      <template #media_id="{ record }">
        <span>[{{ record.media_id }}] {{ record.media_name }}</span>
      </template>
      <template #agent_id="{ record }">
        <span>[{{ record.agent_id }}] {{ record.agent_name }}</span>
      </template>
      <template #site_id="{ record }">
        <span>[{{ record.site_id }}] {{ record.site_name }}</span>
      </template>
    </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/customer/roleData'
import GameSelect from '@/components/game-select/index.vue'

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

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

// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  showSort: false,

  edit: {
    show: true,
    auth: ['/v1/customer/RoleData/update'],
    func: async (record) => {
      editRef.value?.open('edit')
      editRef.value?.setFormData(record)
    },
  },
})

// SaTable 列配置
const columns = reactive([
  {
    title: '游戏',
    dataIndex: 'game_id',
    width: 180,
  },
  { title: '用户名', dataIndex: 'user_name', width: 180 },
  { title: '用户UID', dataIndex: 'uid', width: 180 },
  { title: '服务器名', dataIndex: 'server_name', width: 180 },
  { title: '角色ID', dataIndex: 'role_id', width: 180 },
  { title: '角色名', dataIndex: 'role_name', width: 180 },
  { title: '累计充值', dataIndex: 'total_recharge', width: 180 },
  { title: '媒体ID', dataIndex: 'media_id', width: 180 },
  { title: '渠道ID', dataIndex: 'agent_id', width: 180 },
  { title: '广告位ID', dataIndex: 'site_id', width: 180 },
  { title: '注册IP地址', dataIndex: 'ip', width: 180 },
  { title: '账号最后登录时间', dataIndex: 'login_time', width: 220 },
  { title: '角色最后充值时间', dataIndex: 'last_recharge_time', width: 220 },
  { title: '角色创建时间', dataIndex: 'create_time', width: 180 },
])

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

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

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

<script>
export default { name: 'v1/customer/roleData' }
</script>
