<template>
  <MOSTY.PageTree :pageTitle="'辨识计划列表'" :isShowLeftTree="false">
    <template #serach>
      <el-divider />
      <MOSTY.Search :searchArr="searchArr" @submit="onSearch" />
    </template>
    <template #table>
      <section class="eltab7">
        <MOSTY.Table :table-columns="tableColumn" :tableData="tableData" :tableloading="tableloading" :isSelect="false"
          :isSort="true" style="width: 100%;" :actionsW="280">
          <!-- D_BZ_BSLX -->
          <template #bslx="{ row }">
            <dict-tag :options="D_BZ_BSLX" :value="row.bslx" :tag="false" />
          </template>
          <template #status="{ row }">
            <span v-if="row.status == '0'">辨识结束</span>
            <span v-if="row.status == '1'">未下发</span>
            <span v-if="row.status == '2'">辨识中</span>
          </template>
          <template #actions="{ row }">
            <span class="operesee" @click="handlehz(row)"
              v-if='row.bslx == "01" && (row.orgCode == getdept.ssdwid || row.orgCode == getdept.sssgsid)'> <el-icon>
                <Compass />
              </el-icon>汇总</span>
            <span class="operedit" @click="handleSee(row)"><el-icon>
                <EditPen />
              </el-icon>风险评价</span>
            <span class="operedit" @click="handleview(row)"><el-icon>
                <EditPen />
              </el-icon>查看进度</span>
            <!--全员辨识： 省公司：getdept.orgleve:1*; 市公司：row.orgLevel=="20";县公司：row.orgLevel=="30"  （必须为安全员）-->
            <!-- <span class="operesee" @click="handlebsjd(row)"
              v-if='row.bslx == "01" && filterqx("isaqbm") == "1" && (filterqx("isSgs") == "1" || (filterqx("isgs") == "1" && row.orgLevel == "20") || (filterqx("isxgs") == "1" && row.orgLevel == "30"))'>
              <el-icon>
                <EditPen />
              </el-icon>红橙风险情况
            </span> -->

            <!--专项辨识： 安全部门（省：||市：row.orgLevel=="20"||row.orgLevel=="30） -->
            <!-- <span class="operesee" @click="handlebsjd(row)"
              v-if='row.bslx == "02" && filterqx("isaqbm") == "1" && (filterqx("isSgs") == "1" || (filterqx("isgs") == "1" && ["20", "30"].includes(row.orgLevel)))'>
              <el-icon>
                <EditPen />
              </el-icon>红橙风险情况
            </span> -->
            <!-- <span class="operedown" @click="handlejd(row)" v-if="row.status == '0'">
              <el-icon>
                <Eleme />
              </el-icon>
               </span> -->
          </template>

        </MOSTY.Table>
      </section>
      <div class="fenye">
        <MOSTY.Pages :pageConfiger="listQuery" @changeSize="handleSizeChange" @changeNo="handleCurrentChange">
        </MOSTY.Pages>
      </div>
    </template>
  </MOSTY.PageTree>
  <!-- <el-dialog v-model="showdia" :title="'选择单位'" :close-on-click-modal="false" width="30%" :show-close="false">
    <div>
      <el-form class="mosty-from-wrap" ref="elform" label-width="130px" :model="ruleForm" :inline="true" :rules="rules">
        <el-form-item label="单位:" style="width: 100%" prop="orgid">
          <el-select v-model="ruleForm.orgid" clearable placeholder="请选择单位" style="width: 250px">
            <el-option v-for="item in bmList" :key="item" :label="item.orgname" :value="item.orgid" />
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="savebmyj(elform)">确定</el-button>
        <el-button @click="xqproms">取消</el-button>
      </span>
    </template>
  </el-dialog> -->
  <!-- 全员辨识 -->
  <!-- 部门汇总 -->
  <div v-if="addDiaShow" class="dialog-box">
    <Summary @close="closede" :planid="planid" ></Summary>
  </div>

  <!-- 风险评价 -->
  <!-- 安全部门负责人 -->
  <div v-if="showfgspage" class="dialog-box">
    <Bspjindex @close="closede" :planid="planid" :btnshow="btnshow" :initPage="initPage" :orgCodeId="orgCodeId">
    </Bspjindex>
  </div>
  <!-- 单位辨识进度 -->
  <div v-if="showdwbsjdpage" class="dialog-box">
    <Dwfxbsjd @close="closede" :planid="planid" :btnshow="btnshow" :initPage="initPage"></Dwfxbsjd>
  </div>
  <!-- 评价小组成员 -->
  <div v-if="showpjxzpage" class="dialog-box">
    <Cypjindex @close="closede" :planid="planid" :orgid="ruleForm.orgid" :spflg='spflg'></Cypjindex>
  </div>
  <!-- 辨识进度 -->
  <div v-if="showsjd" class="dialog-box">
    <bshzbsjd @close="close" :planid="planid" />
  </div>

  <!-- 专项辨识 -->
  <div v-if="showzxfgspage" class="dialog-box">
    <Zxbspjindex @close="closede" :planid="planid" :btnshow="btnshow" :initPage="initPage" />
  </div>
  <!--红橙风险 -->
  <div v-if="showzxdwbsjdpage" class="dialog-box">
    <Zxdwfxbsjd @close="closede" :planid="planid" :btnshow="btnshow" :initPage="initPage" />
  </div>
  <div v-if="chakanjinduShow" class="dialog-box">
    <ckjd @close="closede" :planid="planid" :btnshow="btnshow" :initPage="initPage"></ckjd>
  </div>

</template>

<script setup>
// 引入
import { reactive, watch, onMounted, getCurrentInstance, ref } from 'vue'
import bshzbsjd from "./bshzbsjd.vue";
import * as MOSTY from "@/components/MyComponents/index";
import Summary from "./Summary.vue";
import Cypjindex from "./cypjindex.vue";
import { getItem } from "@/utils/storage"
import Bspjindex from "./bspjindexNew.vue";
import { getApi } from "@/api/tobAcco_api.js";
import { filterYear, filterqx } from "@/utils/auth.js";
import Dwfxbsjd from './dwfxbsjd.vue';
import Zxbspjindex from './zxbs/Zxbspjindex.vue';
import Zxdwfxbsjd from './zxbs/Zxdwfxbsjd.vue';
import ckjd from './ckjd.vue';
const { proxy } = getCurrentInstance();
const { D_BZ_BSLX, D_BZ_PJFS } = proxy.$dict("D_BZ_BSLX", "D_BZ_PJFS")
const addDiaShow = ref(false);
const showdwbsjdpage = ref(false)
const showzxdwbsjdpage = ref(false)
const getdept = ref(getItem('deptId'))
const planid = ref(null);
const orgCodeId = ref(null);
const chakanjinduShow = ref(false);
const showpjxzpage = ref(false)
const spflg = ref()
const initPage = ref({})
const showsjd = ref(false);
const btnshow = ref(false);
const showdia = ref(false);
const showfgspage = ref(false);
const showzxfgspage = ref(false)
const bmList = ref([])
const searchArr = reactive([
  {
    showType: "select",
    prop: "identifyYear",
    width: '250px',
    defaultVal: new Date().getFullYear(),
    options: filterYear(7),
  }
]);
//表单数据
const ruleForm = ref({ orgid: '' });
//规则校验
const rules = reactive({
  begindate: [
    { required: true, message: "开始日期不能为空", trigger: "blur" }
  ],
  enddate: [
    { required: true, message: "截止日期不能为空", trigger: "blur" }
  ],
  identifyName: [
    {
      trigger: "blur",
      required: true,
      message: "辨识名称不能为空",
    }
  ],
  orgid: [{ required: true, message: "请选择单位", trigger: "chanage" }]
});
const tableColumn = ref([
  {
    title: "辨识名称",
    prop: "identifyName",
    sortable: true
  },
  {
    title: "发起部门",
    prop: "orgName",
    sortable: true
  },
  {
    title: "辨识类型",
    prop: "bslx",
    slot: true,
    sortable: true
  },
  {
    title: "开始时间",
    prop: "begindate",
    sortable: true
  },
  {
    title: "结束时间",
    prop: "enddate",
    sortable: true
  },
  {
    title: "状态",
    prop: "status",
    slot: true,
    sortable: true
  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
])
const tableloading = ref(false)
// 表格高度
const tableHeight = ref()
// 分页
const listQuery = ref({
  pageCurrent: 1,
  pageSize: 20,
  total: 0,
  identifyYear: new Date().getFullYear(),
  status: '0,2'
});
const total = ref(0);
const parentstatusfn = (row) => {
  console.log(row, 'canshu');

}
// 表格数据
const tableData = ref([])
//查询
function onSearch (obj) {
  listQuery.value.identifyYear = obj.identifyYear
  listQuery.value.pageCurrent = 1
  getTabList();
}


//获取表格数据
function getTabList () {
  tableloading.value = true
  getApi(listQuery.value, '/mosty-jcgl/dangerPlanlist/getPageList').then((res) => {
    listQuery.value.total = res.total;
    tableData.value = res.records
  }).finally(() => {
    tableloading.value = false
  })
}

function closede () {
  addDiaShow.value = false
  showfgspage.value = false
  showpjxzpage.value = false
  showdwbsjdpage.value = false
  showzxfgspage.value = false
  showzxdwbsjdpage.value = false
  chakanjinduShow.value = false
}

const handlehz = (row) => {
  getsfgoto(row.id)
  planid.value = row.id
};
//部门汇总-页面进入之前调用
function getsfgoto (planid) {
  getApi({ planid }, '/mosty-jcgl/dangerPlanlist/bmhzInitPage').then(res => {
    addDiaShow.value = true
  })
}
// 风险评价
const handleSee = (row) => {
  planid.value = row.id
  orgCodeId.value = row.orgCode
  getchangegoto(row.id, row.bslx)
};
// 查看进度
const handleview = (row, plan) => {
  planid.value = row.id
  chakanjinduShow.value = true
}

//辨识评价-页面跳转查询
function getchangegoto (planid, bslx) {
  if (bslx == '01') {
    //全员参与
    getApi({ planid }, '/mosty-jcgl/dangerPlanlist/bspj/initPage').then(res => {
      initPage.value = res
      //安全部门负责人进入,有查询所有分公司的权限和添加修改评价小组权限
      btnshow.value = res.role == 'AQY' ? true : false
      showfgspage.value = true

    })
  } else {
    //专项辨识
    getApi({ planid }, '/mosty-jcgl/identifyUser/initPage').then(res => {
      initPage.value = res
      //安全部门负责人进入,有查询所有分公司的权限和添加修改评价小组权限
      btnshow.value = res.role == 'AQY' ? true : false
      showfgspage.value = true
    })
  }

}
//确定按钮
function savebmyj (formEl) {
  if (!formEl) return
  formEl.validate((valid, fields) => {
    if (valid) {
      bmList.value.forEach((item) => {
        if (item.orgid == ruleForm.value.orgid) {
          spflg.value = item.spflg ? item.spflg : null
        }
      })
      showdia.value = false
      showpjxzpage.value = true
    }
  })
}
//取消
function xqproms () {
  showdia.value = false
}
//辨识进度
function handlejd (row) {
  planid.value = row.id
  showsjd.value = true
}

// 方法
const close = () => {
  showsjd.value = false;
  getTabList();
};

onMounted(() => {
  getTabList();
})


//分页
const handleSizeChange = (currentSize) => {
  listQuery.value.pageSize = currentSize;
  getTabList();
};
const handleCurrentChange = (currentPage) => {
  listQuery.value.pageCurrent = currentPage;
  getTabList();
};
</script>

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