<template>
  <div class="synergy-innovation-platform">
    <MapTitle text="全省军民协同创新平台情况" />

    <div class="echarts-search">
      <!-- <div class="card-items">
        <div class="item">
          <span>协同创新平台</span>
          <div class="value-des">
            <span>{{ count || "--" }}</span
            >个
          </div>
        </div>
      </div> -->
      <div class="title2X">历年军民协同创新平台情况</div>
    </div>

    <div id="TargetBar" class="target-bar"></div>
  </div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import MapTitle from "@/components/mapTitle/index.vue";
import * as echarts from "echarts";
import { Aim } from "@element-plus/icons";
import Mock from "./mock";
import { mapState } from "vuex";
const xAxisCity = ["2018年", "2019年", "2020年"];

let MAP_ECHARTS = null;
/**
 * 全省军民协同创新平台情况——折线图
 */
export default defineComponent({
  components: {
    MapTitle,
    Aim,
  },
  setup() {},
  data() {
    return {
      countryEcharts: null,

      TargetBar: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  watch: {
    seriesData() {
      MAP_ECHARTS.setOption(this.optionCity, true);
    },
  },
  computed: {
    ...mapState({
      curDataType: (state) => state.curDataType,
    }),
    count() {
      return Mock[this.curDataType].count;
    },
    seriesData() {
      return Mock[this.curDataType].cityData;
    },
    optionCity() {
      const seriesBar = this.seriesData.map((item) => {
        return {
          type: "bar",

          itemStyle: {
            color: "#4198ff",
          },
          barWidth: 20,

          data: item.value.map((item) => {
            return {
              value: item,
              label: "收入规模",
            };
          }),
        };
      });

      return {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
            shadowStyle: {
              color: "#1881e120",
            },
          },
          formatter: (params) => {
            let html = ``;

            html += `<div class="munition-echart ">
                <span class=" title color_1">${params[0].axisValue}</span>
                <br />
                <span class="text text-color_1">${params[0].data.value}</span>个
               </div>
             `;

            return html;
          },
        },
        legend: {},
        grid: {
          top: "15%",
          left: "5%",
          right: "2%",
          bottom: "3%",
          containLabel: true,
        },
        yAxis: {
          type: "value",
          name: "数量(个)",
          min: 0,
          max: 250,
          nameTextStyle: {
            color: "#fff",
          },
          axisLabel: {
            show: true,
            color: "#fff",
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#125ba3",
              type: "dotted",
            },
          },
        },
        xAxis: {
          type: "category",
          data: xAxisCity,
          axisLabel: {
            show: true,
            color: "#ffffff",
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#125ba3",
            },
          },
          axisTick: {
            show: false,
          },
        },
        series: [...seriesBar],
      };
    },
  },
  methods: {
    initEcharts() {
      this.initCityEcharts();
    },
    initCityEcharts() {
      const dom = document.getElementById("TargetBar");
      MAP_ECHARTS = echarts.init(dom);
      MAP_ECHARTS.setOption(this.optionCity);
      this.TargetBar = MAP_ECHARTS;
    },
  },
  unmounted() {
    if (this.TargetBar) {
      this.TargetBar.dispose();
      this.TargetBar = null;
    }
  },
});
</script>

<style lang="scss" scoped>
.synergy-innovation-platform {
  height: 100%;
  .echarts-search {
    padding-left: 10px;
    .title {
      color: #4198ff;
      margin: 12px 0;
      font-size: 16px;
    }
    .card-items {
      margin: 15px 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      .item {
        flex: 1;
        padding: 8px 15px;
        margin-right: 15px;
        background: #f8f9fb;
        border-radius: 5px;
        font-size: 14px;
        color: #333;
        display: flex;
        align-items: center;
        justify-content: space-between;
        &:last-of-type {
          margin-right: 0;
        }
        .value-des {
          font-size: 12px;
          color: #999;
          display: flex;
          align-items: center;
          span {
            font-size: 20px;
            margin-right: 5px;
            color: #4198ff;
          }
        }
      }
    }
  }
  .title2X {
    margin-top: 15px;
    font-size: 16px;
    color: #fff;
  }

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