<!--巡查管理-->-
<template>
  <div class="app-container inspectionManagement">
    <div class="inspectionManagement-page" v-if="pageType == 1">
      <div class="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" style="margin-left:10px;">
              <div :class="queryParams.manageStatus=='-1'?'checkDiv':''" @click="topLeftClickType('-1')">
                <p class="text-p">全部</p>
                <p class="el-icon-check icon-p" v-if="queryParams.manageStatus=='-1'"></p>
              </div>
              <div :class="queryParams.manageStatus==0?'checkDiv':''" @click="topLeftClickType(0)">
                <p class="text-p">待检查</p>
                <p class="el-icon-check icon-p" v-if="queryParams.manageStatus==0"></p>
              </div>
              <div :class="queryParams.manageStatus==1?'checkDiv':''" @click="topLeftClickType(1)">
                <p class="text-p">检查中</p>
                <p class="el-icon-check icon-p" v-if="queryParams.manageStatus==1"></p>
              </div>
              <div :class="queryParams.manageStatus==2?'checkDiv':''" @click="topLeftClickType(2)">
                <p class="text-p">已检查</p>
                <p class="el-icon-check icon-p" v-if="queryParams.manageStatus==2"></p>
              </div>
            </div>
          </div>
          <el-form-item label="关键字" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="计划标题/实验室/房间号/检查者"
              clearable
              style="width: 250px"
            />
          </el-form-item>
          <el-form-item label="学院" prop="deptId" label-width="50px">
            <el-select v-model="queryParams.deptId" clearable placeholder="请选择学院" style="width: 150px">
              <el-option
                v-for="item in deptSelectList"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptId">
              </el-option>
            </el-select>
          </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="yyyy-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>
          <div class="form-button-max-big-box">
            <div class="form-button-big-box">
              <div :class="queryParams.isSelf==1?'checkDiv':''" style="width:100px;" @click="topRightClickType">
                <p class="text-p">本人发起</p>
                <p class="el-icon-check icon-p" v-if="queryParams.isSelf==1"></p>
              </div>
            </div>
          </div>
        </el-form>
      </div>
      <div class="content-box">
        <el-table  border :data="tableList" ref="multipleTable" @sort-change="sortChange">
          <el-table-column label="序号" align="center"  type="index" width="60" fixed/>
          <el-table-column label="计划标题" align="center" prop="title" show-overflow-tooltip width="250" fixed/>
          <el-table-column label="实验室" align="center" prop="subjectName" show-overflow-tooltip width="220" fixed>
            <template slot-scope="scope">{{scope.row.roomNumber?scope.row.subjectName+'-'+scope.row.roomNumber:scope.row.subjectName}}</template>
          </el-table-column>
          <el-table-column label="学院" align="center" prop="collegeName" show-overflow-tooltip width="150"/>
          <el-table-column label="检查状态" align="center" prop="manageStatus" show-overflow-tooltip width="90">
            <template slot-scope="scope">
              <p :class="scope.row.manageStatus==0?'manageStatus-color-1':(scope.row.manageStatus==1?'manageStatus-color-2':(scope.row.manageStatus==2?'manageStatus-color-3':''))">{{scope.row.manageStatus==0?'待检查':(scope.row.manageStatus==1?'检查中':(scope.row.manageStatus==2?'已检查':''))}}</p>
            </template>
          </el-table-column>
          <el-table-column label="检查者" align="center" prop="checkUser" show-overflow-tooltip width="100"/>
          <el-table-column label="检查结果" align="center" prop="checkResult" show-overflow-tooltip width="80">
            <template slot-scope="scope">
              <p>{{scope.row.checkResult==0?'不符合':(scope.row.checkResult==1?'符合':'')}}</p>
            </template>
          </el-table-column>
          <el-table-column label="隐患数" align="center" prop="dangerNum" show-overflow-tooltip width="80"/>
          <el-table-column label="整改进度" align="center" prop="rectifySchedule" show-overflow-tooltip width="200"/>
          <el-table-column label="计划周期" align="center" prop="startTime" show-overflow-tooltip width="270">
            <template slot-scope="scope">
              <p>{{scope.row.cycleStartTime}} 至 {{scope.row.cycleEndTime}}<span style="color:#EE0606;margin-left:15px;" v-if="scope.row.isOverdue==1">已逾期</span></p>
            </template>
          </el-table-column>
          <el-table-column label="检查时间" sortable="custom" align="center" prop="checkTime" show-overflow-tooltip width="157"/>
          <el-table-column label="操作" align="center" prop="deptName" width="280">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p" v-hasPermi="['safety:checkManage:query']"
                   v-show="scope.row.manageStatus==0||scope.row.manageStatus==2" @click="goAddPage(3,scope.row.id)">详情</p>
                <p class="table-button-p" v-hasPermiAnd="['safety:checkManage:query','safety:checkManage:edit']"
                   v-show="scope.row.manageStatus==1 && scope.row.isCheck==1 && scope.row.isSelfData==1" @click="goAddPage(2,scope.row.id)">编辑</p>
                <p class="table-button-p" v-hasPermiAnd="['safety:checkManage:query','safety:checkManage:edit']"
                   v-show="scope.row.manageStatus==0 && scope.row.isCheck==1 && scope.row.isSelfData==1" @click="goAddPage(2,scope.row.id)">开始检查</p>
                <p class="table-button-p" v-hasPermiAnd="['safety:checkManage:query','safety:checkManage:edit']"
                   style="color:#999" v-show="scope.row.manageStatus==0 && scope.row.isCheck==0 && scope.row.isSelfData==1">开始检查</p>
                <p class="table-button-p" v-show="scope.row.isEndProcess==1 && scope.row.checkResult==0" @click="lookDocumentButton(1,scope.row)">整改报告</p>
                <p class="table-button-p" v-show="scope.row.isAttachment == 1" @click="lookDocumentListButton(1,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>
    <addPage v-if="pageType==2" :propsAddData="propsAddData"></addPage>
    <infoPage v-if="pageType==3" :propsInfoData="propsInfoData"></infoPage>
    <lookDocumentDataDialog v-if="lookDocumentType" :propsLookDocumentData="propsLookDocumentData"></lookDocumentDataDialog>
    <lookDocumentListDialog v-if="lookDocumentListType" :propsLookDocumentListData="propsLookDocumentListData"></lookDocumentListDialog>
  </div>
</template>

<script>
  import { listDepartments } from "@/api/system/dept";
  import { checkManageList,getFindByCheckPlanId } from '@/api/safetyCheck/index'
  import addPage from '@/views/safetyCheck/components/addPage/addPage.vue'
  import infoPage from '@/views/safetyCheck/components/infoPage/infoPage.vue'
  import lookDocumentDataDialog from '@/components/lookDocumentDialog/lookDocumentDataDialog.vue'
  import lookDocumentListDialog from '@/components/lookDocumentDialog/lookDocumentListDialog.vue'
  export default {
    name: 'index',
    components: {
      addPage,
      infoPage,
      lookDocumentDataDialog,
      lookDocumentListDialog
    },
    data(){
      return{
        //子组件数据
        lookDocumentType:false,
        propsLookDocumentData:{},
        lookDocumentListType:false,
        propsLookDocumentListData:{},
        propsAddData:{},
        propsInfoData:{},
        //学院列表
        deptSelectList:[],
        pageType:1,
        queryParams:{
          pageNum:1,
          pageSize:20,
          checkType:1,
          manageStatus:'-1',
          checkTimeSort:0,
          searchValue:"",
          deptId:"",
          isSelf:0,
        },
        dateRange:[],
        tableList:[],
        total:0,
      }
    },
    created(){
      if(this.$route.query.id){
        this.goAddPage(2,this.$route.query.id);
      }
    },
    mounted(){
      this.listDepartments();
      this.getList();
    },
    methods:{
      //开始检查
      goAddPage(type,id){
        if(this.pageType != type){
          if(type == 1){
            //返回
            this.$set(this,'pageType',type);
          }else if(type == 2){
            //开始检查/编辑
            this.$set(this,'propsAddData',{
              id:id,
              title:'校院巡查',
            });
            this.$set(this,'pageType',type);
          }else if(type == 3){
            //详情
            this.$set(this,'propsInfoData',{id:id});
            this.$set(this,'pageType',type);
          }else if(type == 4){
            //返回并刷新
            this.getList();
            this.$set(this,'pageType',1);
          }
        }
      },
      //时间排序方法
      sortChange(val){
        if(val.prop == 'checkTime'){
          this.$set(this.queryParams,'checkTimeSort',val.order=='ascending'?'1':(val.order=='descending'?'2':"0"));
          this.handleQuery();
        }
      },
      //范围选择
      topLeftClickType(type){
        if(this.queryParams.manageStatus != type){
          this.$set(this.queryParams,'manageStatus',type);
          this.handleQuery();
        }
      },
      topRightClickType(){
        this.$set(this.queryParams,'isSelf',this.queryParams.isSelf==1?0:1);
        this.handleQuery();
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.startTime = this.dateRange[0];
        }else{
          obj.startTime = "";
        }
        if(this.dateRange[1]){
          obj.endTime = this.dateRange[1];
        }else{
          obj.endTime = "";
        }
        checkManageList(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,
          checkType:1,
          manageStatus:'-1',
          checkTimeSort:0,
          searchValue:"",
          deptId:"",
          isSelf:0,
        });
        this.handleQuery();
      },
      //查看单个文档
      lookDocumentButton(type,row){
        if(type==1){
          this.$set(this,'propsLookDocumentData',{
            title:"整改报告",
            type:1,
            id:row.id,
            name:row.title
          });
          this.$set(this,'lookDocumentType',true);
        }else{
          this.$set(this,'lookDocumentType',false);
        }
      },
      //查看多个文档
      lookDocumentListButton(type,row){
        if(type==1){
          getFindByCheckPlanId({checkPlanId:row.checkPlanId}).then(response => {
            let list = [];
            for(let i=0;i<response.data.length;i++){
              let obj = {
                name:response.data[i].fileName,
                url:response.data[i].fileUrl,
              }
              list.push(obj);
            }
            this.$set(this,'propsLookDocumentListData',{
              title:"查看附件",
              list:list
            });
            this.$set(this,'lookDocumentListType',true);
          });
        }else{
          this.$set(this,'lookDocumentListType',false);
        }
      },
      //获取学院列表
      listDepartments(){
        listDepartments().then(response => {
          this.deptSelectList = response.data;
        });
      },
    }
  }
</script>

<style scoped lang="scss">
  ::v-deep .el-table__fixed{
    margin-top:-1px;
    margin-left:-1px;
    height:100%!important;
  }
  ::v-deep .el-table__fixed-body-wrapper{
    height: calc(100% - 48px);
    overflow-y: auto;
    pointer-events: none;
    cursor: default;
  }
  .inspectionManagement{
    flex: 1;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    .inspectionManagement-page{
      flex: 1;
      display: flex !important;
      flex-direction: column;
      overflow: hidden;
      .title-box{
        padding-top:20px;
        border-bottom:1px solid #dedede;
        .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:20px;
        overflow: hidden;
      }
    }
  }
</style>
