<!--指标统计列表-->
<template>
  <div class="page-container checkIndexStatistics">
    <div class="page-form-title-box">
      <el-form :model="queryParams" class="form-box" ref="queryForm" :inline="true">
        <el-form-item label="" prop="deptId" label-width="50px" v-if="!userFlg">
          <el-select v-model="queryParams.deptId" 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="50px" v-if="userFlg">
          <el-select placeholder="请输入关键词" filterable remote reserve-keyword
                     v-model="queryParams.subId" :remote-method="getSubList">
            <el-option
              v-for="item in subSelectList"
              :key="item.subId"
              :label="item.subName"
              :value="item.subId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="searchValue" label-width="80px">
          <el-input
            maxLength="30"
            v-model="queryParams.searchValue"
            placeholder="计划任务"
            clearable
            style="width: 200px"/>
        </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.level1}}，占比 {{numData.percent1}}，二级指标隐患总数 {{numData.level2}}，占比 {{numData.percent2}}，三级指标隐患总数 {{numData.level3}}，占比 {{numData.percent3}}，四级指标隐患总数 {{numData.level4}}，占比 {{numData.percent4}}
      </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"/>
        <el-table-column label="序号" align="center"  type="index" width="60" />
        <el-table-column label="计划任务" align="center" prop="title" show-overflow-tooltip/>
        <el-table-column v-if="!userFlg" label="学院" align="center" prop="collegeName" show-overflow-tooltip width="230"/>
        <el-table-column v-if="userFlg" label="实验室" align="center" prop="subjectName" show-overflow-tooltip width="230"/>
        <el-table-column label="隐患总数" align="center" prop="sumTotal" show-overflow-tooltip width="120"/>
        <el-table-column label="一级指标隐患数" align="center" prop="itemsTotal1" show-overflow-tooltip width="130"/>
        <el-table-column label="一级指标占比" align="center" prop="percent" show-overflow-tooltip width="130"/>
        <el-table-column label="二级指标隐患数" align="center" prop="itemsTotal2" show-overflow-tooltip width="130"/>
        <el-table-column label="二级指标占比" align="center" prop="percent2" show-overflow-tooltip width="130"/>
        <el-table-column label="三级指标隐患数" align="center" prop="itemsTotal3" show-overflow-tooltip width="130"/>
        <el-table-column label="三级指标占比" align="center" prop="percent3" show-overflow-tooltip width="130"/>
        <el-table-column label="四级指标隐患数" align="center" prop="itemsTotal4" show-overflow-tooltip width="130"/>
        <el-table-column label="四级指标占比" align="center" prop="percent4" show-overflow-tooltip width="130"/>
      </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 {
  dataStatisticsItemsList, dataStatisticsItemsListTop, isSCollege, getloginUser,
  hiddenDataItemsSubList, hiddenDataItemsSubListTop, listSubAdmin, laboratorySubRelInfoGetListByDeptId
} from '@/api/safetyCheck/index'
  //            V3
  import exportComponent from "@/components/exportComponent/exportComponent.vue";
  import { getDeptDropList } from '@/api/commonality/permission'

  export default {
    name: 'checkIndexStatistics',
    components: {
      exportComponent,
    },
    props:{
      propsData:{},
    },
    data(){
      return{
        //导出
        exportConfig:{
          api:'',             //导出接口地址
          ids:'',                                       //勾选导出,勾选的IDS
          fileName:'检查指标统计',                         //导出文件的命名
        },
        deptSelectList:[],
        subSelectList:[],
        classTypeList:[],
        classifiedList:[],
        dateRange:[],
        queryParams:{
          page:1,
          pageSize:20,
          deptId:null,
          subId:null,
          searchValue:null,
        },
        setChildren:"",
        numData:{},
        tableList:[],
        total:0,
        userFlg:false,
        deptId:"",
      }
    },
    created(){
    },
    mounted(){
      this.initializationInterface();
    },
    methods:{
      initializationInterface(){
        let self = this;
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          searchValue:null,
        });
        //获取学院列表
        getDeptDropList({ deptName: '', level: 2, deptType: 1 }).then(response => {
          this.$set(this, 'deptSelectList', response.data)
        })
        getloginUser().then(response => {
          this.$set(this,'deptId',response.data.deptId)
          this.getSubList('');
        });
        isSCollege().then(response => {
          this.$set(this,'userFlg',response.data.userFlg);
          if(this.userFlg){
            this.$set(this.queryParams,'subId',null)
            this.$set(this.exportConfig,'api','/zd-security/collegCheck/collegeItemsExport/')
          }else{
            this.$set(this.queryParams,'deptId',null)
            this.$set(this.exportConfig,'api','/zd-security/DataStatistics/itemsExport/')
          }
          setTimeout(function(){
            self.getList();
          },200);
        })
      },
      //实验室搜索
      getSubList(val){
        console.log('val',val)
        laboratorySubRelInfoGetListByDeptId({deptIds:[this.deptId],subName:val}).then(response => {
          this.subSelectList = response.data;
        });
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        let objTop = 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';

          objTop.beginTime=this.dateRange[0]+'T00:00:00';
          objTop.endTime=this.dateRange[1]+'T23:59:59';
        }else{
          obj.beginTime== "";
          obj.endTime== "";
          objTop.beginTime== "";
          objTop.endTime== "";
        }


        delete objTop.page
        delete objTop.pageSize
        if(this.userFlg){
          //院级
          hiddenDataItemsSubList(obj).then(response => {
            this.total = response.data.total;
            this.tableList = response.data.records;
          });
          hiddenDataItemsSubListTop(objTop).then(response => {
            this.$set(this,'numData',response.data);
          });
        }else{
          //校级
          dataStatisticsItemsList(obj).then(response => {
            this.total = response.data.total;
            this.tableList = response.data.records;
          });
          dataStatisticsItemsListTop(objTop).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,
          searchValue:null,
        });
        if(this.userFlg){
          this.$set(this.queryParams,'subId',null)
        }else{
          this.$set(this.queryParams,'deptId',null)
        }
        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">
  .checkIndexStatistics{
    .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>
