<!--检查明细--->
<template>
  <div class="page-container checkItem">
    <div class="page-container checkItem" v-if="pageType == 1">
      <div class="page-top-title-box">
        <p class="page-top-title-name-p">{{propsData.title}}</p>
        <p class="page-top-title-out-p" @click="backPage">返回</p>
      </div>
      <div class="content-box scrollbar-box">
        <div class="page-form-title-box" style="border:none;">
          <el-form :model="queryParams" class="form-box" ref="queryForm"
                   :inline="true" style="width:100%;">
            <div class="table-school-college-toggle-box" v-if="!propsData.deptId&&!propsData.subId">
              <p :class="checkStatus==null?'p-check':''" @click="tableCheck(null)">全部</p>
              <p :class="checkStatus==0?'p-check':''" @click="tableCheck(0)">待检查</p>
              <p :class="checkStatus==1?'p-check':''" @click="tableCheck(1)">已检查</p>
            </div>
            <el-form-item label="" prop="hazardCheckName">
              <el-input
                maxLength="30"
                v-model="queryParams.hazardCheckName"
                placeholder="模糊搜索检查项"
                style="width: 140px"
              />
            </el-form-item>
            <el-form-item label="" prop="deptId" v-if="!propsData.deptId&&!propsData.subId">
              <el-select v-model="queryParams.deptId" placeholder="学院单位" style="width: 120px">
                <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="subName">
              <el-input
                maxLength="30"
                v-model="queryParams.subName"
                placeholder="实验室/房间号"
                style="width: 120px"
              />
            </el-form-item>
            <el-form-item label="" prop="checkUserName">
              <el-input
                maxLength="30"
                v-model="queryParams.checkUserName"
                placeholder="检查人/整改人"
                style="width: 120px"
              />
            </el-form-item>
            <el-form-item label="" prop="checkName">
              <el-input
                maxLength="30"
                v-model="queryParams.checkName"
                placeholder="检查名称"
                style="width: 150px"
              />
            </el-form-item>
            <el-form-item label="" prop="checkFlag">
              <el-select v-model="queryParams.checkFlag" placeholder="检查结果" style="width: 120px">
                <el-option
                  v-for="dict in optionList"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
            <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
            <el-form-item style="float: right;">
              <export-component :exportConfig="exportConfig"></export-component>
            </el-form-item>
          </el-form>
        </div>
        <div class="page-content-box" style="padding-top:0;">
          <el-table class="table-box" ref="table-box" v-loading="loading" border :data="dataList"
                    @selection-change="handleSelectionChange" :row-key="getRowKeys" @sort-change="sortChange">
            <el-table-column type="selection" width="50" :reserve-selection="true" align="center"/>
            <el-table-column label="序号" type="index" width="60"/>
            <el-table-column label="检查名称" prop="checkName"  width="200" show-overflow-tooltip/>
            <el-table-column label="实验室" prop="subName"  width="200" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{scope.row.subName}}{{scope.row.roomNum}}</span>
              </template>
            </el-table-column>
            <el-table-column label="检查项" prop="content" width="280" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{scope.row.hazardCheckCode}}{{scope.row.hazardCheckName}}</span>
              </template>
            </el-table-column>
            <el-table-column label="检查状态" prop="checkStatus" width="100" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{scope.row.checkStatus==0?'待检查':'已检查'}}</span>
              </template>
            </el-table-column>
            <el-table-column label="检查人" prop="checkUserName" width="80" show-overflow-tooltip/>
            <el-table-column label="检查结果" prop="checkFlag" width="100" show-overflow-tooltip>
              <template slot-scope="scope">
                <span v-if="scope.row.checkStatus!=0">{{scope.row.checkFlag?'符合':'不符合'}}</span>
              </template>
            </el-table-column>
            <el-table-column label="检查时间" sortable="custom" prop="checkTime" width="150" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.checkTime,"{y}-{m}-{d} {h}:{i}") }}</span>
              </template>
            </el-table-column>
            <el-table-column label="整改状态" prop="rectifyStatus" width="100" show-overflow-tooltip>
              <template slot-scope="scope">
                <span v-if="scope.row.checkStatus!=0&&!scope.row.checkFlag">{{scope.row.rectifyStatus==1?'已完成':(scope.row.rectifyStatus==2?'待整改':(scope.row.rectifyStatus==4?'暂无法整改':''))}}</span>
              </template>
            </el-table-column>
            <el-table-column label="整改人" prop="rectifyName" width="90" show-overflow-tooltip/>
            <el-table-column label="整改时间" sortable="custom" prop="rectifyTime" width="150" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.rectifyTime,"{y}-{m}-{d} {h}:{i}") }}</span>
              </template>
            </el-table-column>
            <el-table-column label="复查状态" prop="reviewStatus" width="80" show-overflow-tooltip>
              <template slot-scope="scope">
                <span v-if="scope.row.checkStatus!=0&&!scope.row.checkFlag&&scope.row.rectifyStatus!=2">{{scope.row.reviewStatus==1?'已复查':(scope.row.reviewStatus==0?'待复查':'')}}</span>
              </template>
            </el-table-column>
            <el-table-column label="复查人" prop="reviewName" width="80" show-overflow-tooltip/>
            <el-table-column label="复查结果" prop="examineResult" width="100" 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="操作" width="100" show-overflow-tooltip >
              <template slot-scope="scope">
                <div class="table-button-box">
                  <p class="table-button-null"></p>
                  <p class="table-button-p"
                     @click="tableButton(2,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>
    </div>
    <initiateInspect v-if="pageType == 2" :initiateInspectData="initiateInspectData"></initiateInspect>
  </div>
</template>

<script>
  import {
    getDeptDropList,
  } from '@/api/commonality/permission'
import {
    securityCheckDetailsCheckList
  } from "@/api/safetyCheck/index";
import initiateInspect from "@/views/safetyCheck/components/initiateInspect/initiateInspect.vue";
  import exportComponent from "@/views/safetyCheck/components/exportComponent/exportComponent.vue";
export default {
  name: 'checkItem',
  components: {
    initiateInspect,
    exportComponent,
  },
  props:{
    propsData:{},
  },
  data(){
    return{
      //导出配置
      exportConfig:{
        api:'/security/checkDetails/export  ',             //导出接口地址
        ids:'',                                       //勾选导出,勾选的IDS
        fileName:'检查明细信息',                         //导出文件的命名
        screenData:{},
      },
      //页面状态
      pageType:1,
      //状态选项卡
      checkStatus:null,
      //页面遮罩
      loading:false,
      //下拉列表数据
      deptOption:[],
      optionList:[{value:1,label:'符合'},{value:0,label:'不符合'}],
      //查询条件
      queryParams:{
        page:1,
        pageSize:20,
        hazardCheckName:"",
        deptId :null,
        subName :"",
        checkUserName :"",
        checkName :"",
        checkFlag :null,
        columnName :"",
        sort :"",
      },
      //列表数据
      dataList:[],
      //数据数量
      total:0,
      //子组件数据
      initiateInspectData:{},
    }
  },
  created(){
    if(this.propsData.deptId||this.propsData.subId){
      this.$set(this,'checkStatus',1);
    }
    this.getDeptDropList();
  },
  mounted(){
    this.getList();
  },
  methods:{
    //选项卡切换
    tableCheck(type){
      if (this.checkStatus !== type){
        this.$set(this,'checkStatus',type);
        this.resetQuery();
      }
    },
    // 返回按钮
    backPage(){
      this.$parent.tableButton(6);
    },
    //查询按钮
    handleQuery(){
      this.$set(this.queryParams,'page',1);
      this.getList();
    },
    //重置按钮
    resetQuery(){
      this.$refs['table-box'].clearSelection();
      this.$set(this.exportConfig,'ids','');
      this.$set(this,'queryParams',{
        page:1,
        pageSize:20,
        hazardCheckName:"",
        deptId :null,
        subName :"",
        checkUserName :"",
        checkName :"",
        checkFlag :null,
        columnName :"",
        sort :"",
      });
      this.getList();
    },
    getRowKeys(row) {
      return row.setOptionId
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.$set(this.exportConfig,'ids',selection.map(item => item.setOptionId));
    },
    //时间排序方法
    sortChange(val){
      this.$set(this.queryParams,'columnName',val.prop);
      this.$set(this.queryParams,'sort',val.order=='ascending'?'asc':(val.order=='descending'?'desc':''));
      this.handleQuery();
    },
    //获取数据列表
    getList(){
      this.$set(this,'loading',true);
      let obj = JSON.parse(JSON.stringify(this.queryParams))
      if(this.propsData.planId){
        obj.planId = this.propsData.planId
        this.$set(this.exportConfig,'customKey','planId');
        this.$set(this.exportConfig,'customValue',obj.planId);
      }else if(this.propsData.deptId){
        obj.deptId = this.propsData.deptId
        obj.planId = this.propsData.deptPlanId
        this.$set(this.exportConfig,'customKey','deptId');
        this.$set(this.exportConfig,'customValue',obj.deptId);
      }else if(this.propsData.subId){
        obj.subId = this.propsData.subId
        obj.planId = this.propsData.subPlanId
        this.$set(this.exportConfig,'customKey','subId');
        this.$set(this.exportConfig,'customValue',obj.subId);
      }
      obj.checkStatus = this.checkStatus
      this.$set(this.exportConfig,'screenData',obj);
      securityCheckDetailsCheckList(obj).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 == 2){
        //详情
        this.$set(this,'pageType',2);
        let obj = JSON.parse(JSON.stringify(row))
        obj.planId = this.propsData.planId;
        obj.showType = true;
        obj.orderTitle = '检查详情';
        obj.orderType = '2';
        this.$set(this,'initiateInspectData',obj);
      }else if(type == 6){
        //返回并刷新
        this.$set(this,'pageType',1);
        this.getList();
      }
    },
    //学院列表
    getDeptDropList() {
      getDeptDropList({ deptName: '', level: 2, deptType: 1 }).then(response => {
        this.$set(this, 'deptOption', response.data)
      })
    },
  },
}
</script>

<style scoped lang="scss">
.checkItem{
  .content-box{
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    .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;
        }
      }
    }
  }
}
.num-data-box{
  background: rgba(1,131,250,0.2);
  color:#0183FA;
  font-size:14px;
  line-height:40px;
  padding:0 20px;
  border-radius:4px;
  margin:0px 20px 20px 20px;
  width: 330px;
}
</style>
