<template>
  <div>
    <div class="titleBox">
      <PageTitle title="保安员年检送培">
        <el-button type="primary" @click="onBatchAudit">新增</el-button>
      </PageTitle>
    </div>
    <!-- 搜索 -->
    <div ref="searchBox">
      <Search :searchArr="searchConfiger" @submit="onSearch" :key="pageData.keyCount" />
    </div>
    <!-- 表格 -->
    <div class="tabBox">
      <MyTable :tableData="pageData.tableData" :tableColumn="pageData.tableColumn" :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount" :tableConfiger="pageData.tableConfiger" :controlsWidth="pageData.controlsWidth"
        @chooseData="chooseData">
        <template #sptz="{ row }">
           <DictTag :value="row.sptz" :tag="false" :options="D_BA_SPZT" />
        </template>
        <!-- 操作 -->
        <template #controls="{ row }">
          <el-link type="primary" link @click="addEdit('RefSteap', row)">审核流程</el-link>
          <el-link type="primary" link @click="addEdit('detail', row)">详情</el-link>
        </template>
      </MyTable>
      <Pages @changeNo="changeNo" @changeSize="changeSize" :tableHeight="pageData.tableHeight" :pageConfiger="{
        ...pageData.pageConfiger,
        total: pageData.total
      }"></Pages>
    </div>
    <!-- 详情 -->
    <DetailForm ref="detailDiloag" :dict="{D_BZ_SF}"/>
    <!-- 审核流程 -->
    <Steps ref="RefSteap" ></Steps>
  </div>
</template>

<script setup>
import PageTitle from "@/components/aboutTable/PageTitle.vue";
import MyTable from "@/components/aboutTable/MyTable.vue";
import Pages from "@/components/aboutTable/Pages.vue";
import Search from "@/components/aboutTable/Search.vue";
import DetailForm from "./components/detailForm.vue";
import Steps from "./components/steps.vue";
import {getItem} from '@/utils/storage.js'
import { qcckPost } from "@/api/qcckApi.js";
import { reactive, ref, onMounted, getCurrentInstance, nextTick } from "vue";
import { ElMessage } from "element-plus";
const { proxy } = getCurrentInstance();
const { D_BA_SHZT,D_BA_SPZT } = proxy.$dict("D_BA_SHZT",'D_BA_SPZT');
const detailDiloag = ref();
const RefSteap = ref();
const shForm = ref();
const searchBox = ref(); //搜索框
const selectedRows = ref([]);
const searchConfiger = ref([
  {
    label: "姓名",
    prop: "xm",
    showType: "input"
  },
  {
    label: "身份证号码",
    prop: "sfzhm",
    showType: "input"
  },
  {
    label: "电话",
    prop: "dh",
    showType: "input"
  },
]);
const queryFrom = ref({});
const pageData = reactive({
  tableData: [],
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "checkBox",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageNum: 1
  },
  controlsWidth: 180,
  tableColumn: [
    { label: "保安公司名称", prop: "ssbakk",showOverflowTooltip: true },
    { label: "培训公司", prop: "sptzCompanyName", showOverflowTooltip: true },
    { label: "年审年份", prop: "njnf"},
    { label: "姓名", prop: "xm" },
    { label: "身份证号码", prop: "sfzhm",showOverflowTooltip: true },
    { label: "电话", prop: "dh" },
    { label: "文化程度", prop: "whcd" },
    { label: "证书编号", prop: "zsbh", showOverflowTooltip: true },
    { label: "服务行业", prop: "fwxymc" },
    { label: "入职时间", prop: "rzsj" },
    { label: "上岗证号码", prop: "sgxkhm", showOverflowTooltip: true },
    { label: "送培状态", prop: "sptz", showSolt: true }
  ]
});
onMounted(() => {
  getList();
  tabHeightFn();
});
// 搜索
const onSearch = (val) => {
  queryFrom.value = { ...val };
  pageData.pageConfiger.pageNum = 1;
  getList();
};
const changeNo = (val) => {
  pageData.pageConfiger.pageNum = val;
  getList();
};
const changeSize = (val) => {
  pageData.pageConfiger.pageSize = val;
  getList();
};
// 获取列表
const getList = () => {
  pageData.tableConfiger.loading = true;
  const promes = {
    ...pageData.pageConfiger,
    ...queryFrom.value,
  }
  qcckPost(promes,'/mosty-base/bans/njxx/listForSendTraining').then((res) => {
    pageData.tableData = res.records || []
    pageData.total = res.total;
     pageData.tableConfiger.loading = false;
  }).catch((err) => {
     pageData.tableConfiger.loading = false;
  })
};

const chooseData = (rows) => {
  selectedRows.value = Array.isArray(rows) ? rows : [];
};

const onBatchAudit = () => {
  if (!selectedRows.value.length) {
    ElMessage.warning("请选择需要审核的数据");
    return;
  }
  ElMessage.success("已选择 " + selectedRows.value.length + " 条");
};


// 详情
const addEdit = (type, row) => {
  nextTick(() => {
    if(type == 'RefSteap'){
      RefSteap.value.init(row);
    }else if(type == 'shForm'){
      shForm.value.init(row);
    }
    else{
      detailDiloag.value.init(type, row);
    }
  })
};


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

<style>
.el-loading-mask {
  background: rgba(0, 0, 0, 0.5) !important;
}
</style>
