<template>
  <div class="main" v-cloak>

        <Header/>
        <div class="main_t">
            <div class="main_t_t">
                <i class="main_t_t_l">当前位置：首页 &gt;</i>
                <i>人员违规统计</i>
            </div>
            <div class="main_t_b" id="illegal_chart"></div>
        </div>
        <div class="main_b">
            <!--查询条件-->
            <el-form :model="editForm" ref="queryParams" class="form-box" :inline="true" style="margin:20px;">
                <el-form-item label="实验室" prop="dangerId" label-width="98px">
                    <el-select v-model="editForm.subId" popper-class="select-big-data" placeholder="请选择实验室">
                        <el-option
                                v-for="item in labList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="违规原因" prop="dangerId" label-width="98px">
                    <el-select v-model="editForm.violationType" popper-class="select-big-data" placeholder="请选择违规原因">
                        <el-option
                                v-for="item in causeList"
                                :key="item.id"
                                :label="item.violationName"
                                :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="日期" prop="dateRange" label-width="68px">
                    <el-date-picker
                            popper-class="select-big-data-time"
                            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>
                <el-form-item label-width="0">
                    <el-button type="primary" @click.native.prevent="onSearch" native-type="submit">查询</el-button>
                    <el-button @click="resetForm('searchForm')">重置</el-button>
                </el-form-item>
            </el-form>
            <!--列表-->
            <el-table :data="tableData"  style="width: 100%"  height="420" :row-class-name="tableRowClassName">
                <el-table-column align="center" header-align='center' type="index" :index="indexMethod" label="序号" width="60"></el-table-column>
                <el-table-column align="center" header-align='center' prop="subName" label="实验室"></el-table-column>
                <el-table-column align="center" header-align='center' prop="typeName" label="安全分类"></el-table-column>
                <el-table-column align="center" header-align='center' prop="classifiedName" label="安全分级"></el-table-column>
                <el-table-column align="center" header-align='center' prop="content" label="违规原因"></el-table-column>
                <el-table-column align="center" header-align='center' prop="num" label="违规次数"></el-table-column>
            </el-table>
            <el-pagination
                    style="margin-top: 14px"
                    background
                    @current-change="handleCurrentChange"
                    :page-sizes="[10, 20, 30, 40]"
                    :current-page.sync="param.pageNo"
                    :page-size="param.pageSize"
                    layout="total,prev, pager, next"
                    :total="totalNum">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import {
  departmentsList,
  detailColumnar,
  detailSubList,
  getDictViolation,
  getSubjectDict,
} from "../api/http"
import Header from '@/components/header.vue'
export default {
  components: {
    Header
  },
  data() {
    return {
     //查询条件
      param:{
        pageNo:1,
        pageSize:5
      },
      editForm:{
        deptLevel:'',//这个是登陆后，刘波给你的院校的类型
        subId:'',//实验室
        violationType:'',//违规类型
        beginTimeStr:'',//开始时间
        endTimeStr:'',//结束时间
      },
      subjectOptions:[],//院系
      causeList:[],//违规原因
      dateRange:[],//时间
      totalNum:0,
      tableData:[],
      labList:[],//实验室
      endDay:new Date(2019,11,0).getDate()

    }
  },
  methods: {
    back(){
      this.$router.push('/')
    },
    tableRowClassName({ rowIndex}) {
      if (rowIndex%2 === 0) {
        return 'success-row';
      } else{

        return 'warning-row';
      }
    },
    indexMethod(index) {
      return (this.param.pageNo - 1) * this.param.pageSize + index + 1;
    },
    //请求列表
    getAjaxList:function (){
      let _this=this;
      //列表
      let obj={
        'subjectId':this.editForm.subId,
        'violationType':this.editForm.violationType,
        'beginTimeStr':this.editForm.beginTimeStr,
        'endTimeStr':this.editForm.endTimeStr,
      }
      detailSubList(obj).then((res) =>{
        if(res.code==200){
          let data = res.rows;
          if(data && data.length>0){
            _this.tableData = data;
            _this.totalNum = res.total;
          }else{
            _this.tableData = [];
            _this.totalNum = 0;
          }
        }
      })
    },
    getAjaxData: function () {
      let _this=this;
      //人员违规统计图表

      let obj={
        'deptLevel':localStorage.getItem('deptLevel'),
        'subjectId':this.editForm.subId,
        'violationType':this.editForm.violationType,
        'beginTimeStr':this.editForm.beginTimeStr,
        'endTimeStr':this.editForm.endTimeStr,
      }
      detailColumnar(obj).then((res) =>{
        if(res.code==200){
          var illegalDetailData=[];
          let data=res.data;
          let dataLength=0;
          let dataNum=[];

          if(data.length<=1){
            illegalDetailData=[
              ['product', '离开未打卡', '未佩戴护目镜', '未佩戴实验手套', '非法闯入', '未穿着实验服','实验室清洁'],
              ['第一季度', 0, 0, 0,0,0,0],
              ['第二季度', 0, 0, 0,0,0,0],
              ['第三季度', 0, 0, 0,0,0,0],
              ['第四季度', 0, 0, 0,0,0,0],

            ]
            dataNum= [
              { type: 'bar', itemStyle: { normal: { barBorderRadius: 8}} ,"label": {"normal": {"show": true,"position": "top",fontSize: 14,color: '#fff',}},},
              { type: 'bar' , itemStyle: { normal: { barBorderRadius: 8}}},
              { type: 'bar', itemStyle: { normal: { barBorderRadius: 8}} },
              { type: 'bar' , itemStyle: { normal: { barBorderRadius: 8}}},
              { type: 'bar', itemStyle: { normal: { barBorderRadius: 8}} },
              { type: 'bar' , itemStyle: { normal: { barBorderRadius: 8}}}
            ]

          }else{
            illegalDetailData=data
            illegalDetailData[0].unshift('product')
            dataLength=illegalDetailData[0].length-1
            for(var i=0;i<dataLength;i++){
              dataNum.push({ type: 'bar',barMaxWidth: "20", itemStyle: { normal: { barBorderRadius: 8}},"label": {"normal": {"show": true,"position": "top",fontSize: 14,color: '#fff',}}, },)
            }
          }
          _this.illegalDetailFun(illegalDetailData,dataNum)

        }
      })

      //查询院系
      departmentsList().then((res) =>{
        if(res.code==200){
          let data=res.data;
          _this.subjectOptions=data
        }
      })
      //查询实验室
      getSubjectDict().then((res) =>{
        if(res.code==200){
          let data=res.data;
          _this.labList=data

        }
      })
      //查询违规原因
      getDictViolation().then((res) =>{
        if(res.code==200){
          let data=res.data;
          _this.causeList=data

        }
      })
    },
    /*查询*/
    onSearch() {

      if(this.dateRange.length>0){
        this.editForm.beginTimeStr = this.dateRange[0];
        this.editForm.endTimeStr = this.dateRange[1];
      }
      this.getAjaxList();
      this.getAjaxData();
    },
    /*重置*/
    resetForm() {

      this.editForm.subId = "";
      this.editForm.violationType = "";
      this.editForm.beginTimeStr=this.getdate()+'-1'
      this.editForm.endTimeStr=this.getdate()+'-'+this.endDay
      this.dateRange = [];
      this.onSearch();
    },
    handleCurrentChange(val) {
      this.param.pageNo = val;
      // this.getAjaxList();
    },
    getdate() {
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var strDate = date.getDate();

      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      var currentdate = year + "-" + month;
      return currentdate;
    },
    /*安全隐患详情图表*/
     illegalDetailFun:function(illegalDetailData,dataNum) {
      let illegalOption = {

        color: ['#05A3CD','#1CB146','#822FDF','#C65A18','#18C4C6','#055ACD'],
        legend: {
          type: 'scroll',

          itemGap:20,
          itemWidth :14,
          textStyle:{
            color:'#fff'
          },
          right: '5%',
          top: '2%',
        },
        tooltip: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          top: '20%',
          containLabel: true
        },
        dataset: {
          /*source: [
              ['product', '离开未打卡', '未佩戴护目镜', '未佩戴实验手套', '非法闯入', '为穿着实验服','实验室清洁'],
              ['第一季度', 43.3, 85.8, 93.7,12,12,34],
              ['第二季度', 83.1, 73.4, 55.1,12,12,34],
              ['第三季度', 86.4, 65.2, 82.5,12,12,34],
              ['第四季度', 72.4, 53.9, 39.1,12,12,34]
          ]*/
          source:illegalDetailData
        },
        xAxis: {
          type: 'category',
          axisLabel: {
            textStyle: {//改变X轴字体颜色
              color: '#fff',

            }
          },
          axisTick:{//去掉X轴刻度
            show:false,
          },
          axisLine:{
            lineStyle:{
              color:'#2E4C74',//改变X轴颜色
              width: 2,

            }
          },




        },
        yAxis: {
          axisLabel: {
            textStyle: {//改变X轴字体颜色
              color: '#fff',

            }
          },
          splitLine: {           // 分隔线
            show: false,        // 默认显示，属性show控制显示与否
            lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
              color: ['#fff'],
              width: 1,
              type: 'solid',
              opacity:0.15
            },

          },
          axisTick:{//去掉X轴刻度
            show:false,
          },
          axisLine:{
            show:true,
            lineStyle:{
              color:'#2E4C74',//改变X轴颜色
              width: 2,

            }
          },
        },
        // Declare several bar series, each will be mapped
        // to a column of dataset.source by default.


        series:dataNum
        /* series: [
             { type: 'bar', itemStyle: { normal: { barBorderRadius: 8}} ,"label": {"normal": {"show": true,"position": "top",fontSize: 14,color: '#fff',}},},
             { type: 'bar' , itemStyle: { normal: { barBorderRadius: 8}}},
             { type: 'bar', itemStyle: { normal: { barBorderRadius: 8}} },
             { type: 'bar' , itemStyle: { normal: { barBorderRadius: 8}}},
             { type: 'bar', itemStyle: { normal: { barBorderRadius: 8}} },
             { type: 'bar' , itemStyle: { normal: { barBorderRadius: 8}}}
         ]*/
      };
      var illegal_chart = this.$echarts.init(document.getElementById('illegal_chart'));
      illegal_chart.setOption(illegalOption);
    }
  },
  beforeMount(){
    let _this=this
    _this.editForm.beginTimeStr=_this.getdate()+'-1'
    _this.editForm.endTimeStr=_this.getdate()+'-'+_this.endDay
  },
  mounted() {

    this.getAjaxData()
    this.getAjaxList()


  },


}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>

@function rw($px){

  @return $px*100/1920 *1vw;
}
@function rh($px){

  @return $px*100/1080 *1vh;
}
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.main {
  width: rw(1920);
  height: rh(1080);
  /* background: url("../img/index_bg.png") no-repeat;
   background-size: 100% 100%;*/
  position: relative;
  left: 0;
  top: 0;
  z-index: 50;

  background: #062338;

  .header {
    width: 100%;
    position: absolute;
    left: rw(0);
    top: rh(0);
    z-index: 100;
    display: flex;
    justify-content: flex-start;

    .header_l {
      width: rw(182);
      height: rh(44);
      margin: rh(10) 0 0 rw(40);
    }
    .header_c {
      width: rw(1180);
      height: rh(152);
      margin-left: rw(136);
      background: url("~@/assets/image/index_icon2.png") no-repeat;
      background-size: 100% 100%;
      font-size: rh(30);
      font-family: Microsoft YaHei;
      font-weight: bold;
      color: #FFFFFF;
      line-height: rh(30);
      text-align: center;
      padding-top: rh(26);
    }
    .header_r {
      margin-left: rw(264);
      width: rw(82);
      height: rh(32);
      margin-top: rh(18);
    }
  }
  .main_t{
    background: rgba(9, 55, 81, 0.6);
    width: rw(1852);
    height: rh(352);
    position: absolute;
    left: rw(34);
    top: rh(86);
    z-index: 200;
    .main_t_t{
      margin: rh(20) 0 0 rw(18);
      >i{
        font-size: rh(16);
        font-family: Microsoft YaHei;
        font-weight: bold;
        color: #FFFFFF;
        line-height: rh(16);
      }
      >i:nth-of-type(1){

      }
      >i:nth-of-type(2){
        color: #1ED0F8;
      }
    }
    .main_t_b{
      width: rw(1852);
      height: rh(302);
    }
  }
  .main_b{
    background: rgba(9, 55, 81, 0.6);
    padding: 0 rw(32);
    width: rw(1852);
    height: rh(602);
    position: absolute;
    left: rw(34);
    top: rh(468);
    z-index: 200;
  }
}
</style>
<style lang="scss">
li{list-style:none}
i,em,b{font-style:normal;font-weight:100;}
body{margin: 0}
</style>
