<template>
  <MapTitle text='军民融合"十百千"项目投资金额及进度情况' />
  <div id="InvestmentProgress" class="investment-progress"></div>
</template>
<script lang="ts">
/**
 * 绩效评价情况——柱状图
 */
import { defineComponent } from "vue";
import MapTitle from "@/components/mapTitle/index.vue";
import * as echarts from "echarts";

import Mock from "./mock";
import { mapState } from "vuex";

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

export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  computed: {
    ...mapState({
      curDataType: (state) => state.curDataType,
    }),
    seriesData() {
      return Mock[this.curDataType];
    },
    optionBar() {
      const seriesBarList = this.seriesData.map((item, index) => {
        return {
          name: item.name,
          type: "bar",
          itemStyle: {
            color: "#4198FF",
          },
          barWidth: 12,
          data: item.barValue.map((barItem, barIndex) => {
            return {
              value: barItem,
              label: "投资金额",
            };
          }),
        };
      });

      const seriesLineList = this.seriesData.map((item) => {
        return {
          name: "项目进度",
          type: "line",
          itemStyle: {
            color: "#75ce95",
          },
          lineStyle: {
            type: "dashed",
          },
          yAxisIndex: 1,
          data: item.growthRate.map((value) => {
            return {
              value,
              label: "项目进度",
            };
          }),
        };
      });

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

            html += `<div class="tooltip-progress ">
                <span class=" title color_1">${params[0].data.label}</span>
                <br />
                <span class="text text-color_1">${params[0].data.value}</span>亿元
               </div>
              <div class="tooltip-progress">
                <span class=" title  color_2">${params[1].data.label}</span>
                  <br />
                <span class="text text-color_2">${params[1].data.value}%</span>
            </div>`;

            return html;
          },
        },
        grid: {
          left: "5%",
          right: "2%",
          bottom: "3%",
          containLabel: true,
        },
        legend: {
          right: "2%",
        },
        yAxis: [
          {
            type: "value",
            name: "金额(亿元)",
          },
          {
            type: "value",
            name: "项目进度%",
            min: 0,
            max: 100,
          },
        ],
        xAxis: {
          type: "category",
          data: xAxisValue,
        },
        series: [...seriesBarList, ...seriesLineList],
      };
    },
  },
   watch: {
    seriesData() {
      this.mapEcharts.showLoading();
      this.mapEcharts.setOption(this.optionBar);
      this.mapEcharts.hideLoading();
    },
  },

  methods: {
    initEcharts() {
      const dom = document.getElementById("InvestmentProgress");
      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>
.tooltip-progress:first-of-type {
  margin-bottom: 5px;
}
.tooltip-progress .name {
  margin-bottom: 15px;
  font-size: 14px;
  color: #333;
  font-weight: bold;
}
.tooltip-progress {
  width: 100px;
}

.tooltip-progress .name {
  margin-bottom: 15px;
  font-size: 14px;
  color: #333;
  font-weight: bold;
}
.tooltip-progress .title {
  padding-left: 10px;
  font-weight: 600;
  font-size: 12px;
  color: #666;
  position: relative;
}
.tooltip-progress .title::before {
  position: absolute;
  top: 5px;
  left: 0;
  content: " ";
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 50%;
}
.tooltip-progress .text {
  padding-left: 20px;
  margin-bottom: 20px;
  font-size: 20px;
}
.tooltip-progress .text:last-of-type {
  margin: 0;
}

.tooltip-progress .text-color_1 {
  color: #4198ff;
}
.tooltip-progress .text-color_2 {
  color: #75ce95;
}
.tooltip-progress .color_1::before {
  background: #4198ff;
}
.tooltip-progress .color_2::before {
  background: #75ce95;
}
</style>

<style lang="scss" scoped>
.investment-progress {
  flex: 1;
  height: 245px;
  box-sizing: border-box;
  margin-top: 10px;
}
</style>
