<template>
  <div :id="health" class="dashboard"></div>
</template>

<script>
import { v4 as uuidv4 } from 'uuid';
var echarts = require("echarts");
export default {
  props: {
    data: {
      type: Object,
      default: () => {
        return {
          num: 0,
          color: "#e15260",
          text: "敏感",
        };
      },
    },
  },
  components: {},
  data() {
    return {
      health: uuidv4(),
    };
  },
  watch: {
    data: {
      handler(val) {
        this.init_health(this.data.num, this.data.color, this.data.text);
      },
      deep: true,
    },
  },
  computed: {},
  created() {},
  mounted() {
    this.init_health(this.data.num, this.data.color, this.data.text);
  },
  methods: {
    init_health(num, color, text) {
      var options = {
        color: [color, "#c9cedd"],
        title: {
          text: num + "%",
          textStyle: {
            color: "#000",
            fontSize: 26,
            fontWeight: 200,
          },
          subtext: text,
          subtextStyle: {
            color: "#707693",
            fontSize: 12,
          },
          itemGap: 0, // 主副标题距离
          left: "center",
          top: "center",
        },
        angleAxis: {
          max: 100, // 满分
          clockwise: false, // 逆时针
          startAngle: 90,
          // 隐藏刻度线
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          splitLine: {
            show: false,
          },
        },
        radiusAxis: {
          type: "category",
          // 隐藏刻度线
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          splitLine: {
            show: false,
          },
        },
        polar: {
          center: ["50%", "50%"],
          radius: "140%", //图形大小
        },
        series: [
          {
            type: "pie",
            z: 5,
            center: ["50%", "50%"],
            radius: ["68%", "72%"],
            silent: true,
            label: {
              normal: {
                show: false,
              },
              emphasis: {
                show: false,
              },
            },
            labelLine: {
              normal: {
                show: false,
              },
              emphasis: {
                show: false,
              },
            },
            tooltip: {
              show: false,
            },
            data: [
              {
                name: "",
                value: num,
              },
              {
                name: "",
                value: 100 - num,
              },
            ],
          },
          {
            type: "pie",
            z: 4,
            center: ["50%", "50%"],
            radius: ["60%", "80%"],
            hoverAnimation: false,
            avoidLabelOverlap: false,
            label: {
              normal: {
                show: false,
              },
              emphasis: {
                show: false,
              },
            },
            labelLine: {
              normal: {
                show: false,
              },
              emphasis: {
                show: false,
              },
            },
            tooltip: {
              show: false,
            },
            itemStyle: {
              normal: {
                color: "#f6f7fc",
              },
            },
            emphasis: {
              show: false,
              itemStyle: {
                color: "#f6f7fc",
              },
            },
            data: [
              {
                value: 1,
              },
            ],
          },
        ],
      };
      window[this.health] = echarts.init(document.getElementById(this.health));
      window[this.health].setOption(options, true);
    },
  },
};
</script>

<style scoped>
.dashboard {
  width: 100%;
  height: 100%;
}
</style>
