<template>
  <div class="ma-content-block">
    <sa-table
      ref="crudRef"
      :options="options"
      :columns="columns"
      :searchForm="searchForm"
    >
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :sm="12" :md="6" :lg="7" :xl="6" :xxl="4" :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="12" :md="6" :lg="7" :xl="6" :xxl="4" :xs="24">
          <a-form-item label="媒体类型" field="media_id">
            <media-select v-model="searchForm.media_id" />
          </a-form-item>
        </a-col>
        <a-col :sm="12" :md="6" :lg="7" :xl="6" :xxl="4" :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="12" :md="6" :lg="7" :xl="6" :xxl="4" :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="12" :md="6" :lg="7" :xl="6" :xxl="5" :xs="24">
          <a-form-item label="注册日期" field="create_time">
            <a-range-picker
              class="w-full"
              v-model="searchForm.create_time"
              placeholder="注册日期"
            />
          </a-form-item>
        </a-col>
        <a-col :sm="12" :md="6" :lg="7" :xl="6" :xxl="3" :xs="24">
          <a-form-item label="负责人" field="auth_id">
            <auth-select v-model="searchForm.auth_id" multiple />
          </a-form-item>
        </a-col>
      </template>
    </sa-table>
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from "vue";
import api from "../../api/gameLog/roleData";
import dayjs from "dayjs";
import commonApi from "../../api/common";
import GameSelect from "@/components/game-select/index.vue";
import AuthSelect from "@/components/auth-select/index.vue";
import MediaSelect from "@/components/media-select/index.vue";

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

// 搜索表单
const searchForm = ref({
  game_id: "",
  media_id: "",
  site_id: "",
  auth_id: "",
  user_name: "",
  create_time: [dayjs().format("YYYY-MM-DD"), dayjs().format("YYYY-MM-DD")],
});

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

// SaTable 列配置
const columns = reactive([
  { title: "注册时间", dataIndex: "create_time", width: 180 },
  { title: "角色ID", dataIndex: "role_id", width: 80 },
  { title: "角色名", dataIndex: "role_name", width: 80 },
  { title: "角色等级", dataIndex: "role_level", width: 80 },
  { title: "区服id", dataIndex: "server_id", width: 60 },
  { title: "区服名", dataIndex: "server_name", width: 100 },
  { title: "用户名", dataIndex: "user_name", width: 120 },
  { title: "游戏名", dataIndex: "game_name", width: 120 },
  { title: "渠道ID", dataIndex: "agent_id", width: 100 },
  { title: "广告位ID", dataIndex: "site_id", width: 100 },
  { title: "注册IP", dataIndex: "ip", width: 180 },
  { title: "渠道名", dataIndex: "agent_name", width: 120 },
  { title: "负责人", dataIndex: "auth_name", width: 120 },
]);

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

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

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

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

<script>
export default { name: "v1/gameLog/roleData" };
</script>
