<template>
  <MapTitle text="产业融合发展总览" />

  <div class="echarts-search">
    <div class="title">各市产业融合创新指标情况</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-select v-model="value" size="small" placeholder="请选择">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select> -->
    </el-row>
  </div>

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

const xAxisValue = [
  "杭州",
  "宁波",
  "温州",
  "湖州",
  "嘉兴",
  "绍兴",
  "金华",
  "衢州",
  "舟山",
  "台州",
  "丽水",
];

/**
 * 产业融合发展总览——柱状图
 */
export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      value: 1,
      options: [
        { label: "得分情况", value: 1 },
        { label: "军转民收入及增长率", value: 2 },
        { label: "规模以上企业收入及增长率", value: 3 },
        { label: "国防科工产值", value: 4 },
      ],
      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: {
          top: 0,
          left: "-5%",
          right: "5%",
          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: [14.5, 9, 6, 10, 13, 14, 13.5, 8, 6, 12.5, 15],
          },
        ],
      };
    },
  },
  methods: {
    initEcharts() {
      const dom = document.getElementById("TargetBar");
      const mapEcharts = echarts.init(dom);
      mapEcharts.setOption(this.optionBar);
      this.mapEcharts = mapEcharts;
    },
    yearHandle(index: number) {
      this.curYearIndex = index;
    },
  },
  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>
.echarts-search {
  padding-left: 10px;
  .title {
    color: #4198ff;
    margin: 10px 0;
    font-size: 14px;
  }
  .years {
    display: flex;
    align-items: center;
    background: #f4f6f9;
    border-radius: 5px;
    overflow: hidden;
    span {
      padding: 0 12px;
      height: 32px;
      line-height: 32px;
      font-size: 12px;
      color: #333;
    }
    .active {
      background-color: #4198ff;
      color: #fff;
    }
  }
}

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