<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 class="item">
          <span>协同创新示范平台</span>
          <div class="value-des">
            <span>66</span>个
          </div>
        </div>-->
      </div>

      <!-- <div class="title">协同创新平台投入研发经费</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年"];
// const cityData = {
//   value: [225, 160, 170],
// };

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

      TargetBar: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  watch: {
    seriesData() {
      this.TargetBar.showLoading();
      this.TargetBar.setOption(this.optionCity);
      this.TargetBar.hideLoading();
    },
  },
  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: "收入规模",
            };
          }),
        };
      });

      // const seriesBar = {
      //   type: "bar",

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

      //   data: cityData.value.map((item) => {
      //     return {
      //       value: item,
      //       label: "收入规模",
      //     };
      //   }),
      // };
      return {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          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: "10%",
          left: "5%",
          right: "2%",
          bottom: "3%",
          containLabel: true,
        },
        yAxis: {
          type: "value",
          name: "数量(个)",
          min: 0,
          max: 250,
        },
        xAxis: {
          type: "category",
          data: xAxisCity,
        },
        series: [...seriesBar],
      };
    },
  },
  methods: {
    initEcharts() {
      this.initCityEcharts();
    },
    initCityEcharts() {
      const dom = document.getElementById("TargetBar");
      const mapEcharts = echarts.init(dom);
      mapEcharts.setOption(this.optionCity);
      this.TargetBar = mapEcharts;
    },
  },
  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;
          }
        }
      }
    }
  }

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