<template>
  <div class="snapshotManagement-listPage">
    <div class="snapshotManagement-listPage-min" v-if="infoPageType == 1">
      <div class="page-form-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">
              <div :class="queryParams.rectifyStatus===''?'checkDiv':''" @click="topLeftClickType('')">
                <p class="text-p">全部</p>
                <p class="el-icon-check icon-p" v-if="queryParams.rectifyStatus===''"></p>
              </div>
              <div :class="queryParams.rectifyStatus===0?'checkDiv':''" @click="topLeftClickType(0)">
                <p class="text-p">待整改</p>
                <p class="el-icon-check icon-p" v-if="queryParams.rectifyStatus===0"></p>
              </div>
              <div :class="queryParams.rectifyStatus===1?'checkDiv':''" @click="topLeftClickType(1)">
                <p class="text-p">已整改</p>
                <p class="el-icon-check icon-p" v-if="queryParams.rectifyStatus===1"></p>
              </div>
              <div :class="queryParams.rectifyStatus===2?'checkDiv':''" @click="topLeftClickType(2)">
                <p class="text-p">暂无法整改</p>
                <p class="el-icon-check icon-p" v-if="queryParams.rectifyStatus===2"></p>
              </div>
            </div>
          </div>
          <el-form-item label="" prop="searchValue" style="margin-left:10px;">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="实验室/房间号/上报人"
              clearable
              style="width: 180px"
            />
          </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: 220px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery" style="margin-right:10px;">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-out-common-style-button"
             style="float: right;"
             @click="outButton"
          >返回</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" 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="deptName" show-overflow-tooltip/>
          <el-table-column label="实验室" align="center" prop="subName" show-overflow-tooltip width="220">
            <template slot-scope="scope">{{scope.row.roomNum?scope.row.subName+'-'+scope.row.roomNum:scope.row.subName}}</template>
          </el-table-column>
          <el-table-column label="安全员" align="center" prop="safetyPeople" show-overflow-tooltip width="120"/>
          <el-table-column label="上报人" align="center" prop="createName" show-overflow-tooltip width="90"/>
          <el-table-column label="上报时间" sortable="custom" align="center" prop="createTime" show-overflow-tooltip width="157"/>
          <el-table-column label="隐患描述" align="center" prop="hazardDescribe" show-overflow-tooltip width="280"/>
          <el-table-column label="整改人" align="center" prop="rectifyPeople" show-overflow-tooltip width="100"/>
          <el-table-column label="整改时间" sortable="custom" align="center" prop="rectifyTime" show-overflow-tooltip width="157"/>
          <el-table-column label="整改状态" align="center" prop="rectifyStatus" show-overflow-tooltip width="120">
            <template slot-scope="scope">
              {{scope.row.rectifyStatus==0?'待整改':(scope.row.rectifyStatus==1?'已整改':(scope.row.rectifyStatus==2?'暂无法整改':''))}}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" prop="deptName" width="120">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p" @click="goPage(3,scope.row)" v-hasPermiRouter="['safety:rectifyClap:detail']">详情</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>
    <infoPage v-if="infoPageType == 3" :infoPropsData="infoPropsData"></infoPage>
  </div>
</template>

<script>
  import { checkClapMylist } from '@/api/safetyCheck/index'
  import infoPage from './infoPage.vue'
  import { getDeptDropList } from '@/api/commonality/permission'
  export default {
    name: 'listPage',
    components: {
      infoPage
    },
    data(){
      return{
        infoPageType:1,
        deptSelectList:[],
        queryParams:{
          page:1,
          pageSize:20,
          deptId:'',
          searchValue:'',
          rectifyStatus:'',
          upTimeOrder:"",
          zgTimeOrder:"",
        },
        dateRange:[],
        tableList:[],
        total:0,
        //详情
        infoPropsData:{}
      }
    },
    created(){

    },
    mounted(){
      this.listDepartments();
      this.getList();
    },
    methods:{
      //详情按钮
      goPage(type,data){
        if(this.infoPageType != type){
          if (type==1){
            this.$set(this,'infoPageType',type);
          } else if(type==2){
            this.$set(this,'infoPageType',type);
          } else if(type==3){
            this.$set(this,'infoPropsData',data);
            this.$set(this,'infoPageType',type);
          } else if(type==4){
            this.$set(this,'infoPageType',1);
            this.getList();
          }
        }
      },
      //返回按钮
      outButton(){
        this.$parent.goPage(1);
      },
      //范围选择
      topLeftClickType(type){
        if(this.queryParams.rectifyStatus !== type){
          this.$set(this.queryParams,'rectifyStatus',type);
          this.handleQuery();
        }
      },
      //时间排序方法
      sortChange(val){
        if(val.prop == 'rectifyTime'){
          this.$set(this.queryParams,'zgTimeOrder',val.order=='ascending'?'1':(val.order=='descending'?'2':''));
          this.$set(this.queryParams,'upTimeOrder','');
          this.handleQuery();
        }else if(val.prop == 'createTime'){
          this.$set(this.queryParams,'upTimeOrder',val.order=='ascending'?'1':(val.order=='descending'?'2':''));
          this.$set(this.queryParams,'zgTimeOrder','');
          this.handleQuery();
        }
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))

        if(this.dateRange[0]) {
          obj.beginDate=this.dateRange[0]+'T00:00:00';
          obj.endDate=this.dateRange[1]+'T23:59:59';
        } else {
          obj.beginDate='';
          obj.endDate='';
        }

        checkClapMylist(obj).then(response => {
          this.total = response.data.total;
          this.tableList = response.data.records;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'dateRange',[]);
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          deptId:'',
          searchValue:'',
          rectifyStatus:'',
          upTimeOrder:"",
          zgTimeOrder:"",
        });
        this.handleQuery();
      },
      //获取学院列表
      listDepartments(){
        getDeptDropList({deptName:"",level:2,deptType:1}).then(response => {
          this.$set(this, 'deptSelectList', response.data)
        });
      },
    }
  }
</script>

<style scoped lang="scss">
  .snapshotManagement-listPage{
    flex: 1;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    .snapshotManagement-listPage-min{
      flex: 1;
      display: flex !important;
      flex-direction: column;
      overflow: hidden;
      .page-form-title-box{
        .form-button-max-big-box{
          display: inline-block;
          overflow: hidden;
          .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;
              }
            }
            div:nth-child(4){
              width:110px;
            }
            .checkDiv{
              color:#0183FA;
              border:1px solid #0183FA;
            }
          }
        }
      }
    }
  }
</style>
