<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",
            },
            padAngle: 5,
            itemStyle: {
              borderRadius: 10,
            },
          },
        ],
      },
      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",
            },
            padAngle: 5,
            itemStyle: {
              borderRadius: 10,
            },
          },
        ],
      },
      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>
