<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>
            <!-- <img src="@/assets/img/qiandai.svg" alt="" /> -->
            <div>营业收入 <span>(亿元)</span></div>
          </div>
          <span class="mony-number">3532.82</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 pieList"
          :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";

const PIE_LIST = [
  { label: "数字军工(网络、人工智能)领域", value: 932.66 },
  { label: "高端装备领域", value: 383.17 },
  { label: "核电(新能源领域)", value: 311.27 },
  { label: "生物安全领域", value: 267.96 },
  { label: "航空航天领域", value: 269.18 },
  { label: "船舶与海洋装备领域", value: 84.22 },
  { label: "军队现代后勤保障领域", value: 517.9 },
  { label: "军用材料与基础件配套领域", value: 365.24 },
  { label: "其他", value: 401.22 },
];

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",
};

/**
 * 军民融合产业主营业务收入
 */
export default defineComponent({
  components: {
    MapTitle,
    Aim,
  },
  setup() {},
  data() {
    return {
      pieList: PIE_LIST,
      pieColor: PieColor,
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  computed: {
    optionBar() {
      const pieData = PIE_LIST.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");
      const mapEcharts = echarts.init(dom);
      mapEcharts.setOption(this.optionBar);
      this.mapEcharts = mapEcharts;
    },
  },
  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>
