<template>
  <MapTitle text="军地需求对接活动情况" />

  <div class="total-contrac-describes">
    <div class="meeting">
      <div>军地需求对接活动情况</div>
      <div class="frequency">
        {{ count || "--" }}
        <span class="second">次</span>
      </div>
    </div>

    <div class="text">活动分布情况</div>
  </div>

  <el-row class="echart-foot">
    <el-col :span="13"
      ><div id="incomDistribution" class="incom-distribution"></div
    ></el-col>
    <el-col :span="11">
      <div class="list-item-wrapper">
        <div
          class="list-item"
          v-for="(item, index) in this.seriesData"
          :key="item.label"
        >
          <el-row align="middle">
            <div
              class="square"
              :style="{ background: pieColor[`level_${index + 1}`] }"
            ></div>
            <span>{{ item.label }}</span>
          </el-row>

          <div class="pie-value">
            {{ item.value || "--" }}
            <span>次</span>
          </div>
        </div>
      </div>
    </el-col>
  </el-row>
</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 PieColor = {
  level_1: "#6fdef7",
  level_2: "#9cbcfa",
  level_3: "#1781df",
  level_4: "#ffa741",
  level_5: "#47d6ad",
  level_6: "#f78a77",
  level_7: "#8a8aa8",
  level_8: "#3bb4a6",
  level_9: "#634cf0",
  level_10: "#ffcf3c",
  level_11: "#b470fc",
};

/**
 * 合同成交总额
 */
export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      mapEcharts: null,
      pieColor: PieColor,
    };
  },
  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;
    },
    count() {
      return Mock[this.curDataType].count;
    },
    optionBar() {
      const seriesBar = {
        type: "pie",
        radius: ["30%", "60%"],
        itemStyle: {
          borderRadius: 0,
        },
        label: {
          show: false,
        },
        emphasis: {
          label: {
            show: false,
          },
        },
        data: this.seriesData.map((valItem, index) => {
          return {
            value: valItem.value,
            label: valItem.label,
            itemStyle: {
              color: PieColor[`level_${index + 1}`],
            },
            tooltip: {
              borderColor: "#fff",

              className: "resource-share-tooltip",
              formatter: `<div class="resource-share-tooltip">
                <span class='title'>${valItem.label}</span>：
                 <br /> 
                 <div class="pie-text level_${index + 1}">
                  <span>${valItem.value}</span>次
                 </div>
              </div>`,
            },
          };
        }),
      };

      return {
        tooltip: {
          // trigger: "item",
        },

        grid: {
          left: "10%",
          right: "5%",
          bottom: "3%",
          containLabel: true,
        },
        series: [seriesBar],
      };
    },
  },
  methods: {
    initEcharts() {
      const dom = document.getElementById("incomDistribution");
      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>
.echart-foot .incom-distribution canvas {
  transform: scale(1.12) translateX(-15px);
}
.resource-share-tooltip .title {
  color: #333;
  font-weight: bold;
}
.resource-share-tooltip .pie-text {
  /* padding-left: 10px; */
  margin-top: 5px;
  font-size: 12px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  position: relative;
}
.resource-share-tooltip .level_1::before {
  background: #6fdef7;
}
.resource-share-tooltip .level_2::before {
  background: #9cbcfa;
}
.resource-share-tooltip .level_3::before {
  background: #1781df;
}
.resource-share-tooltip .level_4::before {
  background: #ffa741;
}
.resource-share-tooltip .level_5::before {
  background: #47d6ad;
}
.resource-share-tooltip .level_6::before {
  background: #f78a77;
}
.resource-share-tooltip .level_7::before {
  background: #8a8aa8;
}
.resource-share-tooltip .level_8::before {
  background: #6fdef7;
}

.resource-share-tooltip .level_9::before {
  background: #634cf0;
}
.resource-share-tooltip .level_10::before {
  background: #ffcf3c;
}
.resource-share-tooltip .level_11::before {
  background: #b470fc;
}
.resource-share-tooltip .pie-text::before {
  position: absolute;
  top: 8px;
  left: 18px;
  content: " ";
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 50%;
}
.resource-share-tooltip .pie-text span {
  color: #4198ff;
  margin-right: 2px;
  font-size: 16px;
}
</style>

<style lang="scss" scoped>
.total-contrac-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;
  }
}
.echart-foot {
  flex: 1;
  height: 100%;
  .list-item-wrapper {
    display: flex;
    flex-wrap: wrap;

    .list-item {
      width: 130px;
      margin-bottom: 15px;
      border-radius: 5px;
      box-sizing: border-box;
      .el-row {
        font-size: 14px;
        color: #fff;
      }
      .pie-value {
        padding-left: 20px;
        font-size: 20px;
        color: #999;
        display: flex;
        align-items: center;
        color: #4198ff;
        span {
          margin-left: 5px;
          font-size: 12px;
          color: #fff;
        }
      }
      .square {
        width: 8px;
        height: 8px;
        margin-right: 5px;
      }
    }
  }
}
.incom-distribution {
  height: 350px;
  width: 350px;
  box-sizing: border-box;
}
</style>
