<template>
  <MapTitle text="军民融合产业各领域主营业务收入情况" />

  <el-row>
    <el-col :span="10">
      <div class="echarts-circular">
        <div id="businessIncome" class="business-income"></div>
        <div class="money-logo">
          <div>
            <div>
              营业收入
              <span>(亿元)</span>
            </div>
          </div>
          <span class="mony-number">{{ incomCount || "--" }}</span>
        </div>
      </div>
    </el-col>

    <el-col class="pie-items" :span="12" :offset="2">
      <el-row :gutter="15">
        <el-col
          class="pie-item"
          v-for="(item, index) in this.seriesData"
          :key="item.lable"
          :span="11"
        >
          <el-row align="middle">
            <div
              class="square"
              :style="{ background: pieColor[`level_${index + 1}`] }"
            ></div>
            {{ item.label }}
          </el-row>
          <div class="pie-value">
            <span>{{ item.value }}</span
            >亿元
          </div>
        </el-col>
      </el-row>
    </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 { Aim } from "@element-plus/icons";
import Mock from "./mock";
import { mapState } from "vuex";

const PieColor = {
  level_1: "#1781df",
  level_2: "#67bbf9",
  level_3: "#fac858",
  level_4: "#9cbcfa",
  level_5: "#f78a77",
  level_6: "#6fdef7",
  level_7: "#008faa",
  level_8: "#ffa741",
  level_9: "#47d6ad",
};

let MAP_ECHARTS = null;
/**
 * 军民融合产业主营业务收入
 */
export default defineComponent({
  components: {
    MapTitle,
    Aim,
  },
  setup() {},
  data() {
    return {
      pieColor: PieColor,
      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,
    }),
    incomCount() {
      return Mock[this.curDataType].incomCount;
    },
    seriesData() {
      return Mock[this.curDataType].seriesData;
    },
    optionBar() {
      const pieData = this.seriesData.map((item, index) => {
        return {
          value: item.value,
          itemStyle: {
            color: PieColor[`level_${index + 1}`],
          },
          tooltip: {
            borderColor: "none",
            className: "business-pie-tooltip",
            formatter: `<div class="business-pie-tooltip">
                <span class='title'>${item.label}</span>：
                 <br /> 
                 <div class='pie-text'>
                  <span>${item.value}</span>万元
                 </div>
              </div>`,
          },
        };
      });

      return {
        tooltip: {
          trigger: "item",
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: ["48%", "70%"],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: false,
                fontSize: "20",
                formatter: "营业额(万元)\n \n{c}",
              },
            },
            labelLine: {
              show: false,
            },
            data: pieData,
          },
        ],
      };
    },
  },
  methods: {
    initEcharts() {
      const dom = document.getElementById("businessIncome");
      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>
.business-income canvas:first-of-type {
  transform: scale(1.2);
}
.business-pie-tooltip .title {
  color: #333;
  font-weight: bold;
}
.business-pie-tooltip .pie-text {
  padding-left: 10px;
  margin-top: 5px;
  font-size: 12px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.business-pie-tooltip .pie-text span {
  color: #4198ff;
  font-size: 20px;
}
</style>

<style lang="scss" scoped>
.echarts-circular {
  position: relative;
  .money-logo {
    top: 40%;
    left: 37%;
    position: absolute;
    text-align: center;
    transform: scale(1.2);
    div {
      display: flex;
      align-items: center;
      font-size: 22px;
      color: #333;
      span {
        font-size: 16px;
        color: #666;
      }
      img {
        width: 35px;
      }
    }
    .mony-number {
      font-size: 36px;
      color: #4198ff;
    }
  }
}
.business-income {
  flex: 1;
  height: 100%;
  min-height: 400px;
  box-sizing: border-box;
  margin-top: 10px;
}
.pie-items {
  .pie-item {
    margin: 0 15px 10px 0;
    padding: 10px 15px;
    border-radius: 5px;
    background: #f8f9fb;
    .el-row {
      font-size: 14px;
      color: #333;
    }
    .pie-value {
      margin-top: 5px;
      padding-left: 20px;
      font-size: 12px;
      color: #999;
      display: flex;
      align-items: center;
      span {
        margin-right: 5px;
        color: #4198ff;
        font-size: 20px;
      }
    }
    .square {
      width: 8px;
      height: 8px;
      margin-right: 5px;
    }
  }
}
</style>
