<template>
  <moduleEnclosure title="近一月维修完工统计">
    <div id="main3" style="width: 100%; height: 100%"></div>
  </moduleEnclosure>
</template>

<script>
import moduleEnclosure from '@/components/moduleEnclosure.vue';
import * as echarts from 'echarts';
import { getQuery10 } from '@/api/bigView.js';
import { csize } from '@/utils/const.js';
let myChart4;
export default {
  components: {
    moduleEnclosure,
  },
  data() {
    return {
      myChart2: null,
    };
  },
  mounted() {
    this.timeId = getQuery10((res) => {
      this.init_myChart2(res.data);
    }, 40000);
  },
  beforeUnmount() {
    this.timeId();
  },
  methods: {
    init_myChart2(value) {
      var times = value.map((item) => {
        var str1 = item.ddate.split(' ')[0];
        return str1.slice(5);
      });
      var data1 = value.map((item) => {
        return item.completeOrder || 0;
      });
      var data2 = value.map((item) => {
        return item.totalOrder || 0;
      });
      if (myChart4) {
        myChart4.dispose();
      }
      myChart4 = new echarts.init(document.getElementById('main3'));
      myChart4.setOption({
        tooltip: {
          trigger: 'axis',
          formatter: function (params) {
            var res = '';
            for (var i = 0, l = params.length; i < l; i++) {
              res +=
                '' + params[i].seriesName + ' : ' + params[i].value + '<br>';
            }
            return `<div style="color:#fff;">${res}</div>`;
          },
          transitionDuration: 0,
          backgroundColor: '#092a66',
          borderColor: '#0462b5',
          borderRadius: 8,
          borderWidth: 2,
          padding: [5, 10],
          axisPointer: {
            type: 'line',
            lineStyle: {
              type: 'dashed',
              color: '#8AB1DC',
            },
          },
        },
        legend: {
          icon: 'circle',
          itemWidth: 8,
          itemHeight: 8,
          itemGap: 10,
          top: '16',
          right: '10',
          data: ['维修新增', '维修完成'],
          textStyle: {
            fontSize: csize(16),
            color: '#8AB1DC',
          },
        },
        grid: {
          x: csize(65),
          y: csize(50),
          x2: csize(30),
          y2: csize(30),
          containLabel: false,
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            axisLabel: {
              interval: Math.floor(times.length / 10),
              showMinLabel: true, //是否显示最小 tick 的 label
              showMaxLabel: true, //是否显示最大 tick 的 label
              fontSize: csize(12),
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: '#8AB1DC',
              },
            },
            axisTick: {
              show: false,
            },
            data: times,
          },
        ],
        yAxis: [
          {
            type: 'value',
            name: '单',
            nameTextStyle: {
              fontSize: csize(16),
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: '#8AB1DC',
              },
            },
            axisLabel: {
              margin: 10,
              textStyle: {
                fontSize: csize(12),
              },
            },
            splitLine: {
              lineStyle: {
                color: '#364D95',
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [
          {
            name: '维修新增',
            type: 'line',
            smooth: true,
            showSymbol: false,
            lineStyle: {
              normal: {
                width: 2,
              },
            },
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: 'rgba(137, 189, 27, 0.3)',
                    },
                    {
                      offset: 0.8,
                      color: 'rgba(137, 189, 27, 0)',
                    },
                  ],
                  false
                ),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10,
              },
            },
            itemStyle: {
              normal: {
                color: '#F34799',
              },
            },
            data: data1,
          },
          {
            name: '维修完成',
            type: 'line',
            smooth: true,
            showSymbol: false,
            lineStyle: {
              normal: {
                width: 2,
              },
            },
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: 'rgba(0, 136, 212, 0.3)',
                    },
                    {
                      offset: 0.8,
                      color: 'rgba(0, 136, 212, 0)',
                    },
                  ],
                  false
                ),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10,
              },
            },
            itemStyle: {
              normal: {
                color: '#38A0D6',
              },
            },
            data: data2,
          },
        ],
      });
    },
  },
};
</script>

<style></style>
