<template>
  <div>
    <div class="titleBox">
      <page-title title="保安考试管理" />
    </div>
    <!-- 搜索 -->
    <div ref="searchBox">
      <Search :searchArr="searchConfiger" @submit="onSearch"></Search>
    </div>
    <!-- 表格 -->
    <div class="tabBox">
      <MyTable :tableData="pageData.tableData" :tableColumn="pageData.tableColumn" :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount" :tableConfiger="pageData.tableConfiger" :controlsWidth="pageData.controlsWidth">
        <template #bxxLx="{ row }">
          <DictTag :value="row.bxxLx" :tag="false" :options="D_BZ_BXDLX" />
        </template>
        <!-- 操作 -->
        <template #controls="{ row }">
          <el-link type="primary" @click="addEdit('view', row)">详情</el-link>
          <el-link type="primary" @click="addEdit('edit', row)">证件申请</el-link>
        </template>
      </MyTable>
      <Pages @changeNo="changeNo" @changeSize="changeSize" :tableHeight="pageData.tableHeight" :pageConfiger="{
        ...pageData.pageConfiger,
        total: pageData.total
      }"></Pages>
    </div>

    <!-- 线下线上考试详情 -->
    <view-exam-detalis v-model="isVisible" ref="trainerRef" @refresh="getList" />
  </div>
</template>

<script setup>
import { onMounted, reactive, ref } from "vue";
import MyTable from '@/components/aboutTable/MyTable.vue';
import Pages from '@/components/aboutTable/Pages.vue';
import Search from '@/components/aboutTable/Search.vue';
import { qcckGet, qcckPost, qcckDelete } from "@/api/qcckApi.js";
import PageTitle from "@/components/aboutTable/PageTitle.vue";
import ViewExamDetalis from "./components/viewExamDetalis.vue";

const trainerRef = ref(null);
const queryFrom = ref({});
const isVisible = ref(false);
const searchBox = ref(null);
const D_BZ_BXDLX = ref([]);
const searchConfiger = ref([
  {
    label: "培训项目名称",
    prop: "xmmc",
    placeholder: "请输入培训项目名称",
    showType: "input"
  },
  {
    label: "考试时间",
    prop: "kssj",
    placeholder: "请选择考试时间",
    showType: "date"
  },
]);

const pageData = reactive({
  tableData: [{}],
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 10,
    pageCurrent: 1
  },
  controlsWidth: 180,
  tableColumn: [
    { label: "培训项目名称", prop: "xmmc" },
    { label: "考试时间", prop: "kssj" },
    { label: "监考民警", prop: "jkmj" },
    { label: "考试地址", prop: "ksdz" },
    { label: "考试方式", prop: "ksfs" },
  ]
});

// 表格高度计算
const tabHeightFn = () => {
  pageData.tableHeight =
    window.innerHeight - searchBox.value.offsetHeight - 250;
  window.onresize = function () {
    tabHeightFn();
  };
};

const addEdit = (type, row) => {
  trainerRef.value.open(row, type);
};

const onSearch = (value) => {
  queryFrom.value = value
  pageData.pageConfiger.pageCurrent = 1;
  getList();
}

const getList = async () => {
  try {
    pageData.tableConfiger.loading = true;
    const res = await qcckPost({
      ...pageData.pageConfiger,
      ...queryFrom.value
    }, `/mosty-base/baxx/ksgl/page`)

    if(res) {
      pageData.tableData = [{}];
      pageData.total = res.total;
    }
  } finally {
    pageData.tableConfiger.loading = false;
  }
}

onMounted(() => {
  tabHeightFn();
  getList();
});
</script>

<style scoped lang="scss">
::v-deep {
  .el-dialog__header {
    background: transparent !important;
  }
}
</style>
