<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>
        <el-button type="danger" @click="addEdit('add', '')">
          <el-icon style="vertical-align: middle"><Dete /></el-icon>
          <span style="vertical-align: middle">批量删除</span>
        </el-button>
        <el-button >
          <el-icon style="vertical-align: middle"><Setting /></el-icon>
          <span style="vertical-align: middle">批量处置</span>
        </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 #accidentPhoto="{ row }">
          <el-image 
            style="width: 50px; height: 50px"
            :src="row.accidentPhoto"
            :preview-src-list="[row.accidentPhoto]">
          </el-image>
        </template>
        <!-- 操作 -->
        <template #controls="{ row }">
          <el-link size="small" type="primary" @click="addEdit('detail', row)">查看</el-link>
          <el-link size="small" type="primary" @click="addEdit('edit', row)">编辑</el-link>
          <el-link size="small" type="danger" @click="deleteRow(row)">删除</el-link>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      ></Pages>
    </div>
    <!-- 详情 -->
    <DetailForm ref="detailDiloag" />
  </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 } from "vue";
const { proxy } = getCurrentInstance();
const detailDiloag = ref();
const searchBox = ref(); //搜索框

const searchConfiger = ref([
  { label: "指令标题", prop: 'instructionTitle', placeholder: "请输入指令标题", showType: "input" },
  { label: "督办对象", prop: 'supervisoryObject', placeholder: "请输入督办对象", showType: "input" },
  { label: "指令类型", prop: 'instructionType', placeholder: "请选择指令类型", showType: "input" },
  { label: "指令等级", prop: 'instructionLevel', placeholder: "请选择指令等级", showType: "input" },
  { label: "指令来源", prop: 'instructionSource', placeholder: "请输入指令来源", showType: "input" },
  { label: "处置状态", prop: 'processingStatus', placeholder: "请选择处置状态", showType: "input" },
  { label: "数据来源", prop: 'dataSource', placeholder: "请输入数据来源", showType: "input" },
  { label: "反馈截止时间", prop: 'feedbackDeadline', placeholder: "请选择反馈截止时间", showType: "input" },
  { label: "指令流向", prop: 'instructionFlow', placeholder: "请输入指令流向", showType: "input" },
]);

const queryFrom = ref({});
const pageData = reactive({
    tableData: [
      {id: 1, instructionFlow: '本级发起', instructionTitle: '关于XX的指令', urgencyLevel: '紧急', informationSource: '信息来源', workingStatus: '工作中', supervisoryObject: '督办对象', instructionLevel: '一级', feedbackPosition: '反馈位置', feedbackDeadline: '2024-01-20', receivedNumber: 5, unreceivedNumber: 2, processingStatus: '已处理', status: '已完成'},
    ],
    keyCount: 0,
    tableConfiger: {
      rowHieght: 61,
      showSelectType: "checkBox",
      loading: false
    },
    total: 0,
    pageConfiger: {
      pageSize: 20,
      pageCurrent: 1
    },
    controlsWidth: 180,
    tableColumn: [
      { label: '指令流向', prop: 'instructionFlow' },
      { label: '指令标题', prop: 'instructionTitle' },
      { label: '紧急程度', prop: 'urgencyLevel', width: 100 },
      { label: '信息来源', prop: 'informationSource' },
      { label: '工作状态', prop: 'workingStatus', width: 100 },
      { label: '督办对象', prop: 'supervisoryObject' },
      { label: '指令等级', prop: 'instructionLevel', width: 100 },
      { label: '反馈位置', prop: 'feedbackPosition' },
      { label: '反馈截止时间', prop: 'feedbackDeadline', width: 120 },
      { label: '发送人数', prop: 'receivedNumber', width: 100 },
      { label: '未接收人数', prop: 'unreceivedNumber', width: 100 },
      { label: '处置状态', prop: 'processingStatus', width: 100 },
      { label: '状态', prop: 'status', width: 100 },
    ]
  });

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

//选择类型
const handleType = (val) => {
  pageData.keyCount++;
  pageData.pageConfiger.pageCurrent = 1;
  getList()
}
// 搜索
const onSearch = (val) =>{
  queryFrom.value = {...val}
  pageData.pageConfiger.pageCurrent = 1;
  getList()
}

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

// 获取列表
const getList = (val) =>{
  // pageData.tableConfiger.loading = true;
  let data = { ...pageData.pageConfiger, ...queryFrom.value };
  // let url = '/mosty-lzcj/tbDwMbkf/queryList';
  // qcckPost(data,url).then(res=>{
  //   pageData.tableData = res.records || [];
  //   pageData.total = res.total;
  //   pageData.tableConfiger.loading = false;
  // }).catch(()=>{ pageData.tableConfiger.loading = false; })
}

// 详情
const addEdit = (type, row) => {
  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>
