<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>80</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";
const SeriesData = {
  type: "level_1",
  rate: [
    {
      value: 15.63,
    },
    {
      value: 7.42,
    },
    {
      value: 1.23,
    },
    {
      value: 2.65,
    },
  ],
};
const xAxisValue = [
  "2018年",
  "2019年",
  "2020年",
  "2021年",
];

/**
 * 全省军民协同创新平台情况——折线图
 */
export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      value: 1,
      options: [
        { label: "得分情况", value: 1 },
        { label: "军转民收入及增长率", value: 2 },
        { label: "规模以上企业收入及增长率", value: 3 },
        { label: "国防科工产值", value: 4 },
      ],
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  computed: {
    optionBar() {
      const seriesLine = {
        type: "line",
        itemStyle: {
          color: "#4198ff",
        },
        emphasis: {
          focus: "series",
        },
        label: {
          show: true,
          position: "top",
        },
        areaStyle: {
          opacity: 0.8,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: "#4198ff",
            },
            {
              offset: 1,
              color: "#fff",
            },
          ]),
        },

        data: SeriesData.rate,
      };

      return {
        tooltip: {
          trigger: "axis",
          className: "science-echart",
          
          formatter: (params) => {
            let html = `<span class="name">${params[0].axisValue}</span>`;

            html += `<div class="science-echart ">
                <span class=" title color_1">项目投资额</span>
                <br />
                <span class="text text-color_1">${params[0].data.value}</span>万元
               </div>`;

            return html;
          },
        },
        legend: {},
        grid: {
          top: "5%",
          left: "0%",
          right: "5%",
          bottom: "3%",
          containLabel: true,
        },
        yAxis: {
          type: "value",
          name: "万元",
        },
        xAxis: {
          type: "category",
          data: xAxisValue,
        },
        series: [seriesLine],
      };
    },
  },
  methods: {
    initEcharts() {
      const dom = document.getElementById("TargetBar");
      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 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% - 130px);
    box-sizing: border-box;
    margin-top: 10px;
  }
}
</style>
