<template>
  <div class="main-box">
    <div class="table-box">
      <ProTable
        ref="proTable"
        :columns="columns"
        :request-api="getTableList"
        :init-param="initParam"
        :search-col="{ xs: 1, sm: 1, md: 2, lg: 3, xl: 3 }"
      >
      </ProTable>
    </div>
  </div>
</template>
<script setup lang="ts" name="accountManage">
import { ref, reactive } from "vue";
import { User } from "@/api/interface";
import ProTable from "@/components/ProTable/index.vue";
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
import { getDictOptions } from "@/api/modules/common";
import { getUserList } from "@/api/modules/system/user";

// ProTable 实例
const proTable = ref<ProTableInstance>();

// 如果表格需要初始化请求参数，直接定义传给 ProTable(之后每次请求都会自动带上该参数，此参数更改之后也会一直带上，改变此参数会自动刷新表格数据)
const initParam = reactive({ deptId: "" });

// 表格配置项
const columns = reactive<ColumnProps<User.ResUserList>[]>([
  { prop: "userName", label: "操作人员", search: { el: "input" } },
  { prop: "nickName", label: "所属模块", search: { el: "input" } },
  {
    prop: "status",
    label: "操作类型",
    enum: () => getDictOptions("sys_oper_type"),
    search: { el: "select" },
    fieldNames: { label: "dictLabel", value: "dictValue" }
  },
  { prop: "nickName", label: "操作对象" },

  { prop: "createTime", label: "操作时间", search: { el: "date-range-picker", custom: true } }
]);
// 分页列表获取数据
const getTableList = (params: User.ReqUserParams) => {
  if (params.createTime) {
    const [beginTime, endTime] = params.createTime;
    params.params = {
      beginTime,
      endTime
    };
    delete params.createTime;
  }
  return getUserList(params);
};
</script>
