<template>
  <div>
    <!-- 搜索 -->
    <div ref="searchBox" class="mt10">
      <Search :searchArr="searchConfiger" @submit="onSearch" />
    </div>
    <PageTitle :malginLeft="10" :height="35" backgroundColor="#ffff" :marginBottom="5" :marginTop="5">
      <template #left>
        <el-button type="primary" size="small" @click="handleAdd('add', null)">添加完成情况</el-button>
        <el-button type="danger" size="small" @click="handleRow()">批量删除</el-button>
      </template>
    </PageTitle>
    <!-- 按钮组 -->
    <div class="content">
      <!-- 表格 -->
      <div class="tabBox">
        <MyTable :tableData="pageData.tableData" :tableColumn="pageData.tableColumn" :tableHeight="pageData.tableHeight"
          :key="pageData.keyCount" :tableConfiger="pageData.tableConfiger" :controlsWidth="pageData.controlsWidth"
          @chooseData="handleChooseData">
          <!-- 操作 -->
          <template #sjzt="{ row }">
            <DictTag :tag="false" :value="row.sjzt" :options="D_BZ_ZDSJCZJG" />
          </template>
          <template #controls="{ row }">
            <el-link type="primary" size="small" @click="handleAdd('edit', row)">编辑</el-link>
            <el-link type="primary" size="small" @click="handleAdd('detail', row)">详情</el-link>
            <el-link type="danger" size="small" @click="handleRow(row.id)">删除</el-link>
          </template>
        </MyTable>
        <Pages @changeNo="changeNo" @changeSize="changeSize" :tableHeight="pageData.tableHeight" :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"></Pages>
      </div>
    </div>
  </div>
  <AddForm ref="addForm" @getList="getList" :dict="{ D_BZ_ZDSJCZJG }" />

</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 { qcckGet, qcckPost, qcckDelete } from "@/api/qcckApi.js";
import { reactive, ref, onMounted, getCurrentInstance } from "vue";
import AddForm from "./addForm.vue";
const { proxy } = getCurrentInstance();
const { D_BZ_ZDSJCZJG } = proxy.$dict("D_BZ_ZDSJCZJG"); //获取字典数据
const searchBox = ref(); //搜索框
const searchConfiger = ref([
  {
    label: "今日值班人",
    prop: "jrzbrXm",
    placeholder: "请输入今日值班人",
    showType: "input",
  },
  {
    label: "明日值班人",
    prop: "mrzbrXm",
    placeholder: "请输入明日值班人",
    showType: "input",
  }, {
    label: "开始时间",
    prop: "startTime",
    placeholder: "请选择开始时间",
    showType: "datetimerange",
  },

]);
const queryFrom = ref({});
const pageData = reactive({
  tableData: [], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "checkbox", //选择类型
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页

  controlsWidth: 250, //操作栏宽度
  tableColumn: [
    { label: "今日值班人", prop: "jrzbrXm", showOverflowTooltip: true },
    { label: "今日值班电话", prop: "jrzbrLxdh", showOverflowTooltip: true },
    { label: "明日值班人", prop: "mrzbrXm", showOverflowTooltip: true },
    { label: "明日值班电话", prop: "mrzbrLxdh", showOverflowTooltip: true },
    { label: "开始时间", prop: "kssj", showOverflowTooltip: true },
    { label: "结束时间", prop: "jssj" },
    { label: "工作日期", prop: "gzrq" },
    { label: "所属部门", prop: "ssbm" },
  ]
});
onMounted(() => {
  getList();
  tabHeightFn();
});

// 搜索
const onSearch = (val) => {
  queryFrom.value = {
    ...val,
    startTime: val.startTime ? val.startTime[0] : '',
    endTime: val.startTime ? val.startTime[1] : ''
  };
  pageData.pageConfiger.pageCurrent = 1;
  getList();
};

const changeNo = (val) => {
  pageData.pageConfiger.pageCurrent = val;
  getList();
};
const changeSize = (val) => {
  pageData.pageConfiger.pageSize = val;
  getList();
};

// 获取列表
const getList = () => {
  const promes = {
    ...pageData.pageConfiger,
    ...queryFrom.value,
  }
  qcckGet(promes, "/mosty-gsxt/gzqk/getPageList").then((res) => {
    pageData.tableData = res.records || [];
    pageData.total = res.total;
    pageData.tableConfiger.loading = false;
  }).catch(() => {
    pageData.tableConfiger.loading = false;
  });
};

// 删除
const ids = ref([])
const handleChooseData = (val) => {
  ids.value = val.map(item => item.id)
}
const handleRow = (id) => {
  const promes = {
    ids: id ? [id] : ids.value
  }
  proxy.$confirm("确定要删除？", "警告", { type: "warning" }).then(() => {
    qcckDelete(promes, "/mosty-gsxt/gzqk/deleteEntity").then(() => {
      proxy.$message({ type: "success", message: "删除成功" });
      getList();
    });
  })
};
const addForm = ref(null);
const handleAdd = (type, row) => {
  addForm.value.init(type, row);
};



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

</script>

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