<template>
  <div class="scientific-research-input">
    <MapTitle text="新兴领域科研投入情况" />
    <div class="describes">
      <div class="card-items">
        <div class="item" v-for="(item, index) in cardItems" :key="item.text">
          <span>{{ item.label }}</span>
          <div class="value-des">
            <span>{{ item.value || "--" }}</span>
            {{ index === 0 ? "亿元" : "" }}
          </div>
        </div>
      </div>
    </div>

    <el-row :gutter="10" type="flex">
      <el-col :span="11">
        <div id="pie" class="economic-construct"></div>
      </el-col>

      <el-col :span="13">
        <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>
      </el-col>
    </el-row>
  </div>
</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";

const PieColor = {
  level_1: "#47d6ad",
  level_2: "#6fdef7",
  level_3: "#4198ff",
  level_4: "#f4a746",
  level_5: "#9daff9",
  level_6: "#fac858",
};
let MAP_ECHARTS = null;

/**
 * 经济建设与国防密切相关的建设项目贯彻国防要求落实情况——柱状图
 */
export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      // seriesData: SeriesData,
      mapEcharts: null,
      cirLeftCharts: null,
      cirRightEchart: null,

      // pieList: PIE_LIST,
      pieColor: PieColor,
    };
  },
  mounted() {
    this.initEcharts();
  },
  watch: {
    seriesData() {
      MAP_ECHARTS.setOption(this.optionBar, true);
    },
  },
  computed: {
    ...mapState({
      curDataType: (state) => state.curDataType,
    }),
    cardItems() {
      return Mock[this.curDataType].cardItems;
    },
    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%", "80%"],
            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("pie");
      MAP_ECHARTS = echarts.init(dom);
      MAP_ECHARTS.setOption(this.optionBar);
      this.mapEcharts = MAP_ECHARTS;
    },
  },
  unmounted() {
    if (this.mapEcharts) {
      this.mapEcharts.dispose();
      this.mapEcharts = null;
    }
  },
});
</script>
<style>
.scientific-research-input .business-pie-tooltip .title {
  color: #333;
  font-weight: bold;
}
.scientific-research-input .business-pie-tooltip .pie-text {
  padding-left: 10px;
  margin-top: 5px;
  font-size: 12px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.scientific-research-input .business-pie-tooltip .pie-text span {
  color: #4198ff;
  /* font-size: 20px; */
}
</style>

<style lang="scss" scoped>
.scientific-research-input {
  height: 100%;
  .describes {
    margin: 0 10px;
    height: 120px;
    box-sizing: border-box;
    .card-items {
      margin: 15px 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      .item {
        flex: 1;

        padding: 10px 15px;
        margin-right: 15px;
        background: #f8f9fb;
        border-radius: 5px;
        font-size: 14px;
        color: #333;

        &:last-of-type {
          margin-right: 0;
        }
        .value-des {
          margin-top: 10px;
          font-size: 12px;
          color: #999;
          span {
            font-size: 20px;
            margin-right: 5px;
            color: #4198ff;
          }
        }
      }
    }
    .text {
      color: #4198ff;
      margin-top: 10px;
      font-size: 14px;
    }
  }
  .list-item {
    display: flex;
    justify-content: space-between;
    margin: 0 15px 10px 0;
    // padding: 0px 15px;
    border-radius: 5px;
    .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: 20px;
      span {
        font-size: 12px;
        color: rgba(153, 153, 153, 1);
      }
    }
    .square {
      width: 8px;
      height: 8px;
      margin-right: 5px;
    }
  }

  .economic-construct {
    flex: 1;
    height: calc(100% - 0px);
    box-sizing: border-box;
    margin-top: 10px;
    transform: scale(1.2);
  }
}
</style>
