<template>
  <div>
    <div class="titleBox">
      <PageTitle title="我的布控">
        <el-button type="primary" @click="handleAdd('add',null)">发起布控</el-button>
        <el-button type="primary">导出</el-button>
      </PageTitle>
    </div>
    <!-- 搜索 -->
    <div ref="searchBox">
      <Search :searchArr="searchConfiger" @submit="onSearch" />
    </div>
    <!-- 按钮组 -->
    <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"
        >
        <template #bkZt="{ row }">
          <DictTag :tag="false" :value="row.bkZt" :options="D_GS_BK_ZT" />
        </template>
        <template #bkDj="{ row }">
          <DictTag :tag="false" :value="row.bkDj" :options="D_GS_BK_DJ" />
        </template>
        <template #bkDx="{ row }">
          <DictTag :tag="false" :value="row.bkDx" :options="D_GS_BK_DX" />
        </template>
        <template #bkdxList="{ row }">
          <span v-if="row.bkdxList"><span class="nowrap" v-for="(it,idx) in row.bkdxList" :key="idx"> {{ it.ryXm }} <span v-if="idx < row.bkdxList.length-1">、</span></span></span>
          <span v-else>暂无</span>
        </template>
        <template #sjrs="{ row }">
          <span v-if="row.bkdxList"> {{ row.bkdxList.length }} </span>
           <span v-else>0</span>
        </template>
        <template #qyList="{ row }">
          <span v-for="(it,idx) in row.qyList" :key="idx"> {{ it.qymc }} <span v-if="idx < row.qyList.length-1">、</span></span>
        </template>
        <template #yjcs="{row}">
          <span @click="openWarning(row)" style="color: #00ffff;" class="mr5 pointer">{{ row.yjcs || 0}}</span>次
        </template>
          <!-- 操作 -->
          <template #controls="{ row }">
            <el-link type="primary" v-if="row.bkZt == '01'" size="small" @click="handleSend(row.id)">送审</el-link>
            <el-link type="primary" v-if="row.bkZt == '01'" 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>
  <!-- 布控对象 -->
  <AddBkdx ref="addBkdxForm" @change="getList" :dic="{D_GS_BK_DX,D_GS_BK_BKYS,D_BZ_XB,D_GS_BK_CZYQ,D_GS_BK_DJ,D_GS_BK_CZJSDWLX,D_GS_BK_TJFS}" />
  <!-- 预警弹窗 -->
  <YjDialog ref="warningkdxForm"></YjDialog>
</template>

<script setup>
import AddBkdx from "./components/addBkdx.vue";
import YjDialog from "./components/yjDialog.vue";
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";
const { proxy } = getCurrentInstance();
const { D_GS_BK_BKYS,D_BZ_XB,D_GS_BK_SJLX,D_GS_BK_DJ, D_GS_BK_DX, D_GS_BK_ZT,D_GS_BK_CZYQ,D_GS_BK_CZJSDWLX,D_GS_BK_TJFS } = proxy.$dict("D_GS_BK_BKYS","D_BZ_XB","D_GS_BK_SJLX","D_GS_BK_DJ","D_GS_BK_DX","D_GS_BK_ZT","D_GS_BK_CZYQ","D_GS_BK_CZJSDWLX","D_GS_BK_TJFS"); //获取字典数据
const addBkdxForm = ref(null); //布控对象组件
const warningkdxForm = ref(); //布控对象组件
const searchBox = ref(); //搜索框
const searchConfiger = ref([
  {
    label: "布控级别",
    prop: "bqjb",
    placeholder: "请选择布控级别",
    showType: "select",
    options: D_GS_BK_DJ
  },
  {
    label: "布控对象",
    prop: "bkDx",
    placeholder: "请选择布控对象",
    showType: "select",
    options: D_GS_BK_DX
  },
  {
    label: "布控状态",
    prop: "bkZt",
    placeholder: "请选择布控状态",
    showType: "select",
    options: D_GS_BK_ZT
  },
   {
    label: "布控时间类型",
    prop: "bkSjLx",
    placeholder: "请选择布控时间",
    showType: "date",
    options: D_GS_BK_SJLX
  },
]);
const queryFrom = ref({});
const pageData = reactive({
  tableData: [], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null", //选择类型
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页
  controlsWidth: 150, //操作栏宽度

  tableColumn: [
    { label: "布控级别", prop: "bkDj", showSolt: true },
    { label: "布控标题", prop: "bkBt" },
    { label: "布控对象", prop: "bkDx",showSolt: true ,showOverflowTooltip:true},
    { label: "布控对象信息", prop: "bkdxList",showSolt: true,showOverflowTooltip:true },
    { label: "布控范围", prop: "qyList", showSolt: true,showOverflowTooltip:true },
    { label: "涉及人数", prop: "sjrs",showSolt: true },
    { label: "预警次数", prop: "yjcs",showSolt: true  },
    { label: "开始时间", prop: "bkSjKs",showOverflowTooltip:true},
    { label: "结束时间", prop: "bkSjJs",showOverflowTooltip:true},
    { label: "布控发起人", prop: "bkfqrXm"},
    { label: "布控状态", prop: "bkZt",showSolt: true}, 
  ]
});

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

// 搜索
const onSearch = (val) => {
  queryFrom.value = { ...val };
  pageData.pageConfiger.pageCurrent = 1;
  getList();
};

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

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

// 打开预警
const openWarning = (val) =>{
  warningkdxForm.value.init(val)
}

const handleAdd = (type,row) => {
  addBkdxForm.value.init(type,row);
};

// 送审
const handleSend = (id) =>{
  proxy.$confirm("确定要送审？", "警告", { type: "warning" }).then(() => {
    qcckPost({}, "/mosty-gsxt/tbGsxtBk/subExamine/"+id).then(() => {
      proxy.$message({ type: "success", message: "送审成功" });
      getList();
    });
  })
}

// 删除
const handleRow = (id) => {
  proxy.$confirm("确定要删除？", "警告", { type: "warning" }).then(() => {
    qcckDelete({}, "/mosty-gsxt/tbGsxtBk/"+id).then(() => {
      proxy.$message({ type: "success", message: "删除成功" });
      getList();
    });
  })
};

// 表格高度计算
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>
