<template>
  <MapTitle text="军民资源共享信息平台情况" />
  <div class="platform-describes">
    <div class="meeting">
      <div>军民资源共享信息平台数量</div>
      <div class="frequency">
        {{ seriesData[0].count || "--" }}
        <span class="second">个</span>
      </div>
    </div>

    <div class="text">军民资源共享信息平台分布情况</div>
  </div>

  <div id="numPlatforms" class="platform-bar-echarts-line"></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";

let MAP_ECHARTS = null;

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

/**
 * 军民资源共享信息平台情况
 */
export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  watch: {
    seriesData() {
      MAP_ECHARTS.showLoading();
      MAP_ECHARTS.setOption(this.optionBar, true);
      MAP_ECHARTS.hideLoading();
    },
  },
  computed: {
    ...mapState({
      curDataType: (state) => state.curDataType,
    }),
    seriesData() {
      return Mock[this.curDataType].seriesData;
    },
    optionBar() {
      const seriesBar = this.seriesData.map((item) => {
        return {
          type: "bar",

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

          data: item.value.map((item) => {
            return {
              value: item,
              label: "收入规模",
            };
          }),
        };
      });

      return {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
            shadowStyle: {
              color: "#1881e120",
            },
          },
          formatter: (params) => {
            let html = ``;

            html += `<div class="platform-info-target-tooltip ">
                <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: "12%",
          left: "1%",
          right: "1%",
          bottom: "3%",
          containLabel: true,
        },
        yAxis: {
          type: "value",
          name: "数量(个)",
          nameTextStyle: {
            color: "#fff",
          },
          axisLabel: {
            show: true,
            color: "#fff",
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#125ba3",
              type: "dotted",
            },
          },
        },
        xAxis: {
          type: "category",
          data: xAxisCity,
          axisLabel: {
            show: true,
            color: "#ffffff",
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#125ba3",
            },
          },
          axisTick: {
            show: false,
          },
        },
        series: [...seriesBar],
      };
    },
  },
  methods: {
    initEcharts() {
      const dom = document.getElementById("numPlatforms");
      MAP_ECHARTS = echarts.init(dom);
      MAP_ECHARTS.setOption(this.optionBar);
      this.mapEcharts = MAP_ECHARTS;
    },
  },
  unmounted() {
    if (!this.mapEcharts) {
      return;
    }
    this.mapEcharts.dispose();
    this.mapEcharts = null;
  },
});
</script>
<style>
.platform-info-target-tooltip {
  width: 60px;
}
.platform-info-target-tooltip .name {
  margin-bottom: 15px;
  font-size: 14px;
  color: #333;
  font-weight: bold;
}
.platform-info-target-tooltip .title {
  padding-left: 10px;
  font-weight: 600;
  font-size: 12px;
  color: #666;
  position: relative;
}
.platform-info-target-tooltip .title::before {
  position: absolute;
  top: 5px;
  left: 0;
  content: " ";
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 50%;
}
.platform-info-target-tooltip .text {
  padding-left: 20px;
  margin-bottom: 20px;
}
.platform-info-target-tooltip .text:last-of-type {
  margin: 0;
}
.platform-info-target-tooltip .text-color_1 {
  color: #4198ff;
}
.platform-info-target-tooltip .color_1::before {
  background: #4198ff;
}
</style>
<style lang="scss" scoped>
.platform-bar-echarts-line {
  flex: 1;
  height: calc(100% - 140px);
  box-sizing: border-box;
}
.platform-describes {
  margin: 0 10px;
  height: 100px;
  box-sizing: border-box;
  .meeting {
    height: 50px;
    line-height: 50px;
    border-radius: 4px;
    color: #fff;
    background: #197ded15;
    display: flex;
    justify-content: space-between;
    padding: 0 10px 0 10px;
    box-sizing: border-box;
    margin-top: 10px;
    .frequency {
      color: #19ecff;
      font-weight: 500;
      font-size: 20px;
    }
    .second {
      color: #fff;
      font-size: 14px;
    }
  }
  .text {
    color: #4198ff;
    margin-top: 10px;
    font-size: 14px;
  }
}
</style>
