<template>
  <div class="synergy-innovation">
    <MapTitle text="军民协同创新总览" />
    <div class="describes">
      <div class="text">各市军民协同创新指标情况</div>
    </div>
    <!-- <el-row>
      <el-button>2019年</el-button>
      <el-button>2020年</el-button>
      <el-button type="primary">2021年上半年</el-button>
    </el-row>-->

    <div id="synergyInnovation" class="line"></div>
  </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 SeriesData = [19, 13.5, 6.5, 12.5, 15.5, 14, 6.5, 10.5, 8, 4, 6];
const xAxisValue = [
  "杭州",
  "宁波",
  "温州",
  "湖州",
  "嘉兴",
  "绍兴",
  "金华",
  "衢州",
  "舟山",
  "台州",
  "丽水",
];

/**
 * 军民协同创新总览
 */
export default defineComponent({
  props: {},
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  watch: {
    seriesData() {
      this.mapEcharts.showLoading();
      this.mapEcharts.setOption(this.optionBar);
      this.mapEcharts.hideLoading();
    },
  },
  computed: {
    ...mapState({
      curDataType: (state) => state.curDataType,
    }),
    seriesData() {
      return Mock[this.curDataType];
    },
    optionBar() {
      return {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          textStyle: {},
          className: "target-bar-tooltip",
          formatter:
            "<span class='title'>{b0}市</span>: <br /> <span class='bar-text'>{c0}</span> 分",
        },
        legend: {},
        grid: {
          left: "-5%",
          right: "5%",
          bottom: "5%",
          containLabel: true,
        },
        yAxis: {
          type: "value",
          show: false,
        },
        xAxis: {
          type: "category",
          data: xAxisValue,
        },
        series: [
          {
            type: "bar",
            itemStyle: {
              color: "#4198ff",
            },
            label: {
              show: true,
              position: "top",
            },
            barWidth: 20,
            data: this.seriesData,
          },
        ],
      };
    },
  },
  methods: {
    yearHandle(index: number) {
      this.curYearIndex = index;
    },
    initEcharts() {
      const dom = document.getElementById("synergyInnovation");
      const mapEcharts = echarts.init(dom);
      mapEcharts.setOption(this.optionBar);
      this.mapEcharts = mapEcharts;
    },
  },
  unmounted() {
    if (!this.mapEcharts) {
      return;
    }
    this.mapEcharts.dispose();
    this.mapEcharts = null;
  },
});
</script>
<style>
.target-bar-tooltip .title {
  color: #333;
  font-weight: bold;
}
.target-bar-tooltip .bar-text {
  padding-left: 10px;
  color: #4198ff;
}
</style>

<style lang="scss" scoped>
.synergy-innovation {
  .line {
    flex: 1;
    height: 375px;
    box-sizing: border-box;
  }
  .btn {
    width: 300px;
    height: 153px;
    border: 1px solid;
  }
  .describes {
    margin: 0 10px 5px 0;
    box-sizing: border-box;

    .text {
      color: #4198ff;
      margin: 10px 0;
      font-size: 16px;
    }
  }
}
</style>
