<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="13">
        <div id="pie" class="economic-construct"></div>
      </el-col>

      <el-col :span="11">
        <div
          class="list-item"
          v-for="(item, index) in pieList"
          :key="item.label"
        >
          <el-row align="middle">
            <div
              class="square"
              :style="{ background: pieColor[`level_${index + 1}`] }"
            ></div>
            {{ item.label }}
          </el-row>
          <div class="pie-value">{{ item.value }}%</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";

const SeriesData = {
  name: "国防要求建设项目",
  type: "level_1",
  value: [
    37.28, 61.75, 34.54, 8.2, 34.63, 74.4, 32.74, 75.35, 28.13, 27.25, 12.76,
  ],
  rate: [
    {
      city: "杭州",
      value: 49.28,
    },
    {
      city: "宁波",
      value: 45.7,
    },
    {
      city: "温州",
      value: 25.68,
    },
    {
      city: "湖州",
      value: 36.89,
    },
    {
      city: "嘉兴",
      value: 84.07,
    },
    {
      city: "绍兴",
      value: 53.85,
    },
    {
      city: "金华",
      value: 36.05,
    },
    {
      city: "衢州",
      value: 57.74,
    },
    {
      city: "舟山",
      value: 56.43,
    },

    {
      city: "台州",
      value: 55.68,
    },
    {
      city: "丽水",
      value: 32.85,
    },
  ],
};
const PIE_LIST = [
  { label: "海洋领域", value: 25.17 },
  { label: "太空领域", value: 30.96 },
  { label: "网络领域", value: 20.18 },
  { label: "生物领域", value: 10.22 },
  { label: "新能源领域", value: 5.9 },
  { label: "人工智能领域", value: 12.24 },
];
const PieColor = {
  level_1: "#fac858",
  level_2: "#6fdef7",
  level_3: "#4198ff",
  level_4: "#f4a746",
  level_5: "#9daff9",
  level_6: "#47d6ad",
};

/**
 * 经济建设与国防密切相关的建设项目贯彻国防要求落实情况——柱状图
 */
export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      seriesData: SeriesData,
      mapEcharts: null,
      cirLeftCharts: null,
      cirRightEchart: null,
      cardItems: [
        { label: "联合科研攻关投入金额", value: "1113.4" },
        {
          label: "联合科研攻关投入金额增长率",
          value: "19",
        },
      ],
      pieList: PIE_LIST,
      pieColor: PieColor,
    };
  },
  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%", "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");
      const mapEcharts = echarts.init(dom);
      mapEcharts.setOption(this.optionBar);
      this.mapEcharts = mapEcharts;
    },
  },
  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;
    }
    .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>
