<template >
  <div style="height: 100%; width: 100%" >
    <div id="main1"></div>
  </div>
</template>
<script>
import * as echarts from "echarts";
import { workStatistics } from "@/api/yingji/keyEnterprise.js";

export default {
  data() {
    return {
      load1: true,
      arr1: [],
      arr2: [],
      beforeParams: {
        pageSize: 10,
        pageNum: 1,
      },
    };
  },
  mounted() {
    this.$nextTick(() => {
      // this.getData();
      this.initChart()
    });
  },
  methods: {
    getData() {
      this.load1 = true;
      workStatistics(this.beforeParams).then((res) => {
        res.data.list.forEach((value, index) => {
          this.arr1.push(value.deptName);
          this.arr2.push(value.keyCompleted + value.nonKeyCompleted);
        });
        this.initChart();
        this.load1 = false;
      });
    },
    initChart() {
      var chartDom = document.getElementById("main1");
      var myChart = echarts.init(chartDom);
      // 渲染
      var option = {
        title: {
          show: true,
          text: "各区域完成计划",
          textStyle: {
            color: "#3D434D",
            fontSize: 16,
          },
          left: 34,
          top: 20,
        },
        tooltip: {
          //   show: false,
          trigger: "axis",
          textStyle: {
            align: "left",
          },
          axisPointer: {
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        grid: {
          left: "3%",
          right: "3%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "value",
            splitLine: { show: false }, // 删除坐标轴分割线
            axisLabel: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
          },
          {
            type: "value",
            show: false,
          },
        ],
        yAxis: [
          {
            type: "category",
            data: [
              "高新区",
              "工业园区",
              "相城区",
              "姑苏区",
              "吴中区",
              "吴江区",
              "昆山市",
              "太仓市",
              "常熟市",
              "张家港市",
              "苏州",
            ],
            // data: this.arr1,
            axisLabel: {
              // 超出指定长度显示省略号
              formatter: function (value) {
                var val = "";
                if (value.length > 5) {
                  val = value.substr(0, 5) + "...";
                  return val;
                } else {
                  return value;
                }
              },
              fontSize: "13px",
              fontFamily: "Alibaba PuHuiTi",
              fontWeight: 500,
              color: "#525966",
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
          },
          {
            type: "category",
            data: [33, 63, 115, 167, 210, 225, 245, 283, 300, 321, 1000],
            // data: this.arr2,
            axisLabel: {
              formatter: function (value, index) {
                return `{a|${value}}{b|家}`;
              },
              rich: {
                a: {
                  color: "#0084FF",
                  align: "right",
                  // width: 32,
                  // width: 20,
                },
                b: {
                  color: "#525966",
                  align: "right",
                },
              },
            },

            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
          },
        ],
        series: [
          {
            type: "bar",
            // name: "数据",
            label: {
              show: false, //是否显示标签
            },
            data: [63, 115, 167, 210, 225, 245, 283, 300, 321, 678, 1000],
            // data: this.arr2,
            barWidth: 12,
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [
                  {
                    offset: 0,
                    color: "#0084FF", // 渐变起始颜色
                  },
                  {
                    offset: 1,
                    color: "#00BAFF", // 渐变结束颜色
                  },
                ],
              },
            },
            emphasis: {
              disabled: true,
            },
            z: 102,
          },
          {
            // name: '背景',
            type: "bar",
            barWidth: 12,
            barGap: "-100%",
            // data: [
            //   1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000,
            // ],
            data: [],
            itemStyle: {
              normal: {
                color: "#EDF0F2",
              },
            },
            emphasis: {
              disabled: true,
            },
            tooltip: {
              show: false,
            },
            z: 101,
          },
        ],
      };
      option && myChart.setOption(option);
    },
  },
};
</script>
<style lang="scss" scoped>
#main1 {
  height: 100%;
  width: 100%;
  border-radius: 10px;
}
</style>