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

<script>
import * as echarts from "echarts";

export default {
  name: "ArCompanyBar",
  data() {
    return {
      barChart: {
        title: {
          show: true,
          text: "已开票未收款（结算单位）",
          left: "center",
          textStyle: {color: "white"}
        },
        textStyle: {
          color: "#FFFFFF",
          fontSize: "12"
        },
        grid: {
          containLabel: true,
          top: "10%",
          bottom: '10%'
        },
        xAxis: {
          data: ['XXXXXX股份有限公司', 'XXXXXX股份有限公司', 'XXXXXX股份有限公司', 'XXXXXX股份有限公司', 'XXXXXX股份有限公司', 'XXXXXX股份有限公司', 'XXXXXX股份有限公司', 'XXXXXX股份有限公司', 'XXXXXX股份有限公司', 'XXXXXX股份有限公司'],
          axisLabel: {
            color: "#FFFFFF",
            fontSize: "12",
            interval: 0,
            rotate: 0
          },
          axisTick: {
            show: false
          }
        },
        yAxis: [{
          type: "value",
          splitLine: {
            lineStyle: {
              color: "#1E2C58"
            }
          },
          axisLabel: {
            show: false,
            color: "#FFFFFFAA",
            fontSize: "16"
          }
        }],
        series: [
          {
            type: 'bar',
            data: [25002, 57873, 11987, 71168, 41098, 25002, 57873, 11987, 71168, 41098],
            barWidth: "40%",
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(255, 255, 255, 0.1)'
            },
            itemStyle: {
              barBorderRadius: 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",
            },
          }
        ]
      },
      myChart: null
    }
  },
  methods: {
    resizeChart() {
      if (this.myChart) {
        this.myChart.resize();
      }
    },
  },
  mounted() {
    // 设置500毫秒延迟执行，解决组件没有渲染完成就开始绘制图表的问题
    setTimeout(() => {
      let arCompanyBar = document.getElementById('ar_company_bar')
      this.myChart = echarts.init(arCompanyBar)
      this.myChart.setOption(this.barChart)
      let that = this
      this.myChart.on('click', function(params) {
        that.$router.push({path: '/ar_bar/company', query: {name: params.name}})
      });
      // 监听窗口大小变化，重绘图表
      window.addEventListener('resize', this.resizeChart);
    }, 500)
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.resizeChart);
  }

}

</script>
