<template>
  <div class="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: [20, 140],
        center: ["25%", "50%"],
        roseType: "radius",
        itemStyle: {
          borderRadius: 5,
        },
        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: "none",
              className: "business-pie-tooltip",
              formatter: `<div class="business-pie-tooltip">
                <span class='title'>${valItem.label}</span>：
                 <br /> 
                 <div class='pie-text'>
                  <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>
.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;
  margin-right: 5px;
  font-size: 16px;
}
</style>

<style lang="scss" scoped>
.describes {
  margin: 30px 0 10px 0;
  height: 100px;
  box-sizing: border-box;
  .meeting {
    height: 50px;
    line-height: 50px;
    border-radius: 4px;
    color: #666666;
    background: rgba(248, 249, 251, 1);
    display: flex;
    justify-content: space-between;
    padding: 0 10px 0 10px;
    box-sizing: border-box;
    margin-top: 10px;
    .frequency {
      color: rgba(65, 152, 255, 1);
      font-weight: 500;
    }
    .second {
      color: #999;
    }
  }
  .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: 120px;
      margin-bottom: 15px;
      border-radius: 5px;
      box-sizing: border-box;
      .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;
        color: #4198ff;
        font-size: 18px;
        span {
          font-size: 12px;
          color: rgba(153, 153, 153, 1);
        }
      }
      .square {
        width: 8px;
        height: 8px;
        margin-right: 5px;
      }
    }
  }
}
.incom-distribution {
  height: 335px;
  width: 500px;
  box-sizing: border-box;
}
</style>
