<template>
  <div id="analysis-average-time"  class="block h100">
    <div class="black-title">办件可优化趋势</div>
    <div  v-loading="loading"  element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(3, 30, 57, 0.8)">
      <div  class="flex3 echarts" ref="echarts"></div>
<!--      <div v-if="$store.state.analysisThirdLevel!=''&&$store.state.analysisForthLevel==''" :key="2" class="flex3 echarts" ref="echarts"></div>-->

<!--      <div v-if="$store.state.analysisForthLevel!=''" :key="3" class="flex3 echarts" ref="echarts"></div>-->
    </div>
  </div>
</template>

<script>
import {setAnalysisAverageTime} from "@/echarts/option";
import {mapMutations, mapState} from 'vuex';
import {daysX, daysY} from "@/commomUse";
import * as echarts from "echarts";
export default {
  name: "AnalysisAverageTime",
  data(){
    return{
      loading: true,
      basicList:[],
      dataX:[],
      dataY_TERM_BJ:[],
      dataY_TERM_SL:[],
      dataY_AVG_SL_TIME:[],
      dataY_AVG_BJ_TIME:[],
      itemList:[],
      situationList:[],
    }
  },
  computed:{
    ...mapState({
      analysisObject:'analysis',
      reFresh:'analysisRefresh',
    })
  },
  mounted() {
    this.typeShow()
  },
  methods:{
    typeShow(){
      if(this.analysisObject['analysisThirdLevel']==''&& this.analysisObject['analysisForthLevel']==''){
        this.basicShow()
      }else if(this.analysisObject['analysisThirdLevel']!=''&&this.analysisObject['analysisForthLevel']==''){
        this.basicShow()
      }else if(this.analysisObject['analysisForthLevel']!=''&&this.analysisObject['analysisFifthLevel']==''){
        this.itemShow();
      }else if(this.analysisObject['analysisFifthLevel']!=''){
        this.situationShow();
      }
    },
    basicShow(){
      this.loading=true;
      this.$request({
        url:'/YWTBApi/queryAverageTimeTrend',
        method:'post',
        data:{
          'TYPE':this.analysisObject['analysisThirdLevel'],
          "DATA_TYPE":this.analysisObject['analysisFirstLevel'],
          "ORGANIZATION":this.analysisObject['analysisSecondLevel'],
        }
      }).then(response => {
        let dataArr = response.data.msg[0].Rows;
        this.basicList = dataArr;
        this.dataX = daysX(30);
        this.dataY_TERM_BJ = daysY(30);
        this.dataY_TERM_SL = daysY(30);
        this.dataY_AVG_SL_TIME = daysY(30);
        this.dataY_AVG_BJ_TIME = daysY(30);
        for(let i=0;i<this.basicList.length;i++){
          for(let j=0;j<this.dataX.length;j++){
            if(this.dataX[j] ==dataArr[i].INSERT_TIME){
              this.dataY_TERM_BJ[j]=dataArr[i].TERM_BJ!=undefined?dataArr[i].TERM_BJ:0;
              this.dataY_TERM_SL[j]=dataArr[i].TERM_SL!=undefined?dataArr[i].TERM_SL:0;
              this.dataY_AVG_SL_TIME[j]=dataArr[i].AVG_SL_TIME!=undefined?dataArr[i].AVG_SL_TIME:0;
              this.dataY_AVG_BJ_TIME[j]=dataArr[i].AVG_BJ_TIME!=undefined?dataArr[i].AVG_BJ_TIME:0;
            }
          }
        }
        this.$nextTick(() => {
          this.loading=false;
          let ele = this.$refs.echarts
          setAnalysisAverageTime(ele,this.dataX,this.dataY_TERM_BJ,this.dataY_TERM_SL,this.dataY_AVG_SL_TIME,this.dataY_AVG_BJ_TIME)
          echarts.init(ele).on('click',(params)=> {
            console.log(params.seriesName)

            this.$router.push('/origion/handleSituation');
            this.handleSituationRefresh(false);
            this.$nextTick(() => {
              let index = this.getHandleSituationCode(params.seriesName);
              //this.handleSituationThirdLevel(index);
              this.handleSituationSingleChange([
                {
                  name:'handleSituationThirdLevel',
                  value:index
                },
              ])
            })
          })
        })
      })
    },
    getHandleSituationCode(name){
      console.log(name)
      if(name =='承诺受理'||name =='实际受理'){
        return '3'
      }else{
        return '5'
      }
    },
    itemShow(){
      this.loading=true;
      this.$request({
        url:'/YWTBApi/queryAverageTimeTrend',
        method:'post',
        data:{
          'TYPE':this.analysisObject['analysisThirdLevel'],
          "DATA_TYPE":this.analysisObject['analysisFirstLevel'],
          "ORGANIZATION":this.analysisObject['analysisSecondLevel'],
          "MATTER_CODE":this.analysisObject['analysisForthLevel'],
        }
      }).then(response => {
        let dataArr = response.data.msg[0].Rows;
        this.basicList = dataArr;
        this.dataX = daysX(30);
        this.dataY_TERM_BJ = daysY(30);
        this.dataY_TERM_SL = daysY(30);
        this.dataY_AVG_SL_TIME = daysY(30);
        this.dataY_AVG_BJ_TIME = daysY(30);
        for(let i=0;i<this.basicList.length;i++){
          for(let j=0;j<this.dataX.length;j++){
            if(this.dataX[j] ==dataArr[i].INSERT_TIME){
              this.dataY_TERM_BJ[j]=dataArr[i].TERM_BJ!=undefined?dataArr[i].TERM_BJ:0;
              this.dataY_TERM_SL[j]=dataArr[i].TERM_SL!=undefined?dataArr[i].TERM_SL:0;
              this.dataY_AVG_SL_TIME[j]=dataArr[i].AVG_SL_TIME!=undefined?dataArr[i].AVG_SL_TIME:0;
              this.dataY_AVG_BJ_TIME[j]=dataArr[i].AVG_BJ_TIME!=undefined?dataArr[i].AVG_BJ_TIME:0;
            }
          }
        }
        this.$nextTick(() => {
          this.loading=false;
          let ele = this.$refs.echarts
          setAnalysisAverageTime(ele,this.dataX,this.dataY_TERM_BJ,this.dataY_TERM_SL,this.dataY_AVG_SL_TIME,this.dataY_AVG_BJ_TIME)
          echarts.init(ele).on('click',(params)=> {
            console.log(params.seriesName)

            this.$router.push('/origion/handleSituation');
            this.handleSituationRefresh(false);
            this.$nextTick(() => {
              let index = this.getHandleSituationCode(params.seriesName);
             // this.handleSituationThirdLevel(index);
              this.handleSituationSingleChange([
                {
                  name:'handleSituationThirdLevel',
                  value:index
                },
              ])
            })
          })
        })
      })
    },
    situationShow(){
      this.loading=true;
      this.$request({
        url:'/YWTBApi/queryAverageTimeTrend',
        method:'post',
        data:{
          'TYPE':this.analysisObject['analysisThirdLevel'],
          "DATA_TYPE":this.analysisObject['analysisFirstLevel'],
          "ORGANIZATION":this.analysisObject['analysisSecondLevel'],
          "SITUATION_CODE":this.analysisObject['analysisFifthLevel'],
        }
      }).then(response => {
        let dataArr = response.data.msg[0].Rows;
        this.basicList = dataArr;
        this.dataX = daysX(30);
        this.dataY_TERM_BJ = daysY(30);
        this.dataY_TERM_SL = daysY(30);
        this.dataY_AVG_SL_TIME = daysY(30);
        this.dataY_AVG_BJ_TIME = daysY(30);
        for(let i=0;i<this.basicList.length;i++){
          for(let j=0;j<this.dataX.length;j++){
            if(this.dataX[j] ==dataArr[i].INSERT_TIME){
              this.dataY_TERM_BJ[j]=dataArr[i].TERM_BJ!=undefined?dataArr[i].TERM_BJ:0;
              this.dataY_TERM_SL[j]=dataArr[i].TERM_SL!=undefined?dataArr[i].TERM_SL:0;
              this.dataY_AVG_SL_TIME[j]=dataArr[i].AVG_SL_TIME!=undefined?dataArr[i].AVG_SL_TIME:0;
              this.dataY_AVG_BJ_TIME[j]=dataArr[i].AVG_BJ_TIME!=undefined?dataArr[i].AVG_BJ_TIME:0;
            }
          }
        }
        this.$nextTick(() => {
          this.loading=false;
          let ele = this.$refs.echarts
          setAnalysisAverageTime(ele,this.dataX,this.dataY_TERM_BJ,this.dataY_TERM_SL,this.dataY_AVG_SL_TIME,this.dataY_AVG_BJ_TIME)
          echarts.init(ele).on('click',(params)=> {
            console.log(params.seriesName)

            this.$router.push('/origion/handleSituation');
            this.handleSituationRefresh(false);
            this.$nextTick(() => {
              let index = this.getHandleSituationCode(params.seriesName);
             // this.handleSituationThirdLevel(index);
              this.handleSituationSingleChange([
                {
                  name:'handleSituationThirdLevel',
                  value:index
                },
              ])
            })
          })
        })
      })
    },
    ...mapMutations(['analysis','analysisRefresh','analysisSingleChange','handleSituationRefresh','handleSituation','handleSituationSingleChange'])
  },
  watch: {
    analysisObject(){
      this.typeShow()
    },
  }
}
</script>

<style scoped lang="scss">
#analysis-average-time{
  .black-title{
    height: 32px;
    display: flex;
    color: #fff;
    font-size: 20px;
    font-weight: bold;
    justify-content: center;
    align-items: center;
  }
}

</style>
