<template>
  <MapTitle text="资源开放共享创新总览" />

  <div class="echarts-search">
    <div class="title">各市资源开放共享创新指标情况</div>
  </div>

  <div id="shareTargetBar" class="target-bar"></div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import MapTitle from "@/components/mapTitle/index.vue";
import * as echarts from "echarts";
import Mock from "./mock";
import { mapState } from "vuex";

const xAxisValue = [
  "杭州",
  "宁波",
  "温州",
  "湖州",
  "嘉兴",
  "绍兴",
  "金华",
  "衢州",
  "舟山",
  "台州",
  "丽水",
];
let MAP_ECHARTS = null;
/**
 * 产业融合发展总览——柱状图
 */
export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      value: 1,
      options: [
        { label: "得分情况", value: 1 },
        { label: "军转民收入及增长率", value: 2 },
        { label: "规模以上企业收入及增长率", value: 3 },
        { label: "国防科工产值", value: 4 },
      ],

      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  watch: {
    seriesData() {
      MAP_ECHARTS.showLoading();
      MAP_ECHARTS.setOption(this.optionBar, true);
      MAP_ECHARTS.hideLoading();
    },
  },
  computed: {
    ...mapState({
      curDataType: (state) => state.curDataType,
    }),
    seriesData() {
      return Mock[this.curDataType];
    },
    optionBar() {
      return {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          textStyle: {},
          className: "resource-share-target-tooltip",
          formatter:
            "<span class='title'>{b0}</span>: <br /> <span class='bar-text'>{c0}</span> 分",
        },
        legend: {},
        grid: {
          top: 0,
          left: "-5%",
          right: "0%",
          bottom: "3%",
          containLabel: true,
        },
        yAxis: {
          type: "value",
          show: false,
          max: 20,
        },
        xAxis: {
          type: "category",
          data: xAxisValue,
        },
        series: [
          {
            type: "bar",
            itemStyle: {
              color: "#4198ff",
            },
            barWidth: 20,
            label: {
              show: true,
              position: "top",
              // formatter: "{c}亿元"
            },
            data: this.seriesData,
          },
        ],
      };
    },
  },
  methods: {
    initEcharts() {
      const dom = document.getElementById("shareTargetBar");
      MAP_ECHARTS = echarts.init(dom);
      MAP_ECHARTS.setOption(this.optionBar);
      this.mapEcharts = MAP_ECHARTS;
    },
  },
  unmounted() {
    if (!this.mapEcharts) {
      return;
    }
    this.mapEcharts.dispose();
    this.mapEcharts = null;
  },
});
</script>
<style>
.resource-share-target-tooltip {
  width: 60px;
}
.resource-share-target-tooltip .title {
  padding-left: 10px;
  color: #333;
  font-weight: bold;
  position: relative;
}
.resource-share-target-tooltip .title::before {
  position: absolute;
  top: 8px;
  left: 0;
  content: " ";
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 50%;
  background: #4198ff;
}
.resource-share-target-tooltip .bar-text {
  padding-left: 10px;
  color: #4198ff;
  position: relative;
}
.resource-share-target-tooltip .bar-text {
  padding-left: 10px;
  color: #4198ff;
}
</style>
<style lang="scss" scoped>
.echarts-search {
  padding-left: 10px;
  .title {
    color: #4198ff;
    margin: 10px 0;
    font-size: 16px;
  }
}

.target-bar {
  flex: 1;
  min-height: 250px;
  height: calc(100% - 50px);
  box-sizing: border-box;
  margin-top: 10px;
}
</style>
