<!--实验室自查隐患-->
<template>
  <div class="departmentListPage">
    <div class="departmentListPage-page" v-if="minPageType == 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm" :inline="true" label-width="80px">
          <div class="form-button-max-big-box">
            <div class="form-button-big-box">
              <p class="text-p" :class="queryParams.rectifyStatus=='2'?'checkDiv':''" @click="topLeftClickType('2')">待整改</p>
              <p class="text-p" :class="queryParams.rectifyStatus=='3'?'checkDiv':''" @click="topLeftClickType('3')">待复核</p>
              <p class="text-p" :class="queryParams.rectifyStatus=='1'?'checkDiv':''" @click="topLeftClickType('1')">已完成</p>
            </div>
          </div>
          <!--与我相关-->
          <div class="form-button-max-big-box-me">
            <div class="form-button-big-box-me">
              <div :class="queryParams.myRelated==1?'checkDiv-me':''" @click="topRightClickType">
                <p class="text-p-me">与我有关{{correlationNum}}</p>
                <p class="el-icon-check icon-p-me" v-if="queryParams.myRelated==1"></p>
              </div>
            </div>
          </div>
          <el-form-item label="" prop="searchValue" style="margin-left:10px;">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="计划标题/实验室/房间号"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="dateRange" label-width="70px">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="" prop="examineResult">
            <el-select v-model="queryParams.examineResult" placeholder="审核状态" style="width: 160px">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery" style="margin-right:10px;">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-add-common-style-button"
             style="width:90px;float: right;"
             @click="goPage(2)"
          >批量审核</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" border :data="tableList" ref="multipleTable" @sort-change="sortChange">
          <el-table-column label="序号" align="center"  type="index" width="60" />
          <el-table-column label="计划标题" align="center" prop="title" show-overflow-tooltip/>
          <el-table-column label="隐患描述" align="center" prop="hazardDescribe" show-overflow-tooltip width="220"/>
          <el-table-column label="实验室" align="center" prop="subRoom" show-overflow-tooltip width="170"/>
          <el-table-column label="检查类型" align="center" prop="checkRange" show-overflow-tooltip width="120">
            <template slot-scope="scope">
              <p>{{scope.row.checkCategory==1?'综合检查':(scope.row.checkCategory==2?'专项检查':'-')}}</p>
            </template>
          </el-table-column>
          <el-table-column label="检查内容" align="center" prop="checkRange" show-overflow-tooltip width="120">
            <template slot-scope="scope">
              <p>{{scope.row.hazardName?scope.row.hazardName:'-'}}</p>
            </template>
          </el-table-column>
          <el-table-column label="检查时间" sortable="custom" align="center" prop="checkTime" show-overflow-tooltip width="160"/>
          <el-table-column label="整改人" align="center" prop="rectifyName" show-overflow-tooltip width="90"/>
          <el-table-column label="整改期限" sortable="custom" align="center" prop="rectifyDeadline" show-overflow-tooltip width="180">
            <template slot-scope="scope">
              <p>{{scope.row.rectifyDeadline}}<span v-if="scope.row.overdueStatus==1" style="margin-left:10px;color:#EE0606;">已逾期</span></p>
            </template>
          </el-table-column>
          <el-table-column label="整改状态" align="center" prop="rectifyStatus" show-overflow-tooltip width="110">
            <template slot-scope="scope">
              <p :class="scope.row.rectifyStatus==1?'rectifyStatusColorA':(scope.row.rectifyStatus==2||scope.row.rectifyStatus==3?'rectifyStatusColorB':'')">{{scope.row.rectifyStatus==1?'已完成':(scope.row.rectifyStatus==2?'待整改':(scope.row.rectifyStatus==3?'待复核':''))}}</p>
            </template>
          </el-table-column>
          <el-table-column label="整改时间" sortable="custom" align="center" prop="rectifyTime" show-overflow-tooltip width="170"/>
          <el-table-column label="审核状态" align="center" prop="examineResult" show-overflow-tooltip width="80">
            <template slot-scope="scope">
              {{scope.row.examineResult == 1?'已通过':(scope.row.examineResult == 0?'已驳回':(scope.row.examineResult == 2?'待审核':''))}}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="80">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p" v-hasPermiRouter="['safety:rectifyHazard:detail']"
                   @click="addDialogOpen(true,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>
    <batchAudit v-if="minPageType == 2" :propsBatchAuditData="propsBatchAuditData"></batchAudit>
    <infoDialog v-if="infoDialogType" :propsInfoDialogData="propsInfoDialogData"></infoDialog>
  </div>
</template>

<script>
  import { rectifyList, recheckList, overList } from '@/api/safetyCheck/indexTow'
  import batchAudit from './batchAudit.vue'
  import infoDialog from '@/views/safetyCheck/components/infoDialog/infoDialog.vue'
  export default {
    name: 'departmentListPage',
    components: {
      batchAudit,
      infoDialog
    },
    data(){
      return{
        //子组件参数
        propsBatchAuditData:{},
        propsInfoDialogData:{},
        minPageType:1,
        infoDialogType:false,
        options:[
          {value:"2",label:"待审核"},
          {value:"1",label:"已通过"},
          {value:"0",label:"已驳回"},
        ],
        queryParams:{
          page:1,
          pageSize:20,
          hazardType:2,
          rectifyStatus:"2",
          examineResult:"",
          searchValue:"",
          checkTimeOrder:"",
          zgTimeOrder:"",
          zgTermOrder:"",
          myRelated:1,
        },
        dateRange:[],
        tableList:[],
        total:0,
        correlationNum:'',
      }
    },
    created(){},
    mounted(){
      this.getList();
    },
    methods:{
      //获取相关数量
      getCorrelationNum(){
        rectifyList({
          page:1,
          pageSize:20,
          hazardType:2,
          checkTimeOrder:"",
          zgTimeOrder:"",
          zgTermOrder:"",
          myRelated:1,
          rectifyStatus:this.queryParams.rectifyStatus,
          examineResult:this.queryParams.examineResult,
          searchValue:this.queryParams.searchValue,
          beginTime:this.dateRange[0]?this.dateRange[0]:'',
          endTime:this.dateRange[1]?this.dateRange[1]:'',
        }).then(response => {
          this.$set(this,'correlationNum',response.data.total>999?' 999+':(response.data.total<1?'':' '+response.data.total));
        });
      },
      //与我相关按钮
      topRightClickType(){
        this.$set(this.queryParams,'myRelated',this.queryParams.myRelated==1?0:1);
        this.handleQuery();
      },
      //开关详情页面
      addDialogOpen(type,data){
        if(this.infoDialogType != type){
          if(type){
            let obj = {
              id:data.id
            }
            this.$set(this,'propsInfoDialogData',obj);
            this.$set(this,'infoDialogType',type);
          }else{
            this.getList();
            this.$set(this,'infoDialogType',type);
          }
        }
      },
      //页面切换
      goPage(type){
        if(this.minPageType != type){
          if(type == 1){
            //返回
            this.$set(this,'minPageType',type);
          }else if(type == 2){
            //批量审核
            this.$set(this,'propsBatchAuditData',{hazardType:2,});
            this.$set(this,'minPageType',type);
          }else if(type == 3){
            //返回并刷新
            this.getList();
            this.$set(this,'minPageType',1);
          }
        }
      },
      //范围选择
      topLeftClickType(type){
        if(this.queryParams.rectifyStatus != type){
          this.$set(this.queryParams,'rectifyStatus',type);
          this.handleQuery();
        }
      },
      //时间排序方法
      sortChange(val){
        if(val.prop == 'checkTime'){
          this.$set(this.queryParams,'checkTimeOrder',val.order=='ascending'?'1':(val.order=='descending'?'2':''));
          this.$set(this.queryParams,'zgTimeOrder','');
          this.$set(this.queryParams,'zgTermOrder','');
          this.handleQuery();
        }else if(val.prop == 'rectifyTime'){
          this.$set(this.queryParams,'zgTimeOrder',val.order=='ascending'?'1':(val.order=='descending'?'2':''));
          this.$set(this.queryParams,'checkTimeOrder','');
          this.$set(this.queryParams,'zgTermOrder','');
          this.handleQuery();
        }else if(val.prop == 'rectifyDeadline'){
          this.$set(this.queryParams,'zgTermOrder',val.order=='ascending'?'1':(val.order=='descending'?'2':''));
          this.$set(this.queryParams,'checkTimeOrder','');
          this.$set(this.queryParams,'zgTimeOrder','');
          this.handleQuery();
        }
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.beginTime = this.dateRange[0];
        }else{
          obj.beginTime = "";
        }
        if(this.dateRange[1]){
          obj.endTime = this.dateRange[1];
        }else{
          obj.endTime = "";
        }
        let self = this;
        setTimeout(function(){
          self.getCorrelationNum();
        },500);
        if(this.queryParams.rectifyStatus == 2){
          rectifyList(obj).then(response => {
            this.total = response.data.total;
            this.tableList = response.data.records;
          });
        } else if (this.queryParams.rectifyStatus == 3){
          recheckList(obj).then(response => {
            this.total = response.data.total;
            this.tableList = response.data.records;
          });
        }  else if (this.queryParams.rectifyStatus == 1){
          overList(obj).then(response => {
            this.total = response.data.total;
            this.tableList = response.data.records;
          });
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'dateRange',[]);
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          hazardType:2,
          rectifyStatus:"2",
          examineResult:"",
          searchValue:"",
          checkTimeOrder:"",
          zgTimeOrder:"",
          zgTermOrder:"",
          myRelated:1,
        });
        this.handleQuery();
      },
    },
  }
</script>

<style scoped lang="scss">
  .departmentListPage{
    flex: 1;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    .departmentListPage-page{
      flex: 1;
      display: flex !important;
      flex-direction: column;
      overflow: hidden;
      .page-form-title-box{
        .form-button-max-big-box{
          display: inline-block;
          overflow: hidden;
          .form-button-big-box{
            display: flex;
            p:nth-child(1){
              border-top-left-radius: 4px;
              border-bottom-left-radius: 4px;
              border-top:1px solid #E0E0E0;
              border-bottom:1px solid #E0E0E0;
            }
            p:nth-child(2){
              border-top:1px solid #E0E0E0;
              border-bottom:1px solid #E0E0E0;
            }
            p:nth-child(3){
              border-top-right-radius: 4px;
              border-bottom-right-radius: 4px;
              border-top:1px solid #E0E0E0;
              border-bottom:1px solid #E0E0E0;
              border-right:1px solid #E0E0E0;
            }
            p{
              height:40px;
              width:80px;
              line-height: 40px;
              text-align: center;
              color:#666666;
              font-size:14px;
              font-weight:500;
              cursor: pointer;
              border-left:1px solid #E0E0E0;
            }
            .checkDiv{
              color:#fff!important;
              border:1px solid #0183FA!important;
              background-color: #0183FA;
            }
          }
        }
        .form-button-max-big-box-me{
          display: inline-block;
          overflow: hidden;
          .form-button-big-box-me{
            display: flex;
            div{
              position: relative;
              height:40px;
              width:130px;
              line-height: 40px;
              text-align: center;
              color:#999;
              font-size:14px;
              border:1px solid #999;
              border-radius:4px;
              margin-left:10px;
              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;
            }
          }
        }
      }
      .page-content-box{
        .rectifyStatusColorA{
          color:#23B303;
        }
        .rectifyStatusColorB{
          color:#0183FA;
        }
        .rectifyStatusColorC{
          color:#EE0606;
        }
      }
    }
  }
</style>
