<template>
  <MapTitle :text="echartsTitle" />
  <div class="describes">
    <div class="card-items">
      <div class="item" v-for="(item,index) in cardItems" :key="item.text">
        <span>{{ item.label }}</span>
        <div class="value-des">
          <span>{{ item.value || "--" }}</span
          >{{index === 0?"亿元":"%"}}
        </div>
      </div>
    </div>

    <div class="text">{{ echartsDesText }}</div>
  </div>

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

const seriesData = [
  {
    // name: "国防要求建设项目",
    type: "level_1",
    value: [5204.49, 6029.77, 7633.65, 3545.5],
  },
];

const xAxisValue = ["2018年", "2019年", "2020年", "2021上半年"];

/**
 * 全省军民协同创新平台情况/国防科技工业产值规模分布 -- 折线图
 */
export default defineComponent({
  props: {
    echartsTitle: {
      type: String,
      required: true,
    },
    echartsDesText: {
      type: String,
      required: true,
    },
    cardItems: {
      type: Array,
      required: true,
      dafault: () => [],
    },
    echartsData: {
      type: Array,
      // required: true,
      dafault: () => [],
    },
    echartsAxisValue: {
      type: Array,
      // required: true,
      dafault: () => [],
    },
    echartsId: {
      type: String,
      required: true,
    },
  },
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  computed: {
    optionBar() {
      const seriesLine = seriesData.map((item) => {
        return {
          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: item.value,
        };
      });

      return {
        tooltip: {
          trigger: "axis",
          className: "extend-tooltip",
          formatter: "<span class='title'>{b0}</span>: <br /> <span class='bar-text'>{c0}</span> 亿元",
        },
        legend: {},
        grid: {
          top: "5%",
          left: "0%",
          right: "5%",
          bottom: "9%",
          containLabel: true,
        },
        yAxis: {
          type: "value",
          show: false,
        },
        xAxis: {
          type: "category",
          data: xAxisValue,
        },
        series: seriesLine,
      };
    },
  },
  methods: {
    initEcharts() {
      const dom = document.getElementById(this.echartsId);
      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>
.extend-tooltip .title {
  color: #333;
  font-weight: bold;
}
.extend-tooltip .bar-text {
  padding-left: 10px;
  color: #4198ff;
}
</style>
<style lang="scss" scoped>
.incom-echarts-line {
  flex: 1;
  height: calc(100% - 190px);
  box-sizing: border-box;
}
.describes {
  margin: 0 10px;
  height: 150px;
  box-sizing: border-box;
  .card-items {
    margin: 15px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    .item {
    flex: 1;

      padding: 10px 15px;
      margin-right: 15px;
      background: #f8f9fb;
      border-radius: 5px;
      font-size: 14px;
      color: #333;

      &:last-of-type {
        margin-right: 0;
      }
      .value-des {
        margin-top: 10px;
        font-size: 12px;
        color: #999;
        span {
          font-size: 20px;
          margin-right: 5px;
          color: #4198ff;
        }
      }
    }
  }
  .text {
    color: #4198ff;
    margin-top: 10px;
    font-size: 14px;
  }
}
</style>
