<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
            >人
          </div>
        </div>
      </div>
    </div>

    <div id="pie" class="target-bar"></div>
  </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 SeriesData = {
  name: "国防要求建设项目",
  type: "level_1",
};
const PieColor = {
  level_1: "#4198ff",
  level_2: "#6fdef7",
  level_3: "#4198ff",
  level_4: "#f4a746",
  level_5: "#9daff9",
  level_6: "#47d6ad",
};
let MAP_ECHARTS = null;

/**
 * 经济建设与国防密切相关的建设项目贯彻国防要求落实情况——柱状图
 */
export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      seriesData: SeriesData,
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  computed: {
    ...mapState({
      curDataType: (state) => state.curDataType,
    }),
    cardItems() {
      return Mock[this.curDataType].cardItems;
    },
    pieList() {
      return Mock[this.curDataType].pieList;
    },
    optionBar() {
      const pieData = this.pieList.map((item, index) => {
        return {
          value: item.value,
          name: item.label,
          itemStyle: {
            color: PieColor[`level_${index + 1}`],
          },
          label: {
            show: true,
            position: "outside",
            formatter: (params) => {
              return (
                "{percent" +
                params.dataIndex +
                "|" +
                params.value +
                "}{text" +
                params.dataIndex +
                "|人}\n{cir" +
                params.dataIndex +
                "|●}\n{name" +
                params.dataIndex +
                "|" +
                params.name +
                "}"
              );
            },
            align: "center",
            padding: [0, -100, 0, -100],
            rich: {
              name1: {
                color: "rgba(36, 36, 36, 1)",
                fontSize: 13,
                align: "center",
                padding: [-5, -0, 0, -90],
              },
              name0: {
                color: "rgba(36, 36, 36, 1)",
                fontSize: 13,
                align: "center",
              },
              percent1: {
                fontFamily: "DIN",
                fontWeight: 500,
                fontSize: 22,
                padding: [-5, -30, 0, -66],
                color: "#1D91F5",
                align: "center",
              },
              percent0: {
                fontFamily: "DIN",
                fontWeight: 500,
                fontSize: 22,
                color: "#1D91F5",
                align: "center",
              },
              small: {
                fontSize: 12,
                color: "#999",
              },
              text1: {
                padding: [-5, 30, 0, 8],
              },
              text0: {
                padding: [-5, 0, 0, 8],
              },
              cir0: {
                fontSize: 15,
                opacity: 1,
                color: PieColor[`level_${index + 1}`],
                padding: [-5, 92, 5, 92],
              },
              cir1: {
                fontSize: 15,
                opacity: 1,
                color: PieColor[`level_${index + 1}`],
                padding: [-5, 92, 3, 92],
              },
            },
          },
          labelLine: {
            length: 27,
            length2: 50,
            show: true,
            color: "#00ffff",
          },
        };
      });

      return {
        tooltip: {
          trigger: "item",
          show: false,
        },

        series: [
          {
            name: "Access From",
            type: "pie",
            radius: ["48%", "80%"],

            data: pieData,
          },
        ],
      };
    },
  },
  watch: {
    pieList() {
      MAP_ECHARTS.showLoading();
      MAP_ECHARTS.setOption(this.optionBar, true);
      MAP_ECHARTS.hideLoading();
    },
  },
  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>
.target-bar {
  flex: 1;
  height: calc(100% - 130px);
  box-sizing: border-box;
  margin-top: 10px;
}
.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: 8px 15px;
        margin-right: 15px;
        background: #f8f9fb;
        border-radius: 5px;
        font-size: 14px;
        color: #333;
        display: flex;
        align-items: center;
        justify-content: space-between;
        &: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>
