<template>
  <div>
    <div class="titleBox">
      <PageTitle title="年检签到">
        <el-button type="primary" @click="onBatchAudit('add',null)">新增</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="onBatchAudit('detail', row)">详情</el-link>
        </template>
      </MyTable>
      <Pages @changeNo="changeNo" @changeSize="changeSize" :tableHeight="pageData.tableHeight" :pageConfiger="{
        ...pageData.pageConfiger,
        total: pageData.total
      }"></Pages>
    </div>
    <!-- 新增 -->
    <AddForm ref="addFormRef" @refresh="getList" :dic="{D_BZ_WHCD}"></AddForm>
  </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 AddForm from "./components/addForm.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_BZ_WHCD,D_BA_SPZT } = proxy.$dict("D_BZ_WHCD",'D_BA_SPZT');
const addFormRef = ref();
const searchBox = ref(); //搜索框
const selectedRows = ref([]);
const searchConfiger = ref([
  {
    label: "培训项目名称",
    prop: "pxxmmc",
    showType: "input"
  },
  {
    label: "培训时间",
    prop: "pxsj",
    showType: "datetimerange"
  },
]);
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: "pxxmmc",showOverflowTooltip: true },
    { label: "培训地址", prop: "zzdw", showOverflowTooltip: true },
    { label: "培训开始时间", prop: "pxkssj"},
    { label: "培训结束时间", prop: "pxjssj" },
    { label: "组织单位", prop: "zzdw",showOverflowTooltip: true },
    { label: "培训内容", prop: "pxnr" },
    { label: "培训人员", prop: "totalPersonCount" },
    { label: "已签到人员", prop: "checkedInPersonCount", showOverflowTooltip: true },
    { label: "未签到人员", prop: "notCheckedInPersonCount" },
  ]
});
onMounted(() => {
  getList();
  tabHeightFn();
});
// 搜索
const onSearch = (val) => {
  queryFrom.value = { ...val };
  queryFrom.value.pxkssjStart = val.pxsj ? val.pxsj[0]:'';
  queryFrom.value.pxkssjEnd = val.pxsj ? val.pxsj[1]:'';
  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,
  }
  delete promes.pxsj;
  qcckPost(promes,'/mosty-base/bans/pxqd-item/page').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 = (type, row) => {
  addFormRef.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>
