<template>
  <div class="w-[71.58vh] h-[40.09vh] bgBottomMidBox mt-[2.68vh] relative">
    <div class="flex">
      <div
        class="w-[12.4vh] h-[5.07vh] ml-[1.85vh] flex justify-between items-center"
      >
        <img src="@/assets/svg/Monitor/Triangle.svg" />
        <span class="text-[2.03vh] youshe leading-none">手术等级</span>
      </div>
      <div
        class="w-[12.4vh] h-[5.07vh] ml-[27vh] flex justify-between items-center"
      >
        <img src="@/assets/svg/Monitor/Triangle.svg" />
        <span class="text-[2.03vh] youshe leading-none">ASA分级</span>
      </div>
    </div>
    <section class="flex mt-[4.81vh]">
      <div
        class="w-[35.79vh] h-[24.62vh] border-r border-dashed border-r-[rgba(255,255,255,0.26)]"
      >
        <div class="h-full" ref="echartsContainerLeft"></div>
      </div>
      <div class="w-[35.79vh] h-[24.62vh]">
        <div class="h-full" ref="echartsContainerRight"></div>
      </div>
    </section>
  </div>
</template>

<script>
import * as echarts from "echarts";
import {
  GetMonitorOperationLevel,
  GetMonitorOperationASALevel,
} from "@/api/monitor";
import { fnR } from "@/utils/common";
import dayjs from "dayjs";
let chartLeft = null;
let chartRight = null;

export default {
  data() {
    return {
      nowIndex: 0,
      chartOptionsLeft: {
        series: [
          {
            type: "pie",
            radius: ["32%", "50%"],
            selectedMode: "single",
            data: [
              { name: "一级", value: 148, selected: false },
              { name: "二级", value: 87, selected: false },
              { name: "三级", value: 75, selected: false },
              { name: "四级", value: 40, selected: false },
            ],
            label: {
              formatter: "{b}{c}",
              color: "inherit",
            },
            labelLine: {
              show: true,
              length: 15,
              length2: 18,
              smooth: 0.6, // 可以使引导线稍微弯曲，使得标签位置更加合理
            },
            padAngle: 5,
            itemStyle: {
              borderRadius: 10,
            },
          },
          {
            name: "外边框-outBig",
            type: "pie",
            clockWise: false, //顺时加载
            hoverAnimation: false, //鼠标移入变大
            center: ["50%", "50%"],
            radius: ["62%", "62%"],
            label: {
              normal: {
                show: false,
              },
            },
            data: [
              {
                value: 9,
                name: "",
                itemStyle: {
                  normal: {
                    borderWidth: 2,
                    borderColor: "#2F58B4",
                  },
                },
              },
            ],
          },
          {
            name: "外边框-outSmall",
            type: "pie",
            clockWise: false, //顺时加载
            hoverAnimation: false, //鼠标移入变大
            center: ["50%", "50%"],
            radius: ["57%", "57%"],
            label: {
              normal: {
                show: false,
              },
            },
            showEmptyCircle: true,
            itemStyle: {
              shadowColor: "rgba(255, 0, 0, 1)",
              shadowBlur: 10,
              opacity: 1,
            },
            data: [
              {
                value: 9,
                name: "",
                itemStyle: {
                  normal: {
                    borderWidth: 2,
                    borderColor: "#0D447C",
                  },
                },
              },
            ],
          },
          {
            name: "内边框-inBig",
            type: "pie",
            clockWise: true, //顺时加载
            hoverAnimation: false, //鼠标移入变大
            center: ["50%", "50%"],
            radius: ["25%", "25%"],
            label: {
              normal: {
                show: false,
              },
            },
            itemStyle: {
              shadowColor: "rgba(255, 0, 0, 1)",
              shadowBlur: 10,
              opacity: 1,
            },
            data: [
              {
                value: 9,
                name: "",
                itemStyle: {
                  normal: {
                    borderWidth: 2,
                    borderColor: "#006CFF",
                    opacity: 0.4,
                  },
                },
              },
            ],
          },
          {
            name: "内边框-inSmall",
            type: "pie",
            clockWise: true, //顺时加载
            hoverAnimation: false, //鼠标移入变大
            center: ["50%", "50%"],
            radius: ["20%", "20%"],
            label: {
              normal: {
                show: false,
              },
            },
            data: [
              {
                value: 9,
                name: "",
                itemStyle: {
                  normal: {
                    borderWidth: 2,
                    borderColor: "#fff",
                    opacity: 0.2,
                  },
                },
              },
            ],
          },
        ],
      },
      chartOptionsRight: {
        series: [
          {
            type: "pie",
            radius: ["32%", "50%"],
            selectedMode: "single",
            data: [
              { name: "I级", value: 137, selected: false },
              { name: "II级", value: 105, selected: false },
              { name: "III级", value: 58, selected: false },
              { name: "IV级", value: 37, selected: false },
              { name: "V级", value: 13, selected: false },
            ],
            label: {
              formatter: "{b}{c}",
              color: "inherit",
            },
            labelLine: {
              show: true,
              length: 15,
              length2: 18,
              smooth: 0.6, // 可以使引导线稍微弯曲，使得标签位置更加合理
            },
            padAngle: 5,
            itemStyle: {
              borderRadius: 10,
            },
          },
          {
            name: "外边框-outBig",
            type: "pie",
            clockWise: false, //顺时加载
            hoverAnimation: false, //鼠标移入变大
            center: ["50%", "50%"],
            radius: ["62%", "62%"],
            label: {
              normal: {
                show: false,
              },
            },
            data: [
              {
                value: 9,
                name: "",
                itemStyle: {
                  normal: {
                    borderWidth: 2,
                    borderColor: "#2F58B4",
                  },
                },
              },
            ],
          },
          {
            name: "外边框-outSmall",
            type: "pie",
            clockWise: false, //顺时加载
            hoverAnimation: false, //鼠标移入变大
            center: ["50%", "50%"],
            radius: ["57%", "57%"],
            label: {
              normal: {
                show: false,
              },
            },
            showEmptyCircle: true,
            itemStyle: {
              shadowColor: "rgba(255, 0, 0, 1)",
              shadowBlur: 10,
              opacity: 1,
            },
            data: [
              {
                value: 9,
                name: "",
                itemStyle: {
                  normal: {
                    borderWidth: 2,
                    borderColor: "#0D447C",
                  },
                },
              },
            ],
          },
          {
            name: "内边框-inBig",
            type: "pie",
            clockWise: true, //顺时加载
            hoverAnimation: false, //鼠标移入变大
            center: ["50%", "50%"],
            radius: ["25%", "25%"],
            label: {
              normal: {
                show: false,
              },
            },
            itemStyle: {
              shadowColor: "rgba(255, 0, 0, 1)",
              shadowBlur: 10,
              opacity: 1,
            },
            data: [
              {
                value: 9,
                name: "",
                itemStyle: {
                  normal: {
                    borderWidth: 2,
                    borderColor: "#006CFF",
                    opacity: 0.4,
                  },
                },
              },
            ],
          },
          {
            name: "内边框-inSmall",
            type: "pie",
            clockWise: true, //顺时加载
            hoverAnimation: false, //鼠标移入变大
            center: ["50%", "50%"],
            radius: ["20%", "20%"],
            label: {
              normal: {
                show: false,
              },
            },
            data: [
              {
                value: 9,
                name: "",
                itemStyle: {
                  normal: {
                    borderWidth: 2,
                    borderColor: "#fff",
                    opacity: 0.2,
                  },
                },
              },
            ],
          },
        ],
      },
      toDate: dayjs().format("YYYY-MM-DD"),
    };
  },
  methods: {
    onGetPageData() {
      this.isLoading = true;
      Promise.all([
        GetMonitorOperationLevel(this.toDate),
        GetMonitorOperationASALevel(this.toDate),
      ]).then((res) => {
        this.chartOptionsLeft.series[0].data[0].value = res[0].data["level1"];
        this.chartOptionsLeft.series[0].data[1].value = res[0].data["level2"];
        this.chartOptionsLeft.series[0].data[2].value = res[0].data["level3"];
        this.chartOptionsLeft.series[0].data[3].value = res[0].data["level4"];
        this.chartOptionsRight.series[0].data[0].value =
          res[1].data["asaLevel1"];
        this.chartOptionsRight.series[0].data[1].value =
          res[1].data["asaLevel2"];
        this.chartOptionsRight.series[0].data[2].value =
          res[1].data["asaLevel3"];
        this.chartOptionsRight.series[0].data[3].value =
          res[1].data["asaLevel4"];
        this.chartOptionsRight.series[0].data[4].value =
          res[1].data["asaLevel5"];
        if (this.$store.getters.isMock) {
          this.chartOptionsLeft.series[0].data[0].value = fnR();
          this.chartOptionsLeft.series[0].data[1].value = fnR();
          this.chartOptionsLeft.series[0].data[2].value = fnR();
          this.chartOptionsLeft.series[0].data[3].value = fnR();
          this.chartOptionsRight.series[0].data[0].value = fnR();
          this.chartOptionsRight.series[0].data[1].value = fnR();
          this.chartOptionsRight.series[0].data[2].value = fnR();
          this.chartOptionsRight.series[0].data[3].value = fnR();
          this.chartOptionsRight.series[0].data[4].value = fnR();
        }
        chartLeft.setOption(this.chartOptionsLeft);
        chartRight.setOption(this.chartOptionsRight);
        this.isLoading = false;
      });
    },
  },
  mounted() {
    chartLeft = echarts.init(this.$refs.echartsContainerLeft);
    chartLeft.setOption(this.chartOptionsLeft);
    chartRight = echarts.init(this.$refs.echartsContainerRight);
    chartRight.setOption(this.chartOptionsRight);
    this.onGetPageData();
  },
};
</script>

<style>
.bgBottomMidBox {
  background-image: url("@/assets/svg/Monitor/BottomMid/Box.svg");
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}
</style>
