<template>
  <MapTitle text="经济建设与国防密切相关的建设项目贯彻国防要求落实情况" />
  <el-row class="economic-info" justify="space-between">
    <el-col :span="11">
      <div class="card-item">
        <span class="card-text">国防要求建设项目</span>

        <div class="info-wrapper">
          <div class="info-details">
            <div class="info-item">
              <span class="title">项目数量</span>
              <div><span>67</span>个</div>
            </div>

            <div class="info-item">
              <span class="title">投资额</span>
              <div><span>438.32</span>亿元</div>
            </div>
          </div>
          <!-- 环形进度条 -->
          <div v-show="false" id="circularEchart" class="circular"></div>
        </div>
      </div>
    </el-col>

  <el-col :span="1">
     <el-divider direction="vertical"></el-divider>
  </el-col>

    <el-col class="increase-rate" :span="11">
      <div class="card-item">
        <span class="card-text">省军民融合重大示范项目</span>

        <div class="info-wrapper">
          <div class="info-details">
            <div class="info-item">
              <span class="title">项目数量</span>
              <div><span>42</span>个</div>
            </div>

            <div class="info-item">
              <span class="title">投资额</span>
              <div><span>138.84</span>亿元</div>
            </div>
          </div>
          <!-- 环形进度条 -->
          <div id="cirRightEchart" class="circular"></div>
        </div>
      </div>
    </el-col>
  </el-row>

  <div class="bar-title">军民融合"十百千"项目投资金额及进度情况</div>
  <div id="economicConstruct" class="economic-construct"></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.20, 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 xAxisValue = [
  "杭州",
  "宁波",
  "温州",
  "湖州",
  "嘉兴",
  "绍兴",
  "金华",
  "衢州",
  "舟山",
  "台州",
  "丽水",
];

/**
 * 经济建设与国防密切相关的建设项目贯彻国防要求落实情况——柱状图
 */
export default defineComponent({
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      seriesData: SeriesData,
      mapEcharts: null,
      cirLeftCharts: null,
      cirRightEchart: null,
    };
  },
  mounted() {
    this.initEcharts();
    this.initCircularEcharts();
  },
  computed: {
    optionBar() {
      const seriesBar = {
        name: "投资金额",
        type: "bar",
        itemStyle: {
          color: "#4198ff",
        },
        barWidth: 20,
        data: SeriesData.value.map((item) => {
          return {
            name: item.name,
            value: item,
            label: "投资金额",
          };
        }),
      };

      const seriesLine = {
        name: "项目进度",
        type: "line",
        itemStyle: {
          color: "#3aba67",
        },
        yAxisIndex: 1,
        data: SeriesData.rate.map((item) => {
          return {
            value: item.value,
            label: "项目进度",
          };
        }),
      };

      return {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          className: "economic-echart",
          formatter: (params) => {
            let html = `<span class="name">${params[0].axisValue}</span>`;

            html += `<div class="economic-echart ">
                <span class=" title color_1">${params[0].data.label}</span>
                <br />
                <span class="text text-color_1">${params[0].data.value}</span>亿元
               </div>
              <div class="economic-echart">
                <span class=" title  color_2">${params[1].data.label}</span>
                  <br />
                <span class="text text-color_2">${params[1].data.value}%</span>
            </div>`;

            return html;
          },
        },
        legend: {},
        grid: {
          top: "20%",
          left: "5%",
          right: "5%",
          bottom: "3%",
          containLabel: true,
        },
        yAxis: [
          {
            type: "value",
            name: "金额(亿元)",
          },
          {
            type: "value",
            name: "进度%",
            min: 0,
            max: 100,
            splitLine: {
              show:false
            }
          },
        ],
        xAxis: {
          type: "category",
          data: xAxisValue,
        },
        series: [seriesBar, seriesLine],
      };
    },
    ptionCirLeft() {
      const value = 1;
      return {
        backgroundColor: "#fff",
        title: [
          {
            text: `建设进度`,
            left: "45%",
            top: "30%",
            textAlign: "center",
            textStyle: {
              fontSize: "16",
              fontWeight: "400",
              color: "#333",
              textAlign: "center",
            },
            subtext: `${(value * 100).toFixed(0)}%`,
            subtextStyle: {
              fontSize: "22",
              color: "#3aba67",
              textAlign: "center",
            },
          },
        ],
        polar: {
          radius: ["100%", "80%"],
        },
        angleAxis: {
          max: 100,
          clockwise: false,
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          splitLine: {
            show: false,
          },
        },
        radiusAxis: {
          type: "category",
          show: true,
          axisLabel: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        series: [
          {
            name: "",
            type: "bar",
            roundCap: true,
            z: 2,
            showBackground: true,
            backgroundStyle: {
              color: "#e3e3e3",
            },
            data: [value * 100],
            coordinateSystem: "polar",
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0.5, 1, [
                  {
                    offset: 0,
                    color: "#60f795",
                  },
                  {
                    offset: 0.7,
                    color: "#3aba67d6",
                  },
                  {
                    offset: 1,
                    color: "#3aba67",
                  },
                ]),
              },
            },
          },
        ],
      };
    },
    ptionCirRight() {
      const value = 0.4731;
      return {
        backgroundColor: "#fff",
        title: [
          {
            text: `建设进度`,
            left: "45%",
            top: "30%",
            textAlign: "center",
            textStyle: {
              fontSize: "16",
              fontWeight: "400",
              color: "#333",
              textAlign: "center",
            },
            subtext: `${(value * 100)}%`,
            subtextStyle: {
              fontSize: "16",
              color: "#4198ff",
              textAlign: "center",
            },
          },
        ],
        polar: {
          radius: ["100%", "80%"],
        },
        angleAxis: {
          max: 100,
          clockwise: false,
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          splitLine: {
            show: false,
          },
        },
        radiusAxis: {
          type: "category",
          show: true,
          axisLabel: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        series: [
          {
            name: "",
            type: "bar",
            roundCap: true,
            z: 2,
            showBackground: true,
            backgroundStyle: {
              color: "#e3e3e3",
            },
            data: [value * 100],
            coordinateSystem: "polar",
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0.5, 1, [
                  {
                    offset: 0,
                    color: "#7eb9ff",
                  },
                  {
                    offset: 0.7,
                    color: "#4198ffe8",
                  },
                  {
                    offset: 1,
                    color: "#4198ff",
                  },
                ]),
              },
            },
          },
        ],
      };
    },
  },
  methods: {
    initEcharts() {
      const dom = document.getElementById("economicConstruct");
      const mapEcharts = echarts.init(dom);
      mapEcharts.setOption(this.optionBar);
      this.mapEcharts = mapEcharts;
    },
    initCircularEcharts() {
      const dom = document.getElementById("circularEchart");
      const domCirRightEchart = document.getElementById("cirRightEchart");

      const cirLeftCharts = echarts.init(dom);
      const cirRightEchart = echarts.init(domCirRightEchart);

      cirLeftCharts.setOption(this.ptionCirLeft);
      cirRightEchart.setOption(this.ptionCirRight);
      this.cirLeftCharts = cirLeftCharts;
      this.cirRightEchart = cirRightEchart;
    },
  },
  unmounted() {
    if (this.mapEcharts) {
      this.mapEcharts.dispose();
      this.mapEcharts = null;
    }
  },
});
</script>
<style>
.economic-echart {
  width: 110px;
}
.economic-echart .name {
  margin-bottom: 15px;
  font-size: 14px;
  color: #333;
  font-weight: bold;
}
.economic-echart .title {
  padding-left: 10px;
  font-weight: 600;
  font-size: 12px;
  color: #666;
  position: relative;
}
.economic-echart .title::before {
  position: absolute;
  top: 5px;
  left: 0;
  content: " ";
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 50%;
}
.economic-echart .text {
  padding-left: 20px;
  margin-bottom: 20px;
  font-size: 20px;
}
.economic-echart .text-color_1 {
  color: #4198ff;
}
.economic-echart .text-color_2 {
  color: #3aba67;
}
.economic-echart .color_1::before {
  background: #4198ff;
}
.economic-echart .color_2::before {
  background: #3aba67;
}
</style>

<style lang="scss" scoped>
.economic-info {
  margin-top: 15px;
  height: 150px;
  box-sizing: border-box;
  .card-text {
    color: #4198ff;
    margin: 8px 0;
  }
  .card-item {
    .info-wrapper {
      margin-top: 5px;
      display: flex;
      align-items: center;
      .info-details {
        .info-item {
          padding-left: 12px;
          &:first-of-type {
            margin-bottom: 8px;
          }
          .title {
            font-weight: bold;
            color: #333;
            font-size: 14px;
            position: relative;
            &::before {
              position: absolute;
              display: inline-block;
              content: " ";
              top: 5px;
              left: -12px;
              width: 8px;
              height: 8px;
              border-radius: 50%;
              background: #ff8553;
            }
          }
          div {
            padding-left: 10px;
            display: flex;
            align-items: center;
            font-size: 14px;
            color: #999;
            span {
              font-size: 20px;
              margin-right: 5px;
              color: #4198ff;
            }
          }
        }
      }

      .circular {
        margin-left: 40px;
        width: 100px;
        height: 100px;
      }
    }
  }
  .el-divider{
    margin: 15% auto;
    height: 70%;
    background: #f3f3f3;
  }
}

.bar-title {
  color: #4198ff;
  margin-bottom: 10px;
}
.economic-construct {
  flex: 1;
  min-height: 150px;
  height: calc( 100% - 200px);
  box-sizing: border-box;
  margin-top: 10px;
}
</style>
