<template>
  <div class="ma-content-block">
    <sa-table
      ref="crudRef"
      :options="options"
      :columns="columns"
      :searchForm="searchForm"
    >
      <template #tableSearch>
        <a-col :sm="6" :xs="24">
          <a-form-item label="操作" field="action">
            <a-select
              v-model="searchForm.action"
              allow-clear
              placeholder="请选择操作"
            >
              <a-option value="1">封禁</a-option>
              <a-option value="2">解封</a-option>
            </a-select>
          </a-form-item>
        </a-col>
      </template>

      <!-- Table 自定义渲染 -->
    </sa-table>
    <!-- 编辑表单 -->
    <add-ban ref="addRef" @success="refresh" />
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from "vue";
import api from "../../api/customer/account";
import AddBan from "./addBan.vue";

const addRef = ref();
const crudRef = ref();

// 搜索表单
const searchForm = ref({});

// SaTable 基础配置
const options = reactive({
  api: api.getBanListApi,
  operationColumn: false,
  add: {
    show: true,
    auth: ["/v1/customer/Account/banList/add"],
    text: "添加封禁｜解除封禁",
    icon: "",
    func: async () => {
      addRef.value?.open();
    },
  },
});

const columns = ref([
  {
    title: "操作",
    dataIndex: "action",
    key: "action",
  },
  {
    title: "类型",
    key: "type",
    dataIndex: "type",
  },
  {
    title: "值",
    key: "value",
    dataIndex: "value",
  },
  {
    title: "理由",
    key: "reason",
    dataIndex: "reason",
  },
  {
    title: "操作人",
    key: "auth_name",
    dataIndex: "auth_name",
  },
  {
    title: "操作时间",
    key: "created_time",
    dataIndex: "created_time",
  },
]);

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

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

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