<!-- 隐患复查 -->
<template>
  <div class="app-container hiddenDangersReview">
    <div class="page-container hiddenDangersReviewPage" v-if="pageType === 1">
      <div class="page-form-title-box" :class="advancedType?'page-advanced-form-title-box':''">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <div class="table-school-college-toggle-box">
            <p :class="reviewStatus==null?'p-check':''" @click="tableCheck(null)">全部</p>
            <p :class="reviewStatus==0?'p-check':''" @click="tableCheck(0)">待复查</p>
            <p :class="reviewStatus==1?'p-check':''" @click="tableCheck(1)">已复查</p>
          </div>
          <el-form-item label="" prop="planTitle">
            <el-input
              maxLength="30"
              v-model="queryParams.planTitle"
              placeholder="计划标题"
              style="width: 150px"
            />
          </el-form-item>
          <el-form-item label="" prop="hazardCheckPro">
            <el-cascader
              style="width: 150px"
              placeholder="检查指标"
              v-model="queryParams.hazardCheckPro"
              filterable
              :show-all-levels="false"
              :options="cascaderData"
              :props="{ value: 'id', label: 'labelName',emitPath:false }"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="" prop="hazardCheckName">
            <el-input
              maxLength="30"
              v-model="queryParams.hazardCheckName"
              placeholder="模糊搜索检查指标项"
              style="width: 170px"
            />
          </el-form-item>
          <el-form-item label="" prop="deptId">
            <el-select v-model="queryParams.deptId" placeholder="学院单位" style="width: 180px">
              <el-option
                v-for="dict in deptOption"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="levelId">
            <el-select v-model="queryParams.levelId" placeholder="安全分级" style="width: 180px">
              <el-option
                v-for="dict in levelOption"
                :key="dict.levelId"
                :label="dict.levelName"
                :value="dict.levelId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="searchValue" v-if="advancedType">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="实验室/房间号"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="rectifyName" v-if="advancedType">
            <el-input
              maxLength="30"
              v-model="queryParams.rectifyName"
              placeholder="复查人"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="state" v-if="advancedType">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 280px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-save-common-style-button" style="display: inline-block;margin-left:10px;" @click="searchToggle">{{advancedType?'普通搜索':'高级搜索'}}</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="序号" type="index" width="60"/>
          <el-table-column label="计划标题" prop="planTitle"  show-overflow-tooltip/>
          <el-table-column label="检查类型" prop="checkTypeName" width="100" show-overflow-tooltip/>
          <el-table-column label="检查名称" prop="checkName" width="100" show-overflow-tooltip/>
          <el-table-column label="检查项目" prop="hazardCheckCode" width="260" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.hazardCheckCode}} {{scope.row.hazardCheckName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="实验室" prop="subName" width="165" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.subName}}{{scope.row.roomNum?'('+scope.row.roomNum+')':''}}</span>
            </template>
          </el-table-column>
          <el-table-column label="检查人" prop="createName" width="80" show-overflow-tooltip/>
          <el-table-column label="复查人" prop="reviewName" width="80" show-overflow-tooltip/>
          <el-table-column label="复查状态" prop="reviewStatus" width="80" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.reviewStatus == 1?'已复查':(scope.row.reviewStatus == 0?'未复查':'')}}</span>
            </template>
          </el-table-column>
          <el-table-column label="复查结果" prop="examineResult" width="80" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.examineResult == 1?'复查完毕':(scope.row.examineResult == 0?'退回整改':'')}}</span>
            </template>
          </el-table-column>
          <el-table-column label="复查时间" prop="reviewTime" width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.reviewTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="130" show-overflow-tooltip >
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   v-if="scope.row.reviewButtion && scope.row.isReviewer"
                   v-hasPermiRouter="['security:myreview:add']"
                   @click="tableButton(1,scope.row)"
                >复查</p>
                <p class="table-button-p"
                   v-if="!scope.row.reviewButtion"
                   @click="tableButton(2,scope.row)"
                >详情</p>
                <p class="table-button-p"
                   v-if="scope.row.isAdmin"
                   v-hasPermiRouter="['security:myreview:edit']"
                   @click="tableButton(3,scope.row)"
                >转移</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <el-dialog class="hiddenDangersReview-dialog" title='复查人转移' width="745px" append-to-body
               :visible.sync="dialogType" v-if="dialogType" @close="dialogOff()"
               :close-on-click-modal="false" :close-on-press-escape="false">
      <div class="hiddenDangersReview-dialog-max-box">
        <p class="hiddenDangersReview-dialog-name">{{dialogGroupName}}</p>
        <div class="hiddenDangersReview-dialog-box">
          <img src="@/assets/ZDimages/safetyCheck/icon_xyxc_cy.png">
          <p>成员列表</p>
        </div>
        <el-table class="table-box table-null-img-20" border :data="dialogDataList">
          <el-table-column label="" align="center" width="150">
            <template scope="scope">
              <div class="check-img-box" v-if="dialogUserId != scope.row.userId"
                   @click="tableColumnCheck(scope.row)">
                <img src="@/assets/ZDimages/basicsModules/icon_fcrzy_wxz@1x.png" v-if="scope.row.userId != reviewUserid">
                <img src="@/assets/ZDimages/basicsModules/icon_fcrzy_xz@1x.png" v-if="scope.row.userId == reviewUserid">
              </div>
              <p v-if="dialogUserId == scope.row.userId" style="text-align: center!important;">负责人</p>
            </template>
          </el-table-column>
          <el-table-column label="姓名" prop="userName" show-overflow-tooltip/>
          <el-table-column label="工号" prop="account" width="130" show-overflow-tooltip/>
          <el-table-column label="所在部门" prop="deptName" width="188" show-overflow-tooltip/>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="dialogTotal>0"
                    :total="dialogTotal"
                    :page.sync="dialogQueryParams.page"
                    :limit.sync="dialogQueryParams.pageSize"
                    @pagination="securityCheckDangerGetMemberList"
        />
      </div>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-info" @click="dialogOff()">取消</p>
        <p class="dialog-footer-button-primary" @click="dialogSubmit">确认</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </el-dialog>
    <initiateInspect v-if="pageType == 2" :initiateInspectData="initiateInspectData"></initiateInspect>
  </div>
</template>
<script>
  import {
    getDeptDropList,
    laboratoryClassLevelGetList,
  } from '@/api/commonality/permission'
  import {
    securityCheckOptionList,
    securityCheckDangerReviewList,
    securityCheckDangerGetMemberInfo,
    securityCheckDangerGetMemberList,
    securityCheckDangerUpdateByReview,
  } from "@/api/safetyCheck/index";
  import initiateInspect from "@/views/safetyCheck/components/initiateInspect/initiateInspect.vue";
  export default {
    name: 'index',
    components: {
      initiateInspect
    },
    data () {
      return {
        //页面状态
        pageType:1,
        //复查状态选项卡
        reviewStatus:null,
        //页面遮罩
        loading:false,
        //学院列表
        deptOption:[],
        //分级下拉列表
        levelOption:[],
        //检查项下拉列表
        cascaderData:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          planTitle:"",
          hazardCheckPro :null,
          hazardCheckName:"",
          deptId :null,
          levelId :null,
          searchValue:"",
          rectifyName:"",
        },
        //时间数据
        dateRange:[],
        //搜索模式切换
        advancedType:false,
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        initiateInspectData:{},
        //复查转移
        dialogGroupName:'',
        dialogUserId:'',
        dialogQueryParams:{
          page:1,
          pageSize:20,
        },
        dialogDataList:[],
        dialogTotal:0,
        dialogType:false,
        dialogDangerId:'',
        reviewUserid:null,
        reviewName:null
      }
    },
    created () {
      this.getDeptDropList();
      this.laboratoryClassLevelGetList();
      this.securityCheckOptionList();
    },
    mounted () {
      this.getList();
    },
    methods: {
      //复查状态选项卡切换
      tableCheck(type){
        if (this.reviewStatus !== type){
          this.$set(this,'reviewStatus',type);
          this.resetQuery();
        }
      },
      //搜索模式切换
      searchToggle(){
        this.$set(this,'advancedType',!this.advancedType);
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          planTitle:"",
          hazardCheckPro :null,
          hazardCheckName:"",
          deptId :null,
          levelId :null,
          searchValue:"",
          rectifyName:"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        let data = {
          checkCategory:2,
          reviewStatus:this.reviewStatus,
          page:obj.page,
          pageSize:obj.pageSize,
          planTitle:obj.planTitle,
          hazardCheckPro:obj.hazardCheckPro,
          hazardCheckName:obj.hazardCheckName,
          deptId:obj.deptId,
          levelId:obj.levelId,
        };
        if(this.advancedType){
          data.searchValue = obj.searchValue;
          data.rectifyName = obj.rectifyName;
          if(this.dateRange[0]){
            data.startTime = this.dateRange[0]+'T00:00:00'
            data.endTime = this.dateRange[1]+'T23:59:59'
          }else{
            data.startTime = "";
            data.endTime = "";
          }
        }
        securityCheckDangerReviewList(data).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //整改
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          obj.showType = false;
          obj.orderTitle = '复查验证';
          obj.orderType = '5';
          this.$set(this,'initiateInspectData',obj);
        }else if(type == 2){
          //详情
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          obj.showType = true;
          obj.orderTitle = '复查详情';
          obj.orderType = '6';
          this.$set(this,'initiateInspectData',obj);
        }else if(type == 3){
          //转移
          this.$set(this.dialogQueryParams,'page',1);
          this.$set(this,'dialogDangerId',row.dangerId);
          this.securityCheckDangerGetMemberInfo(row.dangerId);
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      //督导组信息查询
      securityCheckDangerGetMemberInfo(dangerId){
        securityCheckDangerGetMemberInfo({dangerId:dangerId}).then(response => {
          this.$set(this,'dialogGroupName',response.data.groupName);
          this.$set(this,'dialogUserId',response.data.userId);
          this.$nextTick(()=>{
            this.securityCheckDangerGetMemberList(dangerId);
          })
        });
      },
      //督导组人员查询
      securityCheckDangerGetMemberList(dangerId){
        let obj = JSON.parse(JSON.stringify(this.dialogQueryParams))
        obj.dangerId = dangerId;
        securityCheckDangerGetMemberList(obj).then(response => {
          this.$set(this,'dialogDataList',response.data.records);
          this.$set(this,'dialogTotal',response.data.total);
          this.$nextTick(()=>{
            if(!this.dialogType){
              this.dialogOpen();
            }
          })
        });
      },
      /******** 转移弹窗 ********/
      //弹层关闭
      dialogOff(){
        this.$set(this,'dialogType',false);
      },
      //弹层开启
      dialogOpen(){
        this.$set(this,'reviewUserid',null);
        this.$set(this,'dialogType',true);
      },
      //弹层确定
      dialogSubmit(){
        if(!this.reviewUserid){
          this.msgError('请选择复查转移人')
          return
        }
        let obj = {
          dangerId:this.dialogDangerId,
          reviewUserid:this.reviewUserid,
          reviewName:this.reviewName,
        };
        securityCheckDangerUpdateByReview(obj).then(response => {
          this.msgSuccess(response.message)
          this.$set(this,'dialogType',false);
          this.getList();
        });
      },
      tableColumnCheck(row) {
        if(this.reviewUserid != row.userId){
          this.$set(this,'reviewUserid',row.userId);
          this.$set(this,'reviewName',row.userName);
        }
      },
      //学院列表
      getDeptDropList() {
        getDeptDropList({ deptName: '', level: 2, deptType: 1 }).then(response => {
          this.$set(this, 'deptOption', response.data)
        })
      },
      //分级下拉列表
      laboratoryClassLevelGetList(){
        laboratoryClassLevelGetList({}).then(response => {
          this.$set(this,'levelOption',response.data);
        });
      },
      //检查项列表
      securityCheckOptionList() {
        securityCheckOptionList({}).then(response => {
          let list = this.getCascaderData(JSON.parse(JSON.stringify(response.data)),3)
          this.$nextTick(()=>{
            this.$set(this, 'cascaderData', list)
          })
        })
      },
      //检查项格式处理
      getCascaderData(list,type) {
        let self = this
        for (let i = 0; i < list.length; i++) {
          list[i].labelName = list[i].code ? list[i].code + ' ' + list[i].name : list[i].name
          if(list[i].level == type){
            delete list[i].children
          }else if (list[i].children) {
            if (list[i].children[0]) {
              list[i].children = self.getCascaderData(list[i].children,type)
            } else {
              list.splice(i, 1)
              i--
            }
          } else {
            list.splice(i, 1)
            i--
          }
        }
        for (let i = 0; i < list.length; i++) {
          list[i].labelName = list[i].code ? list[i].code + ' ' + list[i].name : list[i].name
          if(list[i].level == type){
            delete list[i].children
          }else if (list[i].children) {
            if (list[i].children[0]) {
              list[i].children = self.getCascaderData(list[i].children,type)
            } else {
              list.splice(i, 1)
              i--
            }
          } else {
            list.splice(i, 1)
            i--
          }
        }
        for (let i = 0; i < list.length; i++) {
          list[i].labelName = list[i].code ? list[i].code + ' ' + list[i].name : list[i].name
          if(list[i].level == type){
            delete list[i].children
          }else if (list[i].children) {
            if (list[i].children[0]) {
              list[i].children = self.getCascaderData(list[i].children,type)
            } else {
              list.splice(i, 1)
              i--
            }
          } else {
            list.splice(i, 1)
            i--
          }
        }
        return list
      },
    },
  }
</script>
<style scoped lang="scss">
  .hiddenDangersReview{
    .hiddenDangersReviewPage{
      .table-school-college-toggle-box{
        overflow: hidden;
        display: inline-block;
        margin-right:10px;
        p{
          display: inline-block;
          text-align: center;
          width:80px;
          line-height:40px;
          height:40px;
          color:#333;
          background-color: #fff;
          border:1px solid #E0E0E0;
          font-size:14px;
          cursor: pointer;
        }
        p:nth-child(1){
          border-top-left-radius: 4px;
          border-bottom-left-radius: 4px;
          /*border-right:none;*/
        }
        p:nth-child(4){
          border-top-right-radius: 4px;
          border-bottom-right-radius: 4px;
          /*border-left:none;*/
        }
        .p-check{
          border:1px solid #0183FA;
          background-color: #0183FA;
          color:#fff;
        }
      }
      .form-button-max-big-box-me{
        display: inline-block;
        overflow: hidden;
        margin-right:10px;
        .form-button-big-box-me{
          display: flex;
          div{
            position: relative;
            height:40px;
            width:100px;
            line-height: 40px;
            text-align: center;
            color:#999;
            font-size:14px;
            border:1px solid #999;
            border-radius:4px;
            font-weight:500;
            cursor: pointer;
            .icon-p-me{
              width:15px;
              height:15px;
              line-height:15px;
              text-align: center;
              position: absolute;
              right:0;
              bottom:0;
              color:#fff;
              background: #0183fa;
              border-top-left-radius:4px;
            }
          }
          .checkDiv-me{
            color:#0183FA!important;
            border:1px solid #0183FA!important;
          }
        }
      }
    }
  }
</style>
<style lang="scss">
  .hiddenDangersReview-dialog{
    .el-dialog__body{
      padding-top: 0;
    }
    .hiddenDangersReview-dialog-max-box{
      height:500px;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      flex:1;
      .hiddenDangersReview-dialog-name{
        line-height:70px;
        height:70px;
        font-size:16px;
      }
      .hiddenDangersReview-dialog-box{
        display: flex;
        border:1px solid #dedede;
        border-bottom:none;
        height:40px;
        img{
          width:14px;
          height:14px;
          display: inline-block;
          margin:13px 15px;
        }
        p:nth-child(2){
          flex:1;
          font-size:14px;
          line-height:40px;
          color:#333;
        }
      }
      .check-img-box{
        cursor: pointer;
        height:27px;
        width:130px;
        margin:0 auto;
        overflow: hidden;
        img{
          overflow: hidden;
          height:20px;
          width:20px;
          display: inline-block;
          margin:3px 55px;
        }
      }
    }
  }
</style>
