<template>
  <div class="mapEcharts-institutions">
    <MapTitle text="召开融委全体会议情况" />
    <div class="meeting">
      <div>今年以来召开融委全体会议次数</div>
      <div class="frequency">
        {{ meetingCount || "--" }}
        <span class="second">次</span>
      </div>
    </div>
    <el-row class="investment">
      <el-col class="city-echarts">
        <div class="title2X">各市融委全体会议召开次数</div>
        <div id="mapEcharts" class="echart-item"></div>
      </el-col>
    </el-row>
  </div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import MapTitle from "@/components/mapTitle/index.vue";
import * as echarts from "echarts";
import { Aim } from "@element-plus/icons";
import Mock from "./mock";
import { mapState } from "vuex";

// 城市增长率
const xAxisCity = [
  "杭州",
  "宁波",
  "温州",
  "湖州",
  "嘉兴",
  "绍兴",
  "金华",
  "衢州",
  "舟山",
  "台州",
  "丽水",
];
let MAP_ECHARTS = null;

/**
 * 承担军需品情况
 */
export default defineComponent({
  components: {
    MapTitle,
    Aim,
  },
  setup() {},
  data() {
    return {
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  computed: {
    ...mapState({
      curDataType: (state) => state.curDataType,
    }),
    meetingCount() {
      return Mock[this.curDataType].meetingCount;
    },
    cityData() {
      return Mock[this.curDataType].cityData;
    },
    optionCity() {
      const seriesBar = {
        type: "bar",

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

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

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

            html += `<div class="munition-echart ">
                <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: "10%",
          left: "0.8%",
          right: "2%",
          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],
      };
    },
  },
  watch: {
    cityData() {
      MAP_ECHARTS.showLoading();
      MAP_ECHARTS.setOption(this.optionCity, true);
      MAP_ECHARTS.hideLoading();
    },
  },
  methods: {
    initEcharts() {
      this.initCityEcharts();
    },

    initCityEcharts() {
      const dom = document.getElementById("mapEcharts");
      MAP_ECHARTS = echarts.init(dom);
      MAP_ECHARTS.setOption(this.optionCity);
      this.mapEcharts = MAP_ECHARTS;
    },
  },
  unmounted() {
    if (this.mapEcharts) {
      this.mapEcharts.dispose();
      this.mapEcharts = null;
    }
  },
});
</script>

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

.munition-echart .text-color_1 {
  color: #4198ff;
}
.munition-echart .text-color_2 {
  color: #eca933;
}
.munition-echart .color_1::before {
  background: #4198ff;
}
.munition-echart .color_2::before {
  background: #eca933;
}
/* 次数 */
.meeting {
  height: 50px;
  line-height: 50px;
  border-radius: 4px;
  color: #fff;
  background: #197ded15;
  display: flex;
  justify-content: space-between;
  padding: 0 10px 0 14px;
  box-sizing: border-box;
  margin-top: 10px;
}
.frequency {
  color: #19ecff;
  font-size: 20px;
  font-weight: 500;
}
.second {
  color: #fff;
  font-size: 12px;
  font-weight: normal;
}
</style>


<style lang="scss" scoped>
.mapEcharts-institutions {
  height: 100%;
  .investment {
    .echart-item {
      flex: 1;
      height: 300px;
      box-sizing: border-box;
      margin-top: 10px;
    }
    .card-list {
      // display: flex;
      // flex-direction: column;
      // padding: 20px 20px 20px 0;
      .card-item {
        flex: 1;
        box-sizing: border-box;
        margin-bottom: 15px;
        padding: 20px;
        background: #f8f9fb;
        display: flex;
        flex-direction: column;
        justify-content: center;
        border-radius: 5%;
        &:last-of-type {
          margin-bottom: 0;
        }
        p {
          font-size: 14px;
          color: #333;
          margin-bottom: 10px;
        }
        div {
          color: #4198ff;
          font-size: 20px;
        }
        .unit {
          color: #999;
          font-size: 12px;
        }
      }
    }

    .title2X {
      margin-top: 15px;
      font-size: 16px;
      color: #4198ff;
      padding-left: 5px;
    }
  }
}
</style>
