<template>
  <div class="synergy-innovation-platform">
    <MapTitle text="融办主任主持召开主任会议情况" />

    <div class="echarts-search">
      <div class="card-items">
        <div class="item">
          <span>今年以来融办主任主持召开主任会议次数</span>
          <div class="value-des">
            <span>{{ meetingCount || "--" }}</span
            >次
          </div>
        </div>
      </div>
    </div>

    <div id="targetBar" class="target-bar"></div>
  </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 {
      countryEcharts: null,

      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: "5%",
          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("targetBar");
      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 lang="scss" scoped>
.synergy-innovation-platform {
  height: 100%;
  .echarts-search {
    padding-left: 10px;
    .title {
      color: #4198ff;
      margin: 12px 0;
      font-size: 16px;
    }
    .card-items {
      margin: 15px 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      .item {
        flex: 1;
        padding: 8px 15px;
        margin-right: 15px;
        background: #197ded15;
        border-radius: 5px;
        font-size: 14px;
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;
        &:last-of-type {
          margin-right: 0;
        }
        .value-des {
          font-size: 12px;
          color: #fff;
          display: flex;
          align-items: center;
          span {
            font-size: 20px;
            margin-right: 5px;
            color: #19ecff;
          }
        }
      }
    }
  }

  .target-bar {
    flex: 1;
    height: calc(100% - 130px);
    box-sizing: border-box;
    margin-top: 10px;
  }
}
</style>
