<!--批量审核-->
<template>
  <div class="batchAudit">
    <div class="batchAudit-page">
      <div class="title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm" :inline="true" label-width="80px">
          <el-form-item label="关键字" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="计划标题/实验室/房间号"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="整改时间" prop="dateRange" style="margin-left:10px;" label-width="70px">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="examineOpinion-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <p class="inquire-button-one" @click="handleQuery" style="margin-right:10px;">查询</p>
            <p class="reset-button-one" @click="resetQuery">重置</p>
          </el-form-item>
        </el-form>
      </div>
      <div class="content-box">
        <el-table  border :data="tableList" ref="multipleTable" @sort-change="sortChange"
                   @selection-change="tableChange" :row-key="getRowKeys">
          <el-table-column type="selection" width="50" :reserve-selection="true" align="center"/>
          <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="检查时间" 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="130"/>
          <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?'rectifyStatusColorB':(scope.row.rectifyStatus==3?'rectifyStatusColorC':''))">{{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="220">
            <template slot-scope="scope">
              <p>{{scope.row.rectifyTime}}<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="examineResult" show-overflow-tooltip width="80"/>
          <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" @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.pageNum"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
      <div class="dialog-footer-box">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-info" @click="outButton">返回</p>
        <p class="dialog-footer-button-primary" @click="openDialogPage(1)">确认</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </div>
    <infoDialog v-if="infoDialogType" :propsInfoDialogData="propsInfoDialogData"></infoDialog>
    <el-dialog class="inspectionPlan-dialog-box"
               title="批量审核" :visible.sync="dialogType" v-if="dialogType"
               @close="openDialogPage(2)" width="1303px" append-to-body>

      <el-table border :data="dialogTableList">
        <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="rectifyName" show-overflow-tooltip width="90"/>
        <el-table-column label="操作" align="center" prop="examineResult" width="140">
          <template slot-scope="scope">
            <el-select v-model="scope.row.examineResult" placeholder="请选择">
              <el-option
                v-for="item in dialogOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="审核意见" align="center" prop="examineOpinion" width="400">
          <template slot-scope="scope">
            <el-input v-model="scope.row.examineOpinion" placeholder="请输入审核意见" maxLength="100"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer dialog-footer-box" style="display: flex">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-info" @click="openDialogPage(2)">返回</p>
        <p class="dialog-footer-button-primary" @click="dialogButton">批量审核</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { checkHazardList,batchApprove } from '@/api/safetyCheck/index'
  import infoDialog from '@/views/safetyCheck/components/infoDialog/infoDialog.vue'
  export default {
    name: 'batchAudit',
    props:{
      propsBatchAuditData:{},
    },
    components: {
      infoDialog
    },
    data(){
      return{
        //组件传参
        propsInfoDialogData:{},
        infoDialogType:false,
        queryParams:{
          pageNum:1,
          pageSize:20,
          rectifyStatus:3,
          searchValue:"",
        },
        dateRange:[],
        tableList:[],
        total:0,
        tableNum:0,
        tableIds:[],
        //审批弹窗数据
        dialogType:false,
        dialogTableList:[],
        dialogOptions:[
          {value:"0",label:"驳回"},
          {value:"1",label:"通过"},
        ],
      }
    },
    created(){

    },
    mounted(){
      this.getList();
    },
    methods:{
      //批量审核
      dialogButton(){
        let self = this;
        let list = [];
        for(let i=0;i<self.dialogTableList.length;i++){
          if(!self.dialogTableList[i].examineResult){
            this.msgError('第'+(i+1)+'条数据,未选择审核结果')
            return
          }
          if(!self.dialogTableList[i].examineOpinion){
            this.msgError('第'+(i+1)+'条数据,未输入审核意见')
            return
          }
          let obj = {
            id:self.dialogTableList[i].rectifyId,
            checkHazardId:self.dialogTableList[i].id,
            examineResult:self.dialogTableList[i].examineResult,
            examineOpinion:self.dialogTableList[i].examineOpinion,

          };
          list.push(obj);
        }
        batchApprove(list).then(response => {
          this.msgSuccess(response.msg)
          this.$parent.goPage(3);
        });
      },
      //批量审核弹窗
      openDialogPage(type){
        if(type == 1){
          if(!this.$refs.multipleTable.selection[0]){
            this.msgError('请勾选需要审批的数据')
            return
          }
          let list = JSON.parse(JSON.stringify(this.$refs.multipleTable.selection));
          for(let i=0;i<list.length;i++){
            list[i].examineResult = '';
            list[i].examineOpinion = '';
          }
          this.$set(this,'dialogTableList',list);
          this.$set(this,'dialogType',true);
        }else{
          this.$set(this,'dialogType',false);
        }
      },
      //开关详情页面
      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);
          }
        }
      },
      //返回
      outButton(){
        this.$parent.goPage(1);
      },
      //时间排序方法
      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.getList();
        }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.getList();
        }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.getList();
        }
      },
      //获取数据列表
      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 = "";
        }
        obj.hazardType = this.propsBatchAuditData.hazardType
        checkHazardList(obj).then(response => {
          this.total = response.data.total;
          this.tableList = response.data.records;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.$set(this.queryParams,'pageNum',1);
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'dateRange',[]);
        this.$set(this,'queryParams',{
          pageNum:1,
          pageSize:20,
          rectifyStatus:3,
          searchValue:"",
        });
        this.handleQuery();
      },
      /*===记录勾选数据===
        需要再el-table 添加  :row-key="getRowKeys"
        需要在selection 添加 :reserve-selection="true"
      */
      getRowKeys(row) {
        return row.id
      },
      tableChange(selection){
        this.tableNum = selection.length;
        this.tableIds = selection.map(item => item.userId);
      },
    }
  }
</script>

<style scoped lang="scss">
  .batchAudit{
    flex: 1;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    .batchAudit-page{
      flex: 1;
      display: flex !important;
      flex-direction: column;
      overflow: hidden;
      .title-box{
        padding-top:20px;
        .form-button-max-big-box{
          display: inline-block;
          .form-button-big-box{
            display: flex;
            div{
              position: relative;
              height:40px;
              width:80px;
              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{
                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{
              color:#0183FA;
              border:1px solid #0183FA;
            }
          }
        }
      }
      .content-box{
        flex: 1;
        display: flex;
        flex-direction: column;
        padding:0 20px 20px;
        overflow: hidden;
        .rectifyStatusColorA{
          color:#23B303;
        }
        .rectifyStatusColorB{
          color:#0183FA;
        }
        .rectifyStatusColorC{
          color:#EE0606;
        }
      }
      .dialog-footer-box{
        padding:20px 0;
        height:70px;
        border-top:1px solid #D8D8D8;
        display: flex;
      }
    }
  }
</style>
