<!-- 校级隐患清单 -->
<template>
  <div class="app-container schoolHiddenDangerList">
    <div class="page-container schoolHiddenDangerListPage" 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="time">
              <el-date-picker
                v-model="leftQueryParams.time"
                type="year"
                style="width: 100px"
                value-format="yyyy"
                placeholder="年">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="" prop="searchValue">
              <el-input
                maxLength="30"
                v-model="leftQueryParams.searchValue"
                placeholder="输入检计划名称快速检索"
                clearable
                @clear="leftClear"
                style="width: 265px"
              />
            </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;">
          <el-form :model="queryParams" class="form-box" ref="queryForm"
                   :inline="true" style="width:100%;">
            <el-form-item label="" prop="deptId">
              <el-select v-model="queryParams.deptId" placeholder="选择二级学院单位" style="width:180px;">
                <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="leaderSubmitStatus" v-if="!isSchoolAdmin">
              <el-select v-model="queryParams.leaderSubmitStatus" placeholder="状态" style="width:175px;">
                <el-option
                  v-for="dict in typeOption"
                  :key="dict.key"
                  :label="dict.value"
                  :value="dict.key"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="adminSubmitStatus" v-if="isSchoolAdmin">
              <el-select v-model="queryParams.adminSubmitStatus" placeholder="状态" style="width:175px;">
                <el-option
                  v-for="dict in typeOption"
                  :key="dict.key"
                  :label="dict.value"
                  :value="dict.key"
                />
              </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>
            <p class="page-save-common-style-button"
               style="float: right;"
               @click="allTableButton(2)"
            >{{isSchoolAdmin?'批量审批':'批量提交'}}</p>
            <!--<p class="page-submit-common-style-button"-->
               <!--style="float: right;margin-right:20px;"-->
               <!--@click="allTableButton(1)"-->
            <!--&gt;批量下载</p>-->
          </el-form>
        </div>
        <div class="page-conten-box page-content-right-bottom-box">
          <el-table class="table-box" ref="multipleTable" border :data="dataList" :row-key="getRowKeys"
                    @select-all="handleSelectionChange" @select="handleSelectionChange">
            <el-table-column type="selection" width="50" align="center" :selectable="checkSelectable"/>
            <el-table-column label="隐患清单编号" prop="hiddenNum" show-overflow-tooltip/>
            <el-table-column label="学院单位" prop="deptName" width="160" show-overflow-tooltip/>
            <el-table-column label="隐患数量" prop="hiddenCount" width="120" show-overflow-tooltip/>
            <el-table-column label="状态"  width="120" show-overflow-tooltip>
              <template slot-scope="scope">
                <div v-if="scope.row.flowStatus == 0">
                  <span style="width:10px;height:10px;border-radius:50%;display: inline-block;margin:0 10px;" :style="scope.row.leaderSubmitStatus == 0?'background-color:#D8D8D8;':'background-color:#13CD3F;'"></span>
                  {{scope.row.leaderSubmitStatus == 0?'待提交':'已提交'}}
                </div>
                <div v-if="scope.row.flowStatus == 1">
                  <span style="width:10px;height:10px;border-radius:50%;display: inline-block;margin:0 10px;" :style="scope.row.adminSubmitStatus == 0?'background-color:#D8D8D8;':'background-color:#13CD3F;'"></span>
                  {{scope.row.adminSubmitStatus == 0?'待审批':'已审批'}}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="更新时间" prop="updateTime" width="160" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.updateTime,"{y}-{m}-{d} {h}:{i}") }}</span>
              </template>
            </el-table-column>
            <el-table-column label="更新人" prop="updateName" width="120" show-overflow-tooltip/>
            <el-table-column label="操作" width="180" 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-p"-->
                     <!--v-if="(scope.row.leaderSubmitStatus == 0 && scope.row.flowStatus == 0 && isLeader)||(scope.row.adminSubmitStatus == 0 && scope.row.flowStatus == 1 && isSchoolAdmin)"-->
                     <!--@click="tableButton(1,scope.row)"-->
                  <!--&gt;编辑</p>-->
                  <p class="table-button-p"
                     v-if="(scope.row.leaderSubmitStatus == 0 && scope.row.flowStatus == 0 && isLeader)"
                     @click="tableButton(1,scope.row)"
                  >编辑</p>
                  <p class="table-button-p"
                     v-if="(scope.row.leaderSubmitStatus == 0 && scope.row.flowStatus == 0 && isLeader)||(scope.row.adminSubmitStatus == 0 && scope.row.flowStatus == 1 && isSchoolAdmin)"
                     @click="tableButton(3,scope.row,scope.$index)"
                  >{{isSchoolAdmin?'审批':'提交'}}</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>
    <checkItem :propsData="propsData" v-if="pageType === 2"></checkItem>
    <initiateInspect v-if="pageType == 3" :initiateInspectData="initiateInspectData"></initiateInspect>
  </div>
</template>
<script>
  import {
    securityCheckHiddenDangerTitleList,
    securityCheckHiddenDangerList,
    securityMemberGetCollegeList,
    securityCheckHiddenDangerUpdate,
    securityCheckHiddenDangerFindCurrentMemberRole,
    securityCheckHiddenDangerBatchHiddenDangerSubmit,
  } 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 {
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //学院
        deptOption:[],
        //分类
        typeOption:[
          {key:'0',value:'待提交'},
          {key:'1',value:'已提交'},
        ],
        //计划查询条件
        leftQueryParams:{
          time:'',
          searchValue:'',
          page:1,
          pageSize:20,
        },
        titleTotal:0,
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          myRelated:1,
          deptId:null,
          floorId:null,
          leaderSubmitStatus :null,
          adminSubmitStatus :null,
          levelId :null,
          searchValue:'',
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
        leftBigCheckType:"0",
        leftCheckType:"0",
        leftListData:[],
        checkSetProgress:0,
        //检查组件
        initiateInspectData:{},
        //选中数据
        checkList:[],
        //批量完成展示状态
        memberRole:3,
        //是否是组长
        isLeader:false,
        //是否是校级管理员
        isSchoolAdmin:false,

      }
    },
    created () {

    },
    mounted () {
      this.getTitleList();
    },
    methods: {
      //左侧清除查询按钮
      leftClear(){
        this.$set(this.leftQueryParams,'searchValue','');
        this.$set(this.leftQueryParams,'time','');
        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();
          this.securityMemberGetCollegeList();
          this.securityCheckHiddenDangerFindCurrentMemberRole();
        }
      },
      //左侧计划子级切换
      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();
        }
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          deptId:null,
          floorId:null,
          leaderSubmitStatus :null,
          adminSubmitStatus :null,
          levelId :null,
          searchValue:'',
        });
        this.getList();
      },
      //获取计划数据列表
      getTitleList(){
        securityCheckHiddenDangerTitleList(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);
            this.securityMemberGetCollegeList();
            this.securityCheckHiddenDangerFindCurrentMemberRole();
          }
        });
      },
      getTitleListTwo(){
        securityCheckHiddenDangerTitleList(this.leftQueryParams).then(response => {
          this.$set(this,'leftListData',response.data.records);
          this.$set(this,'titleTotal',response.data.total);
          this.getList();
        });
      },
      //提交审批
      securityCheckHiddenDangerUpdate(item,index){
        console.log(index)
        let obj = {
          hiddenId:item.hiddenId,
        }
        if(item.flowStatus == 1){
          obj.adminSubmitStatus = 1;
          obj.flowStatus = 1;
        }else if(item.flowStatus == 0){
          obj.leaderSubmitStatus = 1;
          obj.flowStatus = 1;
        }
        securityCheckHiddenDangerUpdate(obj).then(response => {
          this.msgSuccess(response.message)
          if(this.listForEstimate(this.leftListData[this.leftBigCheckType].checkPlanSetVoList,index) == 1){
            this.getTitleList();
          }else{
            this.getList();
          }
        })
      },
      //批量提交审批
      securityCheckHiddenDangerBatchHiddenDangerSubmit(){
        let obj = {
          hiddenIds:this.checkList,
        };
        if(!this.isSchoolAdmin){
          //组长
          obj.flowStatus = 1;
          obj.leaderSubmitStatus = 1;
        }else{
          //管理员
          obj.flowStatus = 1;
          obj.adminSubmitStatus = 1;
        }
        securityCheckHiddenDangerBatchHiddenDangerSubmit(obj).then(response => {
          this.$set(this,'checkList',[]);
          this.$refs.multipleTable.clearSelection();
          this.msgSuccess(response.message)
          this.getTitleList();
        })
      },
      //获取数据列表
      getList(){
        if(!this.leftListData[0]){
          this.$set(this,'dataList',[]);
          this.$set(this,'total',0);
          return
        }
        this.$set(this,'loading',true);
        let obj = {
          planId:this.leftListData[this.leftBigCheckType].checkPlanSetVoList[this.leftCheckType].planId,
          planSetId:this.leftListData[this.leftBigCheckType].checkPlanSetVoList[this.leftCheckType].planSetId,
          page:this.queryParams.page,
          pageSize:this.queryParams.pageSize,
          deptId:this.queryParams.deptId,
        }
        if(!this.isSchoolAdmin){
          obj.leaderSubmitStatus = this.queryParams.leaderSubmitStatus;
        }else{
          obj.adminSubmitStatus = this.queryParams.adminSubmitStatus;
        }
        securityCheckHiddenDangerList(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,index){
        let self = this;
        if(type == 1){
          //编辑
          const route = this.$router.resolve({
            path: '/schoolHiddenDangerAdd',
            query: {
              type: 'edit',
              hiddenId:row.hiddenId
            }
          });
          window.open(route.href, '_blank');
        }else if(type == 2){
          //查看
          const route = this.$router.resolve({
            path: '/schoolHiddenDangerAdd',
            query: {
              type: 'look',
              hiddenId:row.hiddenId
            }
          });
          window.open(route.href, '_blank');
        }else if(type == 3){
          //提交
          this.$confirm(`是否确认提交?`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(async () => {
            self.securityCheckHiddenDangerUpdate(row,index);
          }).catch(() => {

          })
        }
      },
      //批量操作
      allTableButton(type){
        let self = this;
        if(!this.checkList[0]){
          this.msgError('请勾选数据')
          return
        }
        if(type == 1){
          //批量下载
          this.$set(this,'checkList',[]);
          this.$refs.multipleTable.clearSelection();
        }else if(type == 2){
          //批量提交
          if(!this.checkList[0]){
            this.msgError('请勾选数据')
            return
          }
          this.$confirm(`是否确认批量提交?`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(async () => {
            self.securityCheckHiddenDangerBatchHiddenDangerSubmit();
          }).catch(() => {

          })
        }
      },
      /*********************************** 学院/楼栋/分类/分级 ***********************************/
      //学院下拉列表
      securityMemberGetCollegeList(){
        securityMemberGetCollegeList({planId:this.leftListData[this.leftBigCheckType].checkPlanSetVoList[this.leftCheckType].planId}).then(response => {
          this.$set(this,'deptOption',response.data);
        });
      },
      //查询当前用户权限范围
      securityCheckHiddenDangerFindCurrentMemberRole(){
        securityCheckHiddenDangerFindCurrentMemberRole({planId:this.leftListData[this.leftBigCheckType].checkPlanSetVoList[this.leftCheckType].planId}).then(response => {
          this.$set(this,'isLeader',response.data.isLeader);
          this.$set(this,'isSchoolAdmin',response.data.isSchoolAdmin);
        });
      },
      /*===记录勾选数据===
        需要再el-table 添加  :row-key="getRowKeys"
        需要在selection 添加 :reserve-selection="true"
      */
      getRowKeys(row) {
        return row.manageId
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.$set(this,'checkList',selection.map(item => item.hiddenId));
      },
      //勾选判定
      checkSelectable(row, index) {
        return row.adminSubmitStatus != 1;
      },
      //数据判断方法
      listForEstimate(list,index){
        if(!list[1]){
          //只有一条数据
          return 1
        }else if(list.length-1 == index){
          //当前数据是数组最后一条数据
          return 2
        }else {
          //list 拥有多条数据 并且当前数据不是最后一条
          return 3
        }
      },
    },
  }
</script>
<style scoped lang="scss">
  .schoolHiddenDangerList{
    .schoolHiddenDangerListPage{
      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>
