<template>
  <div>
    <div class="titleBox">
       <!-- 头部 -->
      <PageTitle title="请休假审批" />
    </div>
    <!-- 搜索 -->
    <div ref="searchBox">
      <!-- <Search :searchArr="searchConfiger" @submit="onSearch">
        <template #defaultSlot>
          <MOSTY.Department width="100%" clearable v-model="searchObj.sqbmdm" />
        </template>
      </Search> -->
    </div>
    <!-- 表格 -->
    <div class="tabBox">
      <MyTable
        :tableData="pageData.tableData"
        :tableColumn="pageData.tableColumn"
        :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount"
        :tableConfiger="pageData.tableConfiger"
        :controlsWidth="210"
      >
        <template #sqrlx="{ row }">
          <dict-tag :options="D_BZ_SQRLX" :value="row.sqrlx" :tag="false" />
        </template>
        <template #kssj="{ row }">
          {{ row.kssj.substring(0, 10) + " — " + row.jssj.substring(0, 10) }}
        </template>
        <template #qjlx="{ row }">
          <dict-tag :options="D_BZ_QXJLX" :value="row.qjlx" :tag="false" />
        </template>
        <template #kqShzt="{ row }">
          <dict-tag :options="D_QW_KQ_SHZT" :value="row.kqShzt" :tag="false" />
        </template>
        <!-- 操作 -->
        <template #controls="{ row }">
          <el-link type="primary" @click="detailHland('detail', row.id,row)">详情</el-link>
          <span class="linkGapLine">|</span>
          <el-link type="primary" v-if="row.kqShry.kqShzt == '01'" @click="detailHland('sp', row.id,row)">审批</el-link>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="pageData.pageConfiger"
      ></Pages>
    </div>
    <!-- 详情 -->
    <Detail ref="detailDialog" @updateDate="getData"/>
  </div>
</template>

<script setup>
import * as MOSTY from "@/components/MyComponents/index";
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 Detail from './detail.vue';
import { serviceGet, serviceDelete, servicePost } from "@/api/serviceApi.js";
import { getQwQxj, addQwQxj, deleteQwQxj, getQwQxjInfo, updateQwQxj } from "@/api/service/pleaseTake.js";
import { reactive, ref ,onMounted,getCurrentInstance } from 'vue';
const { proxy } = getCurrentInstance();
const { D_BZ_QXJLX, D_BZ_SQRLX, D_QW_KQ_SHZT } = proxy.$dict("D_BZ_QXJLX", "D_BZ_SQRLX","D_QW_KQ_SHZT");
const detailDialog = ref();
const ids = ref([]);//多选
const searchBox = ref() //搜索框
let searchObj = ref({}); //搜索数据
const searchConfiger = reactive([
  {
    showType: "daterange",
    prop: "daterangeKey",
    defaultVal: "",
    label: "起止时间"
  },
  {
    showType: "defaultSlot",
    prop: "sqbmdm",
    options: [],
    placeholder: "请选择单位",
    label: "归属单位"
  },
  {
    showType: "select",
    prop: "sqrlx",
    placeholder: "请选择请假人类型",
    label: "请假人类型",
    options:D_BZ_SQRLX
  },
  {
    showType: "input",
    prop: "sqrXm",
    placeholder: "请输入请假人姓名",
    label: "请假人姓名"
  },
])

const queryFrom = ref({})
const pageData = reactive({
  tableData: [], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    loading:false
  },
  pageConfiger: { //分页
    pageCurrent: 1,
    pageSize: 20,
    total: 0,
  },
  tableColumn: [
    { label: "请假人部门", prop: "sqbm",showOverflowTooltip:true },
    { label: "请假人类型", prop: "sqrlx", showSolt :true},
    { label: "请假人", prop: "sqrXm"},
    { label: "请假类型", prop: "qjlx", showSolt :true },
    { label: "起止日期", prop: "kssj", showSolt :true, width:"200" },
    { label: "申请时间", prop: "xtCjsj",showOverflowTooltip:true},
    { label: "审核状态", prop: "kqShzt", showSolt :true },
  ]
});
onMounted(() => {
  getData() //获取数据
  tabHeightFn();
  proxy.mittBus.on("mittFn", (data) => {
    pageData.keyCount = data;
  });
});
// 搜索
const onSearch = (obj)=>{
  let searchItem = JSON.parse(JSON.stringify(obj));
  searchItem.kssj = obj.daterangeKey && obj.daterangeKey.length ? obj.daterangeKey[0] : null;
  searchItem.jssj = obj.daterangeKey && obj.daterangeKey.length ? obj.daterangeKey[1] : null;
  delete searchItem.daterangeKey;
  if(obj.cz) searchObj.value.sqbmdm = '';
  searchObj.value = {...searchObj.value,...searchItem};
  delete searchObj.value.cz;
  pageData.pageConfiger.pageCurrent = 1;
  getData() //获取数据
}
// 获取数据
const getData = ()=>{
  pageData.tableConfiger.loading = true
  let attr = { ...pageData.pageConfiger, ...searchObj.value };
  serviceGet({},`/mosty-qwzx/tbQwQxj/paginAuditsQuery`).then(res=>{
    pageData.tableData = res.records || [];
    pageData.pageConfiger.total = res.total;
    pageData.tableConfiger.loading = false
  }).catch(()=>{
    pageData.tableConfiger.loading = false
  });
}
// 详情
const detailHland =  (type,id,data)=>{
  detailDialog.value.init(type,id,data)
}
// 批量删除 
function delDictItem(row) {
  proxy.$confirm("确定删除该数据？", "警告", { type: "warning" }).then(() => {
    deleteQwQxj(row.id).then(() => {
      getData();
      proxy.$message({ type: "success",  message: "删除成功" });
    });
  }).catch(() => {
    proxy.$message.info("已取消");
  });
}
// 表格高度计算
const tabHeightFn = () => {
  pageData.tableHeight = window.innerHeight - searchBox.value.offsetHeight - 244;
  window.onresize = function () { tabHeightFn(); };
};
</script>

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