<template>
  <div class="DPcomputer20Box">
    <!-- 各装点车铲比 -->
    <div class="intelligentSchScrView_rightView_title">各装点车铲比</div>
    <div class="intelligentSchScrView_rightView_content">
      <div id="carsProportionView"></div>
    </div>
  </div>
</template>

<script>
import {Tools, HttpReq, CAMap} from '@/assets/js/common.js';
import * as echarts from 'echarts';


export default {
  data() {
    return {
      DPcomputer20BoxTimer: null,
      //各装点车铲比Echarts
      carsAreaDistributionData: {
        name: [],
        values: [],
      },
    }
  },
  mounted() {
    this.loadData();
    this.DPcomputer19BoxTimer = setInterval(() => {
      this.loadData();
    }, 10000)
  },
  methods: {
    loadData() {
      //各装点车铲比Echarts
      HttpReq.truckDispatching.getLargeScreenchechanbi1().then((res) => {
        if (res.code == 200) {
          let name = [];
          let values = [];
          res.data.forEach((item, index) => {
            name.push(item.area);
            values.push(item.ratio);
          })
          this.carsAreaDistributionData.name = name;
          this.carsAreaDistributionData.values = values;
          this.carsProportionEcharts();
        }
      })
    },
    //各装点车铲比Echarts
    carsProportionEcharts() {
      echarts.init(document.getElementById('carsProportionView')).dispose();
      var myChart = echarts.init(document.getElementById('carsProportionView'));
      let xZoom=Math.ceil(4/this.carsAreaDistributionData.name.length*100);
      if(xZoom>100){
        xZoom=100
      }
      var option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        // legend: {
        //   textStyle: {
        //     color: 'white',
        //     fontSize: 16,
        //   }
        // },
        grid: {
          top: '10%',
          left: '1%',
          right: '1%',
          bottom: '5%',
          containLabel: true
        },
        dataZoom: [
          {
            type: 'inside',
            start: 0,
            end: xZoom
          },
          {
            start: 0,
            end: xZoom,
            show: false,
          }
        ],
        xAxis: {
          type: 'category',
          data: this.carsAreaDistributionData.name,
          axisLabel: {
            interval: 0,
            show: true,
            textStyle: {
              color: '#A6F6F9',
              fontSize: 12,
            }
          },
          axisLine: {
            lineStyle: {
              color: '#A6F6F9',
              width: 1
            }
          },
        },
        yAxis: {
          type: 'value',
          minInterval: 1,
          axisLabel: {
            show: true,
            textStyle: {
              color: '#A6F6F9',
              fontSize: 14,
            }
          },
          axisLine: {
            lineStyle: {
              color: '#A6F6F9',
              width: 0
            }
          },
        },
        series: [
          {
            name: '车铲比',
            type: 'bar',
            data: this.carsAreaDistributionData.values,
            barWidth: 35,
            itemStyle: {
              color: '#00FFFF'
            },
          },
        ]
      };
      option && myChart.setOption(option);
    },
  },
  beforeDestroy() {
    if (this.DPcomputer20BoxTimer) {
      clearInterval(this.DPcomputer20BoxTimer);
      this.DPcomputer20BoxTimer = null;
    }
  }
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}

.DPcomputer20Box {
  width: 20vw;
  height: 32vh;
  background-color: rgba(32, 42, 67, 0.95);
  padding: 5px 7px;
  box-sizing: border-box;
  overflow: hidden;
}

.DPcomputer20Box .intelligentSchScrView_rightView_title {
  margin-bottom: 5px;
  width: 100%;
  height: 3.5vh;
  background: no-repeat center center url('~@/assets/images/cutGraph/biaoti1.png');
  background-size: 100% 100%;
  padding-left: 10px;
  box-sizing: border-box;
  font-size: 18px;
  line-height: 3.5vh;
  color: #FAFAFB;
  letter-spacing: 1px;
  text-shadow: 1px 1px 1px #92CBFF;
}

.DPcomputer20Box .intelligentSchScrView_rightView_content {
  width: 100%;
}

.DPcomputer20Box #carsProportionView {
  width: 19vw;
  height: 27.5vh;
}
</style>
