<!-- 自查管理 -->
<template>
  <div class="app-container selfInspectionManage">
    <div class="page-container selfInspectionManagePage" v-if="pageType === 1">
      <!--左侧计划栏-->
      <div class="page-content-left-box">
        <!--计划栏搜索框-->
        <div>
          <el-form :model="leftQueryParams" class="form-box" ref="leftQueryForm"
                   :inline="true" style="width:100%;">
            <el-form-item label="" prop="searchValue">
              <el-input
                maxLength="30"
                v-model="leftQueryParams.searchValue"
                placeholder="计划标题"
                clearable
                @clear="leftClear"
                style="width: 365px"
              />
            </el-form-item>
            <p class="page-save-common-style-button" style="width:80px;display: inline-block" @click="leftHandleQuery">查询</p>
          </el-form>
        </div>
        <!--计划栏列表-->
        <div class="left-max-list-box scrollbar-box">
          <div class="left-list-for-max-big-box" v-for="(bigItem,bigIndex) in leftListData" :key="bigIndex">
            <div class="left-list-title-box" @click="leftBigCheckButton(bigIndex)">
              <p :class="bigIndex == leftBigCheckType?'el-icon-caret-bottom':'el-icon-caret-right'"></p>
              <p>{{bigItem.planTitle}}</p>
              <p>{{bigItem.checkTypeName}}</p>
            </div>
            <div class="left-list-box">
              <div class="left-list-for-box" v-if="bigIndex == leftBigCheckType"
                   @click="leftCheckButton(index,bigIndex)"
                   :class="index == leftCheckType ? 'check-left-list-for-box':''"
                   v-for="(item,index) in bigItem.checkPlanSetVoList" :key="index">
                <div class="left-list-text-box">
                  <p>{{item.checkName}}</p>
                  <p>检查开始时间：{{parseTime(item.checkStartTime,"{y}-{m}-{d}")}}</p>
                </div>
                <div class="left-list-progress-box">
                  <el-progress :stroke-width="14" :percentage="item.checkSetProgress"></el-progress>
                </div>
              </div>
            </div>
          </div>
          <p v-if="!leftListData[0]" class="left-list-for-null-p">暂无数据</p>
        </div>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="titleTotal>0"
                    :total="titleTotal"
                    :page.sync="leftQueryParams.page"
                    :limit.sync="leftQueryParams.pageSize"
                    @pagination="getTitleList"
        />
      </div>
      <div class="page-content-center-box"></div>
      <!--右侧数据表格-->
      <div class="page-content-right-box">
        <div class="page-form-title-box" style="border:none;" :class="advancedType?'page-advanced-form-title-box':''">
          <el-form :model="queryParams" class="form-box" ref="queryForm"
                   :inline="true" style="width:100%;">
            <div class="table-school-college-toggle-box">
              <p :class="tableButtonCheckType===''?'p-check':''" @click="tableCheck('')">全部</p>
              <p :class="tableButtonCheckType===0?'p-check':''" @click="tableCheck(0)">未完成</p>
              <!--<p :class="tableButtonCheckType===1?'p-check':''" @click="tableCheck(1)">检查中</p>-->
              <p :class="tableButtonCheckType===2?'p-check':''" @click="tableCheck(2)">已完成</p>
            </div>
            <el-form-item label="" prop="deptId">
              <el-select v-model="queryParams.deptId" placeholder="学院单位" style="width:157px;">
                <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="floorId">
              <!--<el-select v-model="queryParams.floorId" placeholder="楼栋" style="width:150px;">-->
                <!--<el-option-->
                  <!--v-for="dict in buildOption"-->
                  <!--:key="dict.id"-->
                  <!--:label="dict.name"-->
                  <!--:value="dict.id"-->
                <!--/>-->
              <!--</el-select>-->

              <el-cascader
                style="width: 150px"
                placeholder="楼栋"
                v-model="queryParams.floorId"
                filterable
                :show-all-levels="false"
                :options="buildOption"
                :props="{ value: 'id', label: 'name',emitPath:false }"
              ></el-cascader>
            </el-form-item>
            <el-form-item label="" prop="typeId" v-if="advancedType">
              <el-select v-model="queryParams.typeId" placeholder="安全分类" style="width:175px;">
                <el-option
                  v-for="dict in classOption"
                  :key="dict.typeId"
                  :label="dict.typeName"
                  :value="dict.typeId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="levelId" v-if="advancedType">
              <el-select v-model="queryParams.levelId" placeholder="安全分级" style="width:175px;">
                <el-option
                  v-for="dict in levelOption"
                  :key="dict.levelId"
                  :label="dict.levelName"
                  :value="dict.levelId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="searchValue" v-if="advancedType">
              <el-input
                maxLength="30"
                v-model="queryParams.searchValue"
                placeholder="实验室/房间号"
                style="width:170px;"
              />
            </el-form-item>
            <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
            <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
            <p class="page-save-common-style-button" style="display: inline-block;margin-left:10px;" @click="searchToggle">{{advancedType?'普通搜索':'高级搜索'}}</p>
            <p class="page-save-common-style-button" style="display: inline-block;margin-left:10px;"
               @click="tableButton(3)"
               v-if="memberRole != 3"
               v-hasPermiRouter="['security:checkSetOption_1:batch']"
            >检查完成</p>
          </el-form>
        </div>
        <div class="page-conten-box page-content-right-bottom-box">
          <el-table class="table-box" ref="table-box"  border :data="dataList" :row-key="getRowKeys"
                    @select-all="handleSelectionChange" @select="handleSelectionChange">
            <el-table-column type="selection" width="50" :reserve-selection="true" :selectable="selectable" align="center"/>
            <el-table-column label="序号" type="index" width="60"/>
            <el-table-column label="实验室" prop="subName"  show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{scope.row.subName}}{{scope.row.roomNum?'('+scope.row.roomNum+')':''}}</span>
              </template>
            </el-table-column>
            <el-table-column label="完成状态" prop="manageStatus" width="150" show-overflow-tooltip>
              <template slot-scope="scope">
                <!--<span :class="scope.row.manageStatus==0?'colorA':(scope.row.manageStatus==1?'colorB':(scope.row.manageStatus==2?'colorC':''))">-->
                  <!--{{scope.row.manageStatus==0?'待检查':(scope.row.manageStatus==1?'检查中':(scope.row.manageStatus==2?'已检查':''))}}-->
                <!--</span>-->
                <span :class="scope.row.manageStatus==0?'colorA':(scope.row.manageStatus==1?'colorA':(scope.row.manageStatus==2?'colorC':''))">
                  {{scope.row.manageStatus==0?'未完成':(scope.row.manageStatus==1?'未完成':(scope.row.manageStatus==2?'已完成':''))}}
                </span>
              </template>
            </el-table-column>
            <el-table-column label="检查人" prop="checkUserNames" width="230" show-overflow-tooltip/>
            <el-table-column label="操作" width="240" show-overflow-tooltip v-if="tableButtonType">
              <template slot-scope="scope">
                <div class="table-button-box">
                  <p class="table-button-null"></p>
                  <p class="table-button-p"
                     @click="tableButton(1,scope.row)"
                     v-hasPermiRouter="['security:checkSetOption_1:list']"
                  >检查项</p>
                  <p class="table-button-p"
                     v-if='scope.row.manageStatus !=2'
                     @click="tableButton(2,scope.row)"
                     v-hasPermiRouter="['security:checkPlan_1:detail']"
                  >开展检查</p>
                  <p class="table-button-null"></p>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <pagination :page-sizes="[40, 80]"
                      v-show="total>0"
                      :total="total"
                      :page.sync="queryParams.page"
                      :limit.sync="queryParams.pageSize"
                      @pagination="getList"
          />
        </div>
      </div>
    </div>
    <checkItem :propsData="propsData" v-if="pageType === 2"></checkItem>
    <initiateInspect v-if="pageType == 3" :initiateInspectData="initiateInspectData"></initiateInspect>
  </div>
</template>
<script>
  import {
    getDeptDropList,
    systemBuildingGetOptList,
    laboratoryClassLevelGetList,
    laboratoryClassTypeGetList,
  } from '@/api/commonality/permission'
  import {
    securityCheckPlanTitleList,
    securityCheckManageList,
    securityCheckSetOptionFinishCheckBatch,
  } from '@/api/safetyCheck/index'
  import checkItem from "@/views/safetyCheck/components/checkItem.vue";
  import initiateInspect from "@/views/safetyCheck/components/initiateInspect/initiateInspect.vue";
  export default {
    name: 'index',
    components: {
      checkItem,
      initiateInspect,
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['security:checkSetOption_1:list','security:checkPlan_1:detail','security:checkSetOption_1:batch',]),
        //页面状态
        pageType:1,
        //复查状态选项卡
        tableButtonCheckType:'',
        //页面遮罩
        loading:false,
        //学院
        deptOption:[],
        //楼栋
        buildOption:[],
        //分级
        levelOption:[],
        //分类
        classOption:[],
        //计划查询条件
        leftQueryParams:{
          checkCategory:2,
          searchValue:'',
          page:1,
          pageSize:20,
        },
        titleTotal:0,
        //查询条件
        queryParams:{
          page:1,
          pageSize:40,
          myRelated:1,
          deptId:null,
          floorId:null,
          typeId :null,
          levelId :null,
          searchValue:'',
        },
        //时间数据
        dateRange:[],
        //搜索模式切换
        advancedType:false,
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
        leftBigCheckType:"0",
        leftCheckType:"0",
        leftListData:[],
        checkSetProgress:0,
        //检查组件
        initiateInspectData:{},
        //选中数据
        checkList:[],
        //批量完成展示状态
        memberRole:3,
      }
    },
    created () {

    },
    mounted () {
      this.getTitleList();
      this.getDeptDropList();
      this.systemBuildingGetOptList();
      this.laboratoryClassLevelGetList();
      this.laboratoryClassTypeGetList();
    },
    methods: {
      //左侧清除查询按钮
      leftClear(){
        this.$set(this.leftQueryParams,'searchValue','');
        this.getTitleList();
      },
      //左侧查询按钮
      leftHandleQuery(){
        this.getTitleList();
      },
      //左侧计划切换
      leftBigCheckButton(index){
        if(this.leftBigCheckType !== index){
          this.$set(this,'leftBigCheckType',index);
          this.$set(this,'leftCheckType',0);
          this.$set(this,'checkSetProgress',this.leftListData[index].checkPlanSetVoList[0].checkSetProgress);
          this.$set(this,'memberRole',this.leftListData[index].memberRole);
          this.resetQuery();
        }
      },
      //左侧计划子级切换
      leftCheckButton(index,bigIndex){
        if(this.leftCheckType !== index){
          this.$set(this,'leftCheckType',index);
          this.$set(this,'checkSetProgress',this.leftListData[bigIndex].checkPlanSetVoList[index].checkSetProgress);
          this.$set(this,'memberRole',this.leftListData[bigIndex].memberRole);
          this.resetQuery();
        }
      },
      //复查状态选项卡切换
      tableCheck(type){
        if (this.tableButtonCheckType !== type){
          this.$set(this,'tableButtonCheckType',type);
          this.resetQuery();
        }
      },
      //搜索模式切换
      searchToggle(){
        this.$set(this,'advancedType',!this.advancedType);
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:40,
          deptId:null,
          floorId:null,
          typeId :null,
          levelId :null,
          searchValue:'',
        });
        this.getList();
      },
      //获取计划数据列表
      getTitleList(){
        securityCheckPlanTitleList(this.leftQueryParams).then(response => {
          this.$set(this,'leftListData',response.data.records);
          this.$set(this,'titleTotal',response.data.total);
          this.$set(this,'leftBigCheckType',0);
          this.$set(this,'leftCheckType',0);
          this.resetQuery();
          if(response.data.records[0]){
            this.$set(this,'checkSetProgress',this.leftListData[0].checkPlanSetVoList[0].checkSetProgress);
            this.$set(this,'memberRole',this.leftListData[0].memberRole);
          }
        });
      },
      getTitleListTwo(){
        securityCheckPlanTitleList(this.leftQueryParams).then(response => {
          this.$set(this,'leftListData',response.data.records);
          this.$set(this,'titleTotal',response.data.total);
          this.getList();
        });
      },
      //获取数据列表
      getList(){
        if(!this.leftListData[0]){
          this.$set(this,'dataList',[]);
          this.$set(this,'total',0);
          return
        }
        this.$set(this,'loading',true);
        let obj = {
          planSetId:this.leftListData[this.leftBigCheckType].checkPlanSetVoList[this.leftCheckType].planSetId,
          page:this.queryParams.page,
          pageSize:this.queryParams.pageSize,
          manageStatus:this.tableButtonCheckType,
          deptId:this.queryParams.deptId,
          floorId:this.queryParams.floorId,
        }
        if(this.advancedType){
          obj.searchValue = this.queryParams.searchValue;
          obj.typeId = this.queryParams.typeId;
          obj.levelId = this.queryParams.levelId;
        }
        securityCheckManageList(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 == 1){
          //检查项列表
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          obj.showType = true;
          obj.pageType = 2;
          obj.checkSetProgress = this.checkSetProgress;
          this.$set(this,'propsData',obj);
        }else if(type == 2){
          //开始检查
          this.$set(this,'pageType',3);
          let obj = JSON.parse(JSON.stringify(row))
          obj.freeChoiceType = true;
          obj.showType = false;
          obj.orderTitle = '开始检查';
          obj.orderType = '1';
          this.$set(this,'initiateInspectData',obj);
        }else if(type == 3){
          //批量完成
          if (!this.checkList[0]){
            this.msgError('请勾选数据')
            return
          }
          this.$confirm(`是否确认检查完成?`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(async () => {
            securityCheckSetOptionFinishCheckBatch({manageIds:this.checkList }).then(response => {
              this.$set(this,'checkList',[]);
              this.$refs['table-box'].clearSelection();
              self.msgSuccess(response.message)
              self.getTitleList();
            });
          }).catch(() => {

          })
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getTitleListTwo();
        }
      },
      /*********************************** 学院/楼栋/分类/分级 ***********************************/
      //学院下拉列表
      getDeptDropList(){
        getDeptDropList({level: 2, deptType: 1 }).then(response => {
          this.$set(this,'deptOption',response.data);
        });
      },
      //楼栋下拉列表
      systemBuildingGetOptList(){
        systemBuildingGetOptList({}).then(response => {
          let list = this.handleTree(response.data);
          pushNode(list)
          function pushNode(list){
            for(let i=0;i<list.length;i++){
              if(!list[i].children && list[i].type!= 3){
                list.splice(i,1)
                i--
              }if(list[i].children){
                pushNode(list[i].children)
              }
            }
          }
          this.$set(this,'buildOption',list);
        });
      },
      //分级下拉列表
      laboratoryClassLevelGetList(){
        laboratoryClassLevelGetList({}).then(response => {
          this.$set(this,'levelOption',response.data);
        });
      },
      //分类下拉列表
      laboratoryClassTypeGetList(){
        laboratoryClassTypeGetList({}).then(response => {
          this.$set(this,'classOption',response.data);
        });
      },
      /*===记录勾选数据===
        需要再el-table 添加  :row-key="getRowKeys"
        需要在selection 添加 :reserve-selection="true"
      */
      getRowKeys(row) {
        return row.manageId
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.$set(this,'checkList',selection.map(item => item.manageId));
      },
      //处理数据是否可以勾选
      selectable(row){
        return row.manageStatus != 2;
      },
    },
  }
</script>
<style scoped lang="scss">
  .selfInspectionManage{
    .selfInspectionManagePage{
      overflow: hidden;
      display: flex;
      flex-direction: row;
      flex:1;

      .page-content-left-box{
        width: 480px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        margin:20px 0 20px 20px;
        padding-right:10px;
        .left-max-list-box{
          flex:1;
          padding-right:10px;
          .left-list-for-max-big-box{
            .left-list-title-box{
              cursor: pointer;
              display: flex;
              p{
                height:30px;
                line-height:30px;
                margin:15px 0;
              }
              p:nth-child(1){
                font-size:16px;
                width:30px;
              }
              p:nth-child(2){
                font-size:16px;
                flex:1;
                /*单行省略号*/
                display:block;
                overflow:hidden;
                text-overflow:ellipsis;
                white-space:nowrap;
              }
              p:nth-child(3){
                font-size:14px;
                width:80px;
                height:30px;
                text-align: center;
                color:#fff;
                background-color: #0183FA;
                border-radius:4px;
              }
            }
            .left-list-box{
              .left-list-for-box{
                cursor: pointer;
                display: flex;
                height:70px;
                background-color: #F5F5F5;
                padding:5px 23px;
                .left-list-text-box{
                  width:240px;
                  p{
                    height:30px;
                    line-height: 30px;
                    font-size:16px;
                    /*单行省略号*/
                    display:block;
                    overflow:hidden;
                    text-overflow:ellipsis;
                    white-space:nowrap;
                  }
                  p:nth-child(2){
                    color:#666666;
                  }
                }
                .left-list-progress-box{
                  flex:1;
                  padding-top:15px;
                  ::v-deep .el-progress-bar{
                    margin-right: -62px;
                  }
                }
              }
              .check-left-list-for-box{
                background: rgba(1,131,250,0.1);
              }
            }
          }
          .left-list-for-null-p{
            text-align: center;
            line-height:400px;
            color:#999;
          }
        }
      }
      .page-content-center-box{
        margin:20px 0;
        border-right:1px dashed #dedede;
      }
      .page-content-right-box{
        display: flex;
        flex-direction: column;
        overflow: hidden;
        flex:1;
        .page-content-right-bottom-box{
          display: flex;
          flex-direction: column;
          overflow: hidden;
          flex:1;
          padding:0 20px 20px;
          .colorA{
            color:#FA4A04;
          }
          .colorB{
            color:#0484FA;
          }
          .colorC{
            color:#039C06;
          }
        }
      }
      .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(3){
          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;
          }
        }
      }
    }
  }
</style>
