<!--检查内容统计列表-->
<template>
  <div class="page-container safetyHazardStatistics">
    <div class="page-form-title-box">
      <el-form :model="queryParams" class="form-box" ref="queryForm" :inline="true">
        <el-form-item label="" prop="rectifyStatus">
          <el-select v-model="queryParams.hazardTypeMode" clearable placeholder="全部检查内容">
            <el-option
              v-for="item in materialTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="deptId" label-width="50px">
          <el-select v-model="queryParams.deptId" @change="handleNodeClick" clearable placeholder="全部学院">
            <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="subId" label-width="58px">
          <el-select v-model="queryParams.subId" placeholder="请选择实验室">
            <el-option
              v-for="item in subjectOptions"
              :key="item.subId"
              :label="item.subName"
              :value="item.subId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="dateRange" label-width="70px">
          <el-date-picker
            :clearable="false"
            v-model="dateRange"
            size="small"
            style="width: 240px"
            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>
        <el-form-item style="float: right;" v-hasPermiRouter="['safety:dataSub:export']">
          <export-component :exportConfig="exportConfig"></export-component>

        </el-form-item>
      </el-form>
    </div>
    <div class="page-content-box">
      <div class="num-data-box">
        共搜索到隐患总数 {{numData.sumTotal}}，已整改数 {{numData.sumYzg}}， 未整改数 {{numData.sumWzg}}，整改率 {{numData.rate}}
      </div>
      <el-table class="table-box" border :data="tableList" ref="table-box"
                 :row-key="getRowKeys"
                @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="50" align="center" fixed/>
        <el-table-column label="序号" align="center"  type="index" width="60" fixed/>
        <el-table-column label="检查内容" align="center" prop="hazardName" show-overflow-tooltip width="200" fixed/>
        <el-table-column label="学院" align="center" prop="collegeName" show-overflow-tooltip width="200" fixed/>
        <el-table-column label="实验室" align="center" prop="subjectName" show-overflow-tooltip width="180"/>
        <el-table-column label="隐患总数" align="center" prop="sumTotal" show-overflow-tooltip width="100"/>
        <el-table-column label="隐患占比" align="center" prop="percent" show-overflow-tooltip width="180"/>
        <el-table-column label="已整改" align="center" prop="sumYzg" show-overflow-tooltip width="180"/>
        <el-table-column label="未整改" align="center" prop="sumWzg" show-overflow-tooltip width="180"/>
        <el-table-column label="整改率" align="center" prop="percent2" show-overflow-tooltip width="180"/>
      </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>
</template>

<script>
  import { getDicts } from "@/api/commonality/noPermission";
  import {
    dataStatisticsContentList,
    dataStatisticsContentListTop,
    laboratorySubRelInfoGetListByDeptId
  } from '@/api/safetyCheck/index'
  import { dangerList } from '@/apiDemo/gasManage3_0/gasManage'
  import { subjectDictList } from '@/apiDemo/laboratory/record'
  //            V3
  import exportComponent from "@/components/exportComponent/exportComponent.vue";
  import { getDeptDropList } from '@/api/commonality/permission'

  export default {
    name: 'safetyHazardStatistics',
    components: {
      exportComponent,
    },
    data(){
      return{
        //导出
        exportConfig:{
          api:'/zd-security/DataStatistics/contentExport/',             //导出接口地址
          ids:'',                                       //勾选导出,勾选的IDS
          fileName:'检查内容统计',                         //导出文件的命名
        },
        deptSelectList:[],
        materialTypeList:[],
        subjectOptions:[],
        levelList:[{label:"一般隐患",key:"2"},{label:"重大隐患",key:"1"},{label:"管理问题",key:"3"}],
        dateRange:[],
        queryParams:{
          page:1,
          pageSize:20,
          hazardTypeMode:null,
          deptId:null,
          subId:null,
        },
        setChildren:"",
        numData:{},
        tableList:[],
        total:0,
      }
    },
    created(){

    },
    mounted(){
      this.dangerList();
      this.initializationInterface();
      this.getList();
    },
    methods:{
      initializationInterface(){
        //获取学院列表
        getDeptDropList({ deptName: '', level: 2, deptType: 1 }).then(response => {
          this.$set(this, 'deptSelectList', response.data)
        })
      },
      //获取危险源类型
      dangerList(){
        let self=this;
        getDicts('lab_hazard_type').then(response => {
          this.$set(this,'materialTypeList',response.data);
        });
      },
      // 节点单击事件
      handleNodeClick(data) {
        this.queryParams.deptId = data;
        this.getSubjectDictList(data);
      },
      /** 查询实验室字典列表 */
      getSubjectDictList (deptId) {
        this.subjectOptions = null;
        laboratorySubRelInfoGetListByDeptId({deptIds:[deptId],subName:''}).then(response => {
          this.subjectOptions = response.data;
        });
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.beginTime=this.dateRange[0]+'T00:00:00';
          obj.endTime=this.dateRange[1]+'T23:59:59';
        }else{
          obj.beginTime== "";
          obj.endTime== "";
        }
        dataStatisticsContentList(obj).then(response => {
          this.total = response.data.total;
          this.tableList = response.data.records;
        });
        dataStatisticsContentListTop(obj).then(response => {
          this.$set(this,'numData',response.data);
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'dateRange',[]);
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          hazardTypeMode:"",
          deptId:"",
          subId:"",
        });
        this.handleQuery();
      },
      /*===记录勾选数据===
        需要再el-table 添加  :row-key="getRowKeys"
        需要在selection 添加 :reserve-selection="true"
      */
      getRowKeys(row) {
        return row.id
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.exportConfig.ids = selection.map(item => item.id);
      },
    }
  }
</script>

<style scoped lang="scss">
  ::v-deep .el-table__body-wrapper{
    padding-bottom: 8px;
  }
  ::v-deep .el-table__fixed{
    margin-top:-1px;
    margin-left:-1px;
    height:calc(100% - 8px)!important;
  }
  ::v-deep .el-table__fixed-body-wrapper{
    height: calc(100% - 48px);
    overflow-y: auto;
  }
  .safetyHazardStatistics{
    .form-box{
      .form-dropdown-box{
        display: flex;
        margin:0;
        padding:0 10px;
        cursor: pointer;
        height:40px;
        img:nth-child(1){
          width:16px;
          height:16px;
          margin-top:12px;
        }
        p{
          width:47px;
          text-align: center;
          font-size:14px;
          margin:0;
          line-height:40px;
        }
        img:nth-child(3){
          width:10px;
          height:6px;
          margin-top:17px;
        }
      }
    }
    .num-data-box{
      background: rgba(1,131,250,0.2);
      color:#0183FA;
      font-size:14px;
      line-height:40px;
      padding:0 20px;
      border-radius:4px;
      margin-bottom:20px;
    }

  }
</style>
