<template>
  <div>
    <div class="titleBox">
      <PageTitle title="指令信息">
        <el-button type="primary" @click="addEdit('add', '')">
          <el-icon style="vertical-align: middle"><CirclePlus /></el-icon>
          <span style="vertical-align: middle">新增</span>
        </el-button>
      </PageTitle>
    </div>
    <!-- 搜索 -->
    <div ref="searchBox">
      <Search :searchArr="searchConfiger" @submit="onSearch"/>
    </div>
    <!-- 表格 -->
    <div class="tabBox">
      <MyTable
        :tableData="pageData.tableData"
        :tableColumn="pageData.tableColumn"
        :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount"
        :tableConfiger="pageData.tableConfiger"
        :controlsWidth="pageData.controlsWidth"
      >

        <template #zllx="{row}">
          <DictTag :tag="false" :value="row.zllx" :options="D_GS_XS_ZLLX" />
        </template>
        <template #zldj="{row}">
          <DictTag :tag="false" :value="row.zldj" :options="D_GS_ZDQT_FXDJ" />
        </template>
        <template #czzt="{row}">
          <DictTag :tag="false" :value="row.czzt" :options="D_GS_XS_CZZT" />
        </template>
        <template #controls="{ row }">
          <el-link size="small" type="primary" @click="addEdit('edit', row)">编辑</el-link>
          <el-link size="small" type="danger" @click="deleteRow(row.id)">删除</el-link>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      ></Pages>
    </div>
    <!-- 详情 -->
    <DetailForm ref="detailDiloag" v-if="isShow" @updateDate="getList" :dic="{D_GS_XS_ZLLX,D_GS_ZDQT_FXDJ}" />
  </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 { qcckGet, qcckPost, qcckDelete } from "@/api/qcckApi.js";
import { reactive, ref, onMounted, getCurrentInstance, nextTick } from "vue";
const { proxy } = getCurrentInstance();
const {D_GS_XS_SJLY,D_GS_XS_ZLLX,D_GS_ZDQT_FXDJ,D_GS_XS_CZZT} = proxy.$dict('D_GS_XS_SJLY','D_GS_XS_ZLLX','D_GS_ZDQT_FXDJ','D_GS_XS_CZZT')
const detailDiloag = ref();
const isShow = ref(false);
const searchBox = ref(); //搜索框
const searchConfiger = ref([
  { label: "指令标题", prop: 'zlbt', placeholder: "请输入指令标题", showType: "input" },
  { label: "指令类型", prop: 'zllx', placeholder: "请选择指令类型", showType: "select",options:D_GS_XS_ZLLX },
  { label: "指令等级", prop: 'zldj', placeholder: "请选择指令等级", showType: "select" ,options:D_GS_ZDQT_FXDJ},
  { label: "处置状态", prop: 'czzt', placeholder: "请选择处置状态", showType: "select" ,options:D_GS_XS_CZZT},
  { label: "反馈时间", prop: 'time', placeholder: "请选择反馈时间", showType: "datetimerange" },
]);

const queryFrom = ref({});
const pageData = reactive({
    tableData: [],
    keyCount: 0,
    tableConfiger: {
      rowHieght: 61,
      showSelectType: "null",
      loading: false
    },
    total: 0,
    pageConfiger: {
      pageSize: 20,
      pageCurrent: 1
    },
    controlsWidth: 120,
    tableColumn: [
      { label: '指令标题', prop: 'zlbt' },
      { label: '指令类型', prop: 'zllx',showSolt:true  },
      { label: '指令等级', prop: 'zldj',showSolt:true  },
      { label: '反馈截止时间', prop: 'jssj' },
      { label: '处置状态', prop: 'czzt',showSolt:true },
    ]
  });

onMounted(() => {
  getList()
  tabHeightFn();
});

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

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

// 获取列表
const getList = (val) =>{
  pageData.tableConfiger.loading = true;
  let data = { ...pageData.pageConfiger, ...queryFrom.value };
  delete data.time;
  qcckGet(data,'/mosty-gsxt/zlxx/selectPage').then(res=>{
    pageData.tableData = res.records || [];
    pageData.total = res.total;
    pageData.tableConfiger.loading = false;
  }).catch(()=>{ pageData.tableConfiger.loading = false; })
}



 const deleteRow = (id) =>{
  proxy.$confirm("确定要删除", "警告", {type: "warning"}).then(() => {
    qcckPost({id},'/mosty-gsxt/zlxx/delete').then(()=>{
      proxy.$message({ type: "success",  message: "删除成功" });
      getList();
    })
  }).catch(() => {});
}

// 详情
const addEdit = (type, row) => {
  isShow.value = true;
  nextTick(()=>{
    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>
