<template>
  <MapTitle
    text="2021年上半年全省军民融合创新示范绩效评价情况"
    :detailsHandle="detailsHandle"
  />
  <div id="performanceBar" class="performance-bar"></div>
</template>
<script lang="ts">
/**
 * 绩效评价情况——柱状图
 */
import { defineComponent } from "vue";
import MapTitle from "@/components/mapTitle/index.vue";
import * as echarts from "echarts";
enum Bar_Enum {
  level_1 = "#4f5d81",
  level_2 = "#429a9d",
  level_3 = "#007fb2",
  level_4 = "#eca933",
  level_5 = "#4191ff",
}

const seriesData = [
  {
    name: "服务强军兴军",
    type: "level_1",
    value: [25, 27, 18, 22, 28, 24, 19, 20, 21, 22, 19],
  },
    {
    name: "军民协同创新",
    type: "level_3",

    value: [19, 13.5, 6.5, 12.5, 15.5, 14, 6.5, 10.5, 8, 4, 6],
  },
  {
    name: "产业融合发展",
    type: "level_2",

    value: [14.5, 9, 6, 10, 13, 14, 13.5, 8, 6, 12.5, 15],
  },
  {
    name: "资源开放共享",
    type: "level_4",

    value: [13.2, 14, 10, 11, 14, 12.5, 7.5, 13.5, 10, 12, 10],
  },
  {
    name: "五大体系建设",
    type: "level_5",

    value: [14, 15, 10.4, 12, 11, 15, 13, 13, 13, 11, 11.2],
  },
];

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

export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  computed: {
    optionBar() {
      const seriesList = seriesData.map((item, index) => {
        return {
          name: item.name,
          type: "bar",
          stack: "total",
          label: {
            show: true,
            color: "#fff",
          },
          barWidth: 26,
          itemStyle: {
            color: Bar_Enum[item.type],
          },
          emphasis: {
            show: false,
          },

          data: item.value.map((valItem) => {
            return {
              value: valItem,
              class: `color_${index + 1}`,
            };
          }),
        };
      });

      return {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          className: "per-formance-echart",
          formatter: (params) => {
            let html = `<span class="name">${params[0].axisValue}</span>`;
            params.forEach((item) => {
              const { data = {} } = item;

              html += `<div class="per-formance-echart">
                <span class="${data.class} title">${item.seriesName}</span>
                <span class="text">${data.value}</span>
            </div>`;
            });

            return html;
          },
        },
        legend: {},
        grid: {
          left: "0%",
          right: "0%",
          bottom: "3%",
          containLabel: true,
        },
        yAxis: {
          type: "value",
          min: 0,
          max: 100,
        },
        xAxis: {
          type: "category",
          data: xAxisValue,
        },
        series: seriesList,
      };
    },
  },
  methods: {
    detailsHandle() {
      console.log("---点击详情跳转");
    },
    initEcharts() {
      const dom = document.getElementById("performanceBar");
      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>
.per-formance-echart {
  width: 120px;
  display: flex;
  justify-content: space-between;
}

.per-formance-echart .name {
  margin-bottom: 15px;
  font-size: 14px;
  color: #333;
  font-weight: bold;
}
.per-formance-echart .title {
  padding-left: 10px;
  font-weight: 600;
  font-size: 12px;
  color: #666;
  position: relative;
}
.per-formance-echart .title::before {
  position: absolute;
  top: 5px;
  left: 0;
  content: " ";
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 50%;
  background: red;

}
.per-formance-echart .row-item {
  padding: 0 15px 10px 15px;

  display: flex;
  align-items: center;
  font-size: 12px;
  color: #999;
  justify-content: space-between;
}
.per-formance-echart .row-item div {
  margin-right: 15px;
}
.per-formance-echart .row-item p {
  font-size: 12px;
  color: #999;
}
.per-formance-echart .row-item p span {
  font-size: 18px;
  margin-right: 5px;
}
.per-formance-echart .text{
  color: #4191ff
}
.per-formance-echart .color_1::before {
  background: #4f2d11;
}
.per-formance-echart .color_2::before {
  background: #429a9d;
}
.per-formance-echart .color_3::before {
  background: #007fb2;
}
.per-formance-echart .color_4::before {
  background: #eca933;
}
.per-formance-echart .color_5::before {
  background: #4191ff;
}
</style>

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