<!--
 * @FilePath: \gitscreenFront\src\views\generalEnvironment\content\chart\pm.vue
 * @Author: 王路平
 * @文件版本: V1.0.0
 * @Date: 2023-02-10 13:27:36
 * @Description: 
 * 
 * 版权信息         : 2023 by ${再登软件}, All Rights Reserved.
-->

<template>
  <div class="content-small" ref="humiture"></div>
</template>

<script setup lang="ts">
import { EDataPerson, EDataPersonItem } from "@/type/generalEnvironment";
import { getCurrentInstance, markRaw, onMounted, reactive, ref, watch } from "vue";
const { proxy } = getCurrentInstance() as any;
let props = defineProps<{
  name: String;
  title: any;
}>();
let humiture = ref();
const echartsData = reactive<EDataPerson>({
  humiture: {
    div: null,
    data: null,
    title: "",
    box: null,
  },
});
/**
 * @函数功能:
 * @param {*} value 需要设置的数据
 * @param {*} type 1为创建 2为更新
 * @出口参数:
 * @函数备注:
 */
const setData = (value: any, type: number) => {
  echartsData.humiture!.div = humiture.value;
  echartsData.humiture!.title = props.title;
  echartsData.humiture!.data = {
    title: {
      text: props.title,
      show: true,
      textStyle: {
        color: "#fff",
        fontSize: 20,
      },
      top:'2%'
    },
    grid: {
      // 让图表占满容器
      top: "2%",
      left: "0px",
      right: "0px",
      bottom: "0px",
    },
    series: [
      {
        type: "gauge",
        center: ["50%", "90%"],
        startAngle: 190,
        endAngle: -10,
        radius: "50%",
        min: 0,
        max: 100,
        splitNumber: 10,
        pointer: {
          icon: "path://M12.8,0.7l12,40.1H0.7L12.8,0.7z",
          length: "12%",
          width: 10,
          offsetCenter: [0, "-40%"],
          itemStyle: {
            color: "inherit",
          },
        },
        axisLine: {
          lineStyle: {
            width: 8,
            color: [
              [0.35, "#7CFFB2"],
              [0.75, "#FDDD60"],
              [1, "#FF6E76"],
            ],
          },
        },
        axisTick: {
          distance: 0,
          splitNumber: 5,
          lineStyle: {
            width: 2,
            color: "#999",
          },
        },
        splitLine: {
          distance: 5,
          length: 8,
          lineStyle: {
            width: 3,
            color: "#999",
          },
        },
        axisLabel: {
          distance: 12,
          color: "#999",
          fontSize: 10,
        },
        anchor: {
          show: false,
        },
        title: {
          // show: false,
          offsetCenter: [0, "-20%"],
        },
        detail: {
          valueAnimation: true,
          width: "60%",
          lineHeight: 20,
          borderRadius: 8,
          offsetCenter: [0, "20%"],
          fontSize: 15,
          fontWeight: "bolder",
          formatter: "{value} μg/m3",
          color: "inherit",
        },
        
        data: [
          {
            value: value.two,
            name: "PM2.5",
          },
        ],
      },
      {
        type: "gauge",
        center: ["50%", "50%"],
        startAngle: 200,
        endAngle: -20,
        min: 0,
        max: 200,
        axisLine: {
          lineStyle: {
            width: 10,
            color: [
              [0.35, "#7CFFB2"],
              [0.75, "#FDDD60"],
              [1, "#FF6E76"],
            ],
          },
        },
        pointer: {
          itemStyle: {
            color: "inherit",
          },
        },
        axisTick: {
          distance: -10,
          length: 6,
          lineStyle: {
            color: "#fff",
            width: 2,
          },
        },
        splitLine: {
          distance: -10,
          length: 10,
          lineStyle: {
            color: "#fff",
            width: 4,
          },
        },
        axisLabel: {
          color: "inherit",
          distance: 20,
          fontSize: 10,
        },
        detail: {
          valueAnimation: true,
          offsetCenter: [0, "20%"],
          fontSize: 20,
          formatter: "{value} μg/m3",
          color: "inherit",
        },
        title: {
          offsetCenter: [0, "-50%"],
        },
        data: [
          {
            value: value.ten,
            name: "PM10",
          },
        ],
      },
    ],
  };
  // if (type == 1) {
    change(echartsData.humiture);
  // } else {
  //   updata(echartsData.humiture);
  // }
};

const change = (item: EDataPersonItem) => {
  // let Ebox = markRaw(proxy.$echarts.init(item.div, "dark"));
  // Ebox.setOption(item?.data);
  // item.box = Ebox;

  let Ebox;
  //判断是否已经生成过一次dom，没生成就新建生成过就拿之前的dom
  if (!item.box) {
    Ebox = markRaw(proxy.$echarts.init(item.div, "dark"))
  } else {
    Ebox = item.box;
  }
  //将拿到的dom设置数据源
  Ebox.setOption(item.data);
  //保存新设置的dom
  item.box = Ebox;
};
const updata = (item: EDataPersonItem) => {
  item.box.setOption(item.data);
};
function setchartWH(width: any, height: any) {
  echartsData.humiture!.div = humiture.value;
  humiture.value.style.height = height + "px";
  humiture.value.style.width = width + "px";
  if (echartsData.humiture.box) {
    echartsData.humiture.box.resize();
  }
}
onMounted(() => {
  // setData()
});

// return{setchartWH}
defineExpose({
  setchartWH,
  setData,
});
</script>

<style scope></style>
