<template>
  <MOSTY.PageTree :pageTitle="'综合检查配置'" :searchType="'01'" @getDeptId="getdeptId">
    <template #serach>
      <el-divider />
      <MOSTY.Search :searchArr="searchArr" @submit="onSearch" />
      <el-divider />
      <div class="btnBox">
        <el-button type="primary" @click="handleAdd">
          <el-icon>
            <CirclePlus />
          </el-icon>
          <span>新增</span>
        </el-button>
      </div>
    </template>
    <template #table>
      <section class="eltab9">
        <MOSTY.Table :table-columns="tableColumns" :tableData="tableData" :tableloading="tableloading" :isSelect="true"
          :isSort="true" actionsW="380">
          <template #half="{ row }">
            <dict-tag :options="D_TB_FQJCLX" :value="row.half" :tag="false" />
          </template>
          <template #status="{ row }">
            <span v-if="row.status == 0">未下发</span>
            <span v-else-if="row.status == 1">已下发</span>
            <span v-else-if="row.status == 2">已结束</span>
          </template>
          <template #checkType="{ row }">
            <span v-if="row.checkType == 1">常规检查</span>
            <span v-else-if="row.checkType == 2">暗查暗访</span>
          </template>
          <template #actions="scope">
            <div style="flex-wrap: wrap;align-items: center;" class="flex">
              <popperConfirm style="padding-top: 1px;padding-bottom: 2px;" delContent="结束检查" delTitle="是否结束检查"
                :ids="scope.row.id" v-if="scope.row.status === '1'" @isNot="isNot">
              </popperConfirm>
              <span class="operesee" @click="handleSee(scope.row, 'see')"><el-icon>
                  <Compass />
                </el-icon>查看</span>
              <span class="operedit" @click="handleChange(scope.row)" v-if="scope.row.status === '0'"><el-icon>
                  <EditPen />
                </el-icon>
                修改
              </span>
              <popperConfirm style="padding-top: 1px;padding-bottom: 2px;" :ids="scope.row.id"
                v-if="scope.row.status === '0'" delContent="下发" delTitle="是否下发" @isNot="isNot">
              </popperConfirm>
              <span class="operedit" @click="inspectionrecordFn(scope.row)" v-if="scope.row.status !== '0'">
                <el-icon>
                  <PieChart />
                </el-icon>
                检查记录
              </span>
              <span class="operedit" @click="handleTj(scope.row)"
                v-if="scope.row.status === '1' || scope.row.status === '2'">
                <el-icon>
                  <PieChart />
                </el-icon>
                隐患统计
              </span>
              <span class="operedown" @click="opendxm(scope.row, true)"
                v-if="scope.row.status === '2' && orgLevel != '3'">
                <el-icon>
                  <Compass />
                </el-icon>
                点线面分析
              </span>
              <span class="operedown" @click="opendxm(scope.row, false)"
                v-if="scope.row.status === '2' && orgLevel == '3'">
                <el-icon>
                  <Compass />
                </el-icon>
                隐患分析处理
              </span>
              <span v-if="scope.row.status != 0" class="operesee" @click="addYh(scope.row)">
                <el-icon>
                  <CirclePlus />
                </el-icon>
                添加隐患
              </span>

              <el-popconfirm v-if="getItem('USERID') == '000000'" confirm-button-text="是" cancel-button-text="否"
                icon-color="red" title="确定补发任务?" @confirm="bfrw(scope.row)">
                <template #reference>
                  <span class="operedown" size="small">
                    <el-icon>
                      <Position />
                    </el-icon>
                    补发任务
                  </span>
                </template>
              </el-popconfirm>
              <el-popconfirm v-if="scope.row.status == 0 && filterqx('isaqbm') == '1'" confirm-button-text="是"
                cancel-button-text="否" icon-color="red" title="确定删除?" @confirm="handledelete(scope.row)">
                <template #reference>
                  <span class="operdel" size="small">
                    <el-icon>
                      <Delete />
                    </el-icon>
                    删除
                  </span>
                </template>
              </el-popconfirm>
            </div>
          </template>
        </MOSTY.Table>
      </section>
      <div class="fenye">
        <MOSTY.Pages :pageConfiger="rightListQuery" @changeNo="handleCurrentChange" @changeSize="handleSizeChange" />
      </div>
    </template>

  </MOSTY.PageTree>
  <!-- 新增弹出框 -->
  <div v-if="addDiaShow" class="dialog-box">
    <addDia :title="title" :xqId="xqId" @changeAddVi="changeAddVi" :tabledata="seeData">
    </addDia>
  </div>
  <!-- 检查记录 -->
  <div v-if="inspectionrecordShow" class="dialog-box">
    <inspectionrecord :title="title" :xqId="xqId" @changeAddVi="changeAddVi" @close="inspectionrecordClose"
      :tabledata="seeData">
    </inspectionrecord>
  </div>
  <!-- 新增弹出框 -->
  <div v-if="isShowAddYh" class="dialog-box">
    <addYhDialog title="新增隐患" :row="currRow" @ok="addYhClose" @close="addYhClose" />
  </div>
  <!-- 检查统计弹出框 -->
  <tjDia :tjDiaShow="tjDiaShow" :tjId="tjId" :tjTitle="tjTitle" @changeTjVi="changeTjVi"></tjDia>
  <!-- 综合编辑 -->
  <div v-if="comprehensiveShow" class="dialog-box">
    <Zhbj @close="close" />
  </div>
</template>

<script setup>
// 引入
import { onMounted, ref, getCurrentInstance, reactive } from "vue";
import addDia from "../components/zhjc/Addzhjc.vue";
import popperConfirm from "../components/popperConfirm.vue";
import tjDia from "../components/zhjc/tjDia.vue";
import inspectionrecord from "../components/zhjc/inspectionrecord.vue";
import * as MOSTY from "@/components/MyComponents/index";
import { getApi, postApi } from "@/api/tobAcco_api.js";
import Zhbj from "./zhbj.vue";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { getItem } from "@/utils/storage"
import addYhDialog from "./components/zhjcCom/addYh.vue";
import { ElMessage } from "element-plus";
import { filterqx } from "@/utils/auth.js";// isSgs,isgs,isxgs,isaqbm,isldbz
const inspectionrecordShow = ref(false);//检查记录弹出框
const store = useStore();
const router = useRouter();
const orgLevel = ref(JSON.parse(window.localStorage.getItem("deptId")).orgLevel.substring(0, 1))
const { proxy } = getCurrentInstance();
const { D_TB_FQJCLX } = proxy.$dict("D_TB_FQJCLX");
const tjId = ref("");
const xqId = ref("");
const tableData = ref([]);
const total = ref(0);
/** 控制新增弹出框的展示*/
const addDiaShow = ref(false);
const searchArr = reactive([
  {
    showType: "input",
    prop: "title",
    width: '250px',
    placeholder: '请输入检查名称查询'
  }
])
const tableColumns = reactive([
  {
    title: "检查标题",
    prop: "title",
  },
  {
    title: "检查类型",
    prop: "half",
    slot: true
  },
  {
    title: "检查方式",
    prop: "checkType",
    slot: true
  },
  {
    title: "检查配置人",
    prop: "pzrxm",
  },
  {
    title: "配置部门",
    prop: "deptname",
  },
  {
    title: "开始时间",
    prop: "startTime",
  },
  {
    title: "结束时间",
    prop: "endTime",
  },
  {
    title: "状态",
    prop: "status",
    slot: true
  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
])
const rightListQuery = ref({
  pageSize: 10,
  pageCurrent: 1,
  total: 0,
  deptId: "",
  title: ""
});
// 控制检查统计弹出框的展示
const tjDiaShow = ref(false);
const comprehensiveShow = ref(false);
const seeData = ref({});
const tjTitle = ref('')
const currRow = ref({});
/** 新增隐患 */
const isShowAddYh = ref(false)
// 控制新增与检查配置修改的标题
const title = ref("");
// 初始化
onMounted(() => {
});
// 查询
const onSearch = (obj) => {
  rightListQuery.value.title = obj.title;
  rightListQuery.value.pageCurrent = 1;
  getTableData();
}
//获取部门参数
const getdeptId = (val) => {
  rightListQuery.value.deptId = val.id;
  rightListQuery.value.pageCurrent = 1;
  getTableData();
};
// 获取表格数据
const getTableData = () => {
  getApi(rightListQuery.value, "/mosty-jcgl/zhjc/getPageList").then((res) => {
    tableData.value = res.records;
    rightListQuery.value.total = res.total;
  });
};
// 新增弹出框
const handleAdd = () => {
  xqId.value = null
  title.value = "新增检查配置";
  seeData.value = {};
  addDiaShow.value = true; // show 展示弹框
};
// 查看详情
const handleSee = (row) => {
  seeData.value = row;
  xqId.value = row.id;
  title.value = "检查配置详情";
  addDiaShow.value = true;
};
// 修改
const handleChange = (row) => {
  xqId.value = row.id;
  addDiaShow.value = true;
  title.value = "修改检查配置";
};

const addYh = (row) => {
  currRow.value = row || {};
  isShowAddYh.value = true
}
// 新增隐患
const bfrw = (row) => {
  getApi({ zhjcId: row.id }, '/mosty-jcgl/zhjc/reissueTask').then(res => {
    ElMessage.success('补发任务成功！')
  })
};
const addYhClose = (val) => {
  isShowAddYh.value = false
}
// 控制新增弹出框的展示
const changeAddVi = (val) => {
  addDiaShow.value = val;
  xqId.value = null;
  getTableData();
};
// 检查统计弹出
const handleTj = (row) => {
  tjId.value = row.id;
  tjTitle.value = row.title;
  tjDiaShow.value = true;
};
// 控制检查统计弹出框的展示
const changeTjVi = (val) => {
  tjDiaShow.value = val;
  tjId.value = null
  title.value = "";
};
// 关闭综合检查
const close = () => {
  comprehensiveShow.value = false;
  xqId.value = null
  seeData.value = {};
};
//页码发生变化
const handleCurrentChange = (val) => {
  rightListQuery.value.pageCurrent = val;
  getTableData();
};
//查询条数发生变化
const handleSizeChange = (val) => {
  rightListQuery.value.pageSize = val;
  getTableData();
};
// 是否结束下发的接口
const isNot = (title, id) => {
  if (title === "是否下发") {
    getApi({ zhjcId: id }, "/mosty-jcgl/zhjc/issue").then(() => {
      getTableData();
    });
  }
  if (title === "是否结束检查") {
    getApi({ zhjcId: id }, "/mosty-jcgl/zhjc/endZhjc").then(() => {
      getTableData();
    });
  }
};
//点线面
function opendxm(params, val) {
  store.state.zhjcId = params.id
  store.state.isShowshjcd = val
  if (val == true) {
    store.dispatch("user/setRouterName", '点线面分析');
  } else {
    store.dispatch("user/setRouterName", '隐患分析处理');
  }
  router.push({
    path: "/fxgk/jcss/dxmfx",
    query: { zhjcId: store.state.zhjcId }
  });
}
const handledelete = (row) => {
  postApi([row.id], "/mosty-jcgl/zhjc/delZhjc").then((res) => {
    ElMessage.success("删除成功");
    getTableData();
  });
};
// 检查记录
const inspectionrecordFn = (row) => {
  seeData.value = row;
  xqId.value = row.id;
  title.value = "检查记录";
  inspectionrecordShow.value = true;
};
// 控制检查记录弹出框的展示
const inspectionrecordClose = (val) => {
  inspectionrecordShow.value = false;
};
</script>

<style lang="scss" scoped>
.btnBox {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 12px;
}
</style>
