<template>
  <div id="ar_summary_bar"/>
</template>

<script>
import * as echarts from "echarts";
import {convert_num_unit} from "../../../utils/numUtil";

export default {
  name: "ArSummaryBar",
  data() {
    return {
      arSummaryBar: null,
      barChart: {
        tooltip: {
          trigger: 'axis',
          formatter: (params) => params[0].name + "<br>" + params[0].marker + "\t\t" + this.convert_num_unit(params[0]),
        },
        textStyle: {
          color: "#FFFFFF",
          fontSize: "12"
        },
        grid: {
          containLabel: true,
          top: "10%",
          bottom: '0'
        },
        xAxis: {
          data: ['未结算未开票', '已结算未开票', '已开票未收款', '应收款', '已开票已收款'],
          axisLabel: {
            color: "#FFFFFF",
            fontSize: "12",
          },
          axisTick: {
            show: false
          }
        },
        yAxis: {
          type: "value",
          splitLine: {
            lineStyle: {
              color: "#1E2C58"
            }
          },
          axisLabel: {
            show: false,
            color: "#FFFFFFAA",
            fontSize: "16"
          }
        },
        series: {
          type: 'bar',
          data: [0, 0, 0, 0, 0],
          barWidth: "40%",
          showBackground: true,
          backgroundStyle: {
            color: 'rgba(255, 255, 255, 0.1)'
          },
          itemStyle: {
            borderRadius: 10,
          },
          color: {
            type: 'linear',
            x: 0, y: 0, x2: 0, y2: 1,
            colorStops: [
              {offset: 0, color: '#00CCD2'},
              {offset: 1, color: '#00A2FF'}
            ]
          },
          label: {
            show: true,
            position: 'top',
            color: "#FFFFFF",
            formatter: this.convert_num_unit
          },
        }
      },
    }
  },
  methods: {
    convert_num_unit,
    drawArSummaryBar(seriesData) {
      if (!this.arSummaryBar) {
        this.arSummaryBar = echarts.init(document.getElementById('ar_summary_bar'))
      }
      this.barChart.series.data = seriesData
      this.arSummaryBar.setOption(this.barChart);
    },
    resizeChart() {
      if (this.arSummaryBar) {
        this.arSummaryBar.resize();
      }
    }
  },
  mounted() {
    window.addEventListener('resize', this.resizeChart);
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.resizeChart);
  }

}

</script>
