<!--巡查子项管理-->
<template>
  <div class="selfInspectionManagement">
    <div class="selfInspectionManagement-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>
          <el-form-item style="float: right">
            <p class="add-button-one-90" style="width:80px;" @click="outButton">返回</p>
          </el-form-item>
        </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" />
          <el-table-column label="计划标题" align="center" prop="title" show-overflow-tooltip width="250"/>
          <el-table-column label="实验室" align="center" prop="subjectName" show-overflow-tooltip width="220"/>
          <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="230">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p" v-if="scope.row.manageStatus==0||scope.row.manageStatus==2" @click="goAddPage(3,scope.row.id)">详情</p>
                <p class="table-button-p" v-if="scope.row.manageStatus==1" @click="goAddPage(2,scope.row.id)">编辑</p>
                <p class="table-button-p" v-if="scope.row.manageStatus==0" @click="goAddPage(2,scope.row.id)">开始检查</p>
                <p class="table-button-p" v-if="scope.row.manageStatus==2" @click="lookDocumentButton(1,scope.row)">整改报告</p>
                <p class="table-button-p" v-if="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>
    <lookDocumentDialog v-if="lookDocumentType" :propsLookDocumentData="propsLookDocumentData"></lookDocumentDialog>
    <lookDocumentListDialog v-if="lookDocumentListType" :propsLookDocumentListData="propsLookDocumentListData"></lookDocumentListDialog>
  </div>
</template>

<script>
  import { listDepartments } from "@/api/system/dept";
  import { findByCheckPlanId } from '@/api/safetyCheck/index'
  import addPage from '@/views/safetyCheck/components/addPage/addPage.vue'
  import infoPage from '@/views/safetyCheck/components/infoPage/infoPage.vue'
  import lookDocumentDialog from '@/components/lookDocumentDialog/lookDocumentDialog.vue'
  import lookDocumentListDialog from '@/components/lookDocumentDialog/lookDocumentListDialog.vue'
  export default {
    name: 'index',
    props:{
      propsListPageData:{},
    },
    components: {
      addPage,
      infoPage,
      lookDocumentDialog,
      lookDocumentListDialog
    },
    data(){
      return{
        //子组件数据
        lookDocumentType:false,
        propsLookDocumentData:{},
        lookDocumentListType:false,
        propsLookDocumentListData:{},
        propsAddData:{},
        propsInfoData:{},
        //学院列表
        deptSelectList:[],
        pageType:1,
        queryParams:{
          pageNum:1,
          pageSize:20,
          manageStatus:'-1',
          checkTimeSort:0,
          searchValue:"",
          deptId:""
        },
        dateRange:[],
        tableList:[],
        total:0,
      }
    },
    created(){

    },
    mounted(){
      this.listDepartments();
      this.getList();
    },
    methods:{
      //返回按钮
      outButton(){
        this.$parent.goPage(1);
      },
      //开始检查
      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();
        }
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        obj.checkPlanId = this.propsListPageData.id;
        if(this.dateRange[0]){
          obj.startTime = this.dateRange[0];
        }else{
          obj.startTime = "";
        }
        if(this.dateRange[1]){
          obj.endTime = this.dateRange[1];
        }else{
          obj.endTime = "";
        }
        findByCheckPlanId(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,
          manageStatus:'-1',
          checkTimeSort:0,
          searchValue:"",
          deptId:""
        });
        this.handleQuery();
      },
      //查看单个文档
      lookDocumentButton(type,row){
        if(type==1){
          this.$set(this,'propsLookDocumentData',{
            title:"整改报告",
            name:row.name,
            url:row.url
          });
          this.$set(this,'lookDocumentType',true);
        }else{
          this.$set(this,'lookDocumentType',false);
        }
      },
      //查看多个文档
      lookDocumentListButton(type,row){
        if(type==1){
          this.$set(this,'propsLookDocumentListData',{
            title:"查看附件",
            list:row.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">
  .selfInspectionManagement{
    flex: 1;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    .selfInspectionManagement-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;
        .manageStatus-color-1{
          color:#0183FA;
        }
        .manageStatus-color-2{
          color:#EE0606;
        }
        .manageStatus-color-3{
          color:#23B303;
        }
      }
    }
  }
</style>
