<template>
  <div class="userEquipmentComponentsTable">
    <div class="top-title-max-ox">
      <p></p>
      <p>人员设备安全</p>
      <p></p>
      <div class="title-button" @click="outButton">
        <img src="@/assets/ZDimages/icon_yh_fh@1x.png">
        <p>返回</p>
      </div>
    </div>
    <div class="table-title-box">
      <p class="table-title-p">数据筛选</p>
      <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: 260px">
            <el-option
              v-for="item in deptOptions"
              :key="item.deptId"
              :label="item.deptName"
              :value="item.deptId"
            />
          </el-select>
        </el-form-item>
        <p class="form-inquire-common-style-button" @click="handleQuery">查询</p>
        <p class="form-reset-common-style-button" @click="resetQuery">重置</p>
      </el-form>
    </div>
    <div class="table-list-box">
      <p class="table-list-p">数据列表</p>
      <div class="table-list">
        <el-table class="table-box" :row-class-name="tableRowClassName"
                  :data="dataList" @sort-change="sortChange">
          <el-table-column align="center" label="序号"  width="150"  type="index"/>
          <el-table-column align="center" label="学院" prop="deptName"  show-overflow-tooltip/>
          <el-table-column align="center" sortable="custom" label="总人数" prop="totalNum" width="300" show-overflow-tooltip/>
          <el-table-column align="center" sortable="custom" label="办理准入人数" prop="safeApplyNum" width="300" show-overflow-tooltip/>
          <el-table-column align="center" sortable="custom" label="实验人数" prop="subPassOutNum" width="300" show-overflow-tooltip/>
          <el-table-column align="center" sortable="custom" label="值日人数" prop="boardDutyNum" width="300" show-overflow-tooltip/>
          <el-table-column align="center" sortable="custom" label="检查项数" prop="boardPatrolNum" width="300" show-overflow-tooltip/>
          <el-table-column align="center" sortable="custom" label="超期设备" prop="deviceNum" width="300" show-overflow-tooltip/>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    layout="total,sizes, prev, pager, next"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>
<script>
  import { getDeptDropList,reportReportBigDataDeviceSafetyGroupCount } from "@/api/index";
  export default {
    name: 'userEquipmentComponentsTable',
    data () {
      return {
        //学院列表
        deptOptions:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          deptId:"",
        },
        //列表数据
        dataList:[],
        //数据数量
        total:60,
      }
    },
    created(){

    },
    mounted(){
      this.getDeptDropList();
      this.getList();
    },
    methods:{
      outButton(){
        this.$parent.checkComponentType(null)
      },
      //排序方法
      sortChange(val){
        if(val.prop == 'totalNum'){
          //总人数
          this.$set(this.queryParams,'sortType',val.order=='ascending'?1:(val.order=='descending'?2:''));
          this.$set(this.queryParams,'sortAttri',1);
          this.handleQuery();
        }else if(val.prop == 'safeApplyNum'){
          //办理准入人数
          this.$set(this.queryParams,'sortType',val.order=='ascending'?1:(val.order=='descending'?2:''));
          this.$set(this.queryParams,'sortAttri',2);
          this.handleQuery();
        }else if(val.prop == 'subPassOutNum'){
          //实验人数
          this.$set(this.queryParams,'sortType',val.order=='ascending'?1:(val.order=='descending'?2:''));
          this.$set(this.queryParams,'sortAttri',3);
          this.handleQuery();
        }else if(val.prop == 'boardDutyNum'){
          //值日人数
          this.$set(this.queryParams,'sortType',val.order=='ascending'?1:(val.order=='descending'?2:''));
          this.$set(this.queryParams,'sortAttri',4);
          this.handleQuery();
        }else if(val.prop == 'boardPatrolNum'){
          //检查次数
          this.$set(this.queryParams,'sortType',val.order=='ascending'?1:(val.order=='descending'?2:''));
          this.$set(this.queryParams,'sortAttri',5);
          this.handleQuery();
        }else if(val.prop == 'deviceNum'){
          //超期设备
          this.$set(this.queryParams,'sortType',val.order=='ascending'?1:(val.order=='descending'?2:''));
          this.$set(this.queryParams,'sortAttri',6);
          this.handleQuery();
        }else{
          this.$set(this.queryParams,'ascOrDesc',null);
          this.$set(this.queryParams,'sortAttri',null);
          this.handleQuery();
        }
      },
      //列表查询
      getList(){
        reportReportBigDataDeviceSafetyGroupCount(this.queryParams).then(response => {
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          deptId:"",
        });
        this.getList();
      },
      tableRowClassName({row, rowIndex}) {
        if (rowIndex  % 2 == 0) {
          return 'warning-row';
        } else {
          return 'success-row';
        }
        return ''
      },
      //查询学院列表
      getDeptDropList(){
        getDeptDropList({deptName:"",level:2,deptType:1}).then(response => {
          this.$set(this, 'deptOptions', response.data)
        });
      },
    },
  }
</script>
<style scoped lang="scss">
  .userEquipmentComponentsTable{
    padding:0 62px;
    height:1340px;
    display: flex;
    flex-direction: column;
    flex:1;
    overflow: hidden;
    .top-title-max-ox{
      display: flex;
      margin:20px 0;
      p:nth-child(1){
        width:10px;
        height:30px;
        background-color: #15827C;
        margin:5px 20px 0 0;
      }
      p:nth-child(2){
        color:#00FFFF;
        font-size:26px;
        line-height:40px;
      }
      p:nth-child(3){
        flex:1;
      }
      .title-button{
        width:120px;
        height:40px;
        background-color: #021D20;
        border:1px solid #15827C;
        display: flex;
        cursor: pointer;
        img{
          display: block;
          width:24px;
          height:24px;
          margin:8px 15px 0 12px;
        }
        p{
          font-size:18px;
          line-height:42px;
          color:#fff;
        }
      }
    }
    .table-title-box{
      height:200px;
      background-color: #002329;
      margin-bottom:20px;
      .table-title-p{
        line-height:80px;
        border-bottom:1px solid #15827C;
        padding-left:30px;
        font-size:24px;
        color:#fff;
      }
    }
    .table-list-box{
      flex:1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      background: linear-gradient(180deg, rgba(4, 117, 129, 0.2) 0%, rgba(0, 15, 22, 0) 100%);
      .table-list-p{
        line-height:80px;
        border-bottom:1px solid #15827C;
        padding-left:30px;
        font-size:24px;
        color:#fff;
      }
      .table-list{
        padding:35px 30px 0;
        flex:1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
      }
    }
  }
</style>
