<template>
  <div class="snapshotManagement-listPage">
    <div class="snapshotManagement-listPage-min" v-if="infoPageType == 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.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">
            <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>
          <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;">
            <el-col :span="1.5">
              <p class="add-button-one-90"
                 style="width:100px;font-weight:500;"
                 @click="outButton"
              >返回</p>
            </el-col>
          </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="deptName" show-overflow-tooltip/>
          <el-table-column label="实验室" align="center" prop="subName" show-overflow-tooltip width="220"/>
          <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="70">
            <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-hasPermi="['safety:rectifyClap:query']">详情</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>
    <infoPage v-if="infoPageType == 3" :infoPropsData="infoPropsData"></infoPage>
  </div>
</template>

<script>
  import { listDepartments } from "@/api/system/dept";
  import { checkClapMylist } from '@/api/safetyCheck/index'
  import infoPage from './infoPage.vue'
  export default {
    name: 'listPage',
    components: {
      infoPage
    },
    data(){
      return{
        infoPageType:1,
        deptSelectList:[],
        queryParams:{
          pageNum: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.getList();
        }
      },
      //时间排序方法
      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.beginTime = this.dateRange[0]
        }else{
          obj.beginTime = ""
        }
        if(this.dateRange[1]){
          obj.endTime = this.dateRange[1]
        }else{
          obj.endTime = ""
        }
        checkClapMylist(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,
          deptId:'',
          searchValue:'',
          rectifyStatus:'',
          upTimeOrder:"",
          zgTimeOrder:"",
        });
        this.handleQuery();
      },
      //获取学院列表
      listDepartments(){
        listDepartments().then(response => {
          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;
      .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>
