<template>
  <div class="synergy-innovation">
    <MapTitle text="五大体系建设总览" />
    <div class="describes">
      <div class="text">各市五大体系建设指标情况</div>
      <!-- <el-row class="" justify="space-between">
        <div class="years" align="middle">
          <span
            v-for="(item, index) in years"
            :key="item"
            :class="{
              active: index === curYearIndex,
            }"
            @click="yearHandle(index)"
            >{{ item }}年</span
          >
        </div>
      </el-row> -->
    </div>

    <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";

const SeriesData = [250, 170, 190, 145, 128, 194, 160, 210, 150, 300, 160];
const xAxisValue = [
  "杭州",
  "宁波",
  "温州",
  "湖州",
  "嘉兴",
  "绍兴",
  "金华",
  "衢州",
  "舟山",
  "台州",
  "丽水",
];

/**
 * 五大体系建设总览
 */
export default defineComponent({
  props: {},
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      years: [2019, 2020, "2021上半"],
      curYearIndex: 2,
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  computed: {
    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: "3%",
          containLabel: true,
        },
        yAxis: {
          type: "value",
          show: false,
          max:300
        },
        xAxis: {
          type: "category",
          data: xAxisValue,
        },
        series: [
          {
            type: "bar",
            itemStyle: {
              color: "#4198ff",
            },
            label: {
              show: true,
              position: "top",
              formatter:"{c} 分"
            },
            barWidth: 20,
            data: 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: 360px;
    box-sizing: border-box;
  }
  .describes {
    margin: 0 10px 5px 0;
    box-sizing: border-box;
    .years {
      margin-bottom: 15px;
      display: flex;
      align-items: center;
      overflow: hidden;
      span {
        margin-right: 10px;
        padding: 0 12px;
        height: 32px;
        line-height: 32px;
        font-size: 12px;
        color: #333;
        background: #f4f6f9;
        border-radius: 5px;
      }
      .active {
        background-color: #4198ff;
        color: #fff;
      }
    }
    .text {
      color: #4198ff;
      margin: 10px 0;
      font-size: 16px;
    }
  }
}
</style>
