<template>
  <MapTitle text="地方为国防和军队建设培养输送人才情况" />
  <div class="describes">
    <div class="card-items">
      <div class="item" v-for="item in info" :key="item.label">
        <span>{{ item.label }}</span>
        <div class="value-des">
          <span>{{ item.value || "--" }}</span
          >{{ item.unit }}
        </div>
      </div>
    </div>

    <div class="text">各市输送人才情况</div>
  </div>

  <div id="locPerson" class="incom-echarts-line"></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 xAxisCity = [
  "杭州",
  "宁波",
  "温州",
  "湖州",
  "嘉兴",
  "绍兴",
  "金华",
  "衢州",
  "舟山",
  "台州",
  "丽水",
];
let MAP_ECHARTS = null;

/**
 * 地方为国防和军队建设培养输送人才情况
 */
export default defineComponent({
  props: {},
  components: {
    MapTitle,
  },
  setup() {},
  data() {
    return {
      mapEcharts: null,
    };
  },
  mounted() {
    this.initEcharts();
  },
  watch: {
    seriesData() {
     MAP_ECHARTS.showLoading();
      MAP_ECHARTS.setOption({ ...this.optionBar }, true);

      MAP_ECHARTS.hideLoading();
    },
  },
  computed: {
    ...mapState({
      curDataType: (state) => state.curDataType,
    }),
    info() {
      return Mock[this.curDataType].info;
    },
    seriesData() {
      return Mock[this.curDataType].seriesData;
    },
    optionBar() {
      const seriesBar = this.seriesData.map((item) => {
        return {
          name: "入伍人数",

          type: "bar",
          itemStyle: {
            color: "#4198ff",
          },
          barWidth: 20,

          data: item.value.map((item) => {
            return {
              value: item,
              label: "入伍人数",
            };
          }),
        };
      });

      const seriesLine = this.seriesData.map((item) => {
        return {
          name: "入伍比率",
          type: "line",
          stack: "Total",
          itemStyle: {
            color: "#429a9d",
          },
          yAxisIndex: 1,
          emphasis: {
            focus: "series",
          },

          data: item.rate.map((item) => {
            return {
              value: item,
              label: "入伍比率",
            };
          }),
        };
      });

      // const seriesLine = {};

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

            html += `<div class="person-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="person-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: {
          textStyle:{
                color:"#d4f7ff"
            }
        },
        grid: {
          top: "12%",
          left: "0%",
          right: "2%",
          bottom: "3%",
          containLabel: true,
        },
        yAxis: [
          {
            type: "value",
            name: "入伍人数",
            min: 0,
            max: 700,
             axisLine: {
            lineStyle: {
              color: "#d4f7ff",
              // width: 1, //这里是为了突出显示加上的
            },
          },
                   splitLine: {
            lineStyle: {
              // 使用深浅的间隔色
              type: 'dashed',
              color: ["#125ba3"],
            },
          },
          },
          {
            type: "value",
            name: "入伍率(%)",
            min: 0,
            max: 1,
             axisLine: {
            lineStyle: {
              color: "#d4f7ff",
              // width: 1, //这里是为了突出显示加上的
            },
          },
                   splitLine: {
            lineStyle: {
              // 使用深浅的间隔色
              type: 'dashed',
              color: ["#125ba3"],
            },
          },
          },
        ],
        xAxis: {
          type: "category",
          data: xAxisCity,
          axisLabel: {
            show: true,
            textStyle: {
              color: "#d4f7ff", //更改坐标轴文字颜色
            },
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#125ba3",
            },
          },
        },
        series: [...seriesBar, ...seriesLine],
      };
    },
  },
  methods: {
    initEcharts() {
      const dom = document.getElementById("locPerson");
     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>
.person-echart {
  width: 110px;
}
.person-echart .name {
  margin-bottom: 15px;
  font-size: 14px;
  color: #333;
  font-weight: bold;
}
.person-echart .title {
  padding-left: 10px;
  font-weight: 600;
  font-size: 12px;
  color: #666;
  position: relative;
}
.person-echart .title::before {
  position: absolute;
  top: 5px;
  left: 0;
  content: " ";
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 50%;
}
.person-echart .text {
  padding-left: 20px;
  margin-bottom: 20px;
  font-size: 20px;
}
.person-echart .text:last-of-type {
  margin: 0;
}

.person-echart .text-color_1 {
  color: #4198ff;
}
.person-echart .text-color_2 {
  color: #429a9d;
}
.person-echart .color_1::before {
  background: #4198ff;
}
.person-echart .color_2::before {
  background: #429a9d;
}
</style>

<style lang="scss" scoped>
.incom-echarts-line {
  flex: 1;
  height: 250px;
  box-sizing: border-box;
}
.describes {
  margin: 0 10px 5px 0;
  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: rgba(25, 125, 237, 15%);
      border-radius: 5px;
      font-size: 14px;
      color: #d4f7ff;
      display: flex;
      align-items: center;
      justify-content: space-between;
      &:last-of-type {
        margin-right: 0;
      }
      .value-des {
        font-size: 12px;
        color: #d4f7ff;
        display: flex;
        align-items: center;
        span {
          font-size: 20px;
          margin-right: 5px;
          color: #19ecff;
        }
      }
    }
  }
  .text {
    color: #ffffff;
    margin-top: 10px;
    font-size: 14px;
  }
}
</style>
