<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';
export default {
  data() {
    return {
      nowIndex: 0,
      chartOptionsLeft: {
        series: [
          {
            type: 'pie',
            radius: ['32%', '50%'],
            selectedMode: 'single',
            data: [
              { name: '一级', value: 148, selected: true },
              { name: '二级', value: 87, selected: false },
              { name: '三级', value: 75, selected: false },
              { name: '四级', value: 40, selected: false },
            ],
            label: {
              formatter: '{b}{c}',
              color: 'inherit',
            },
          },
        ],
      },
      chartOptionsRight: {
        series: [
          {
            type: 'pie',
            radius: ['32%', '50%'],
            selectedMode: 'single',
            data: [
              { name: 'I级', value: 137, selected: true },
              { 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',
            },
          },
        ],
      },
    };
  },
  mounted() {
    const echartsContainerLeft = this.$refs.echartsContainerLeft;
    const chartLeft = echarts.init(echartsContainerLeft);
    chartLeft.setOption(this.chartOptionsLeft);
    const echartsContainerRight = this.$refs.echartsContainerRight;
    const chartRight = echarts.init(echartsContainerRight);
    chartRight.setOption(this.chartOptionsRight);
    setInterval(() => {
      let lastIndex = this.nowIndex++;
      const leftData = this.chartOptionsLeft['series'][0]['data'];
      leftData[lastIndex % 4]['selected'] = false;
      leftData[this.nowIndex % 4]['selected'] = true;
      chartLeft.setOption(this.chartOptionsLeft, true);
      const rightData = this.chartOptionsRight['series'][0]['data'];
      rightData[lastIndex % 5]['selected'] = false;
      rightData[this.nowIndex % 5]['selected'] = true;
      chartRight.setOption(this.chartOptionsRight, true);
    }, 2000);
  },
};
</script>

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