<template>
  <div
    class="w-[51.29vh] h-[40.09vh] bgBottomLeftBox mt-[2.68vh] relative"
    v-loading="isLoading"
  >
    <div
      class="w-[45%] 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-[42.96vh] ml-[2.96vh] deptBody">
      <div class="h-[30vh] w-full">
        <Histogram
          v-if="getDataList.length"
          :getDataList="getDataList"
        ></Histogram>
        <div
          v-else
          class="flex flex-col w-[100%] h-[100%] items-center justify-center"
        >
          <img src="@/assets/img/noData.png" class="w-[120px]" />
          <span>暂无数据</span>
        </div>
      </div>
    </div>
    <div
      class="absolute right-0 top-1/4 w-[3.51vh] h-[12.6vh]"
      :class="sliderClass"
    >
      <div
        class="h-[6.3vh] leading-[6.3vh] text-center text-[#C0D3E1] cursor-pointer"
        @click="toWeek"
      >
        周
      </div>
      <div
        class="h-[6.3vh] leading-[6.3vh] text-center text-[#C0D3E1] cursor-pointer"
        @click="toMonth"
      >
        月
      </div>
    </div>
  </div>
</template>

<script>
import { GetMonitorOperationDept } from "@/api/monitor";
import dayjs from "dayjs";
import Histogram from "@/views/pageMonitor/bottomRight/DepHistogram.vue";
export default {
  data() {
    return {
      startDate: dayjs().subtract(7, "day").format("YYYY-MM-DD"),
      endDate: dayjs().format("YYYY-MM-DD"),
      sliderClass: {
        bgWeekBox: true,
        bgMonthBox: false,
      },
      renderTimer: null,
      isLoading: true,
      getDataList: [],
    };
  },
  components: {
    Histogram,
  },
  methods: {
    onGetPageData() {
      this.isLoading = true;
      GetMonitorOperationDept({
        startDate: this.startDate,
        endDate: this.endDate,
      }).then((res) => {
        // this.getDataList = [res["data"]] || [];
        // this.isLoading = false;
        this.getDataList = res["data"] || [];
        this.isLoading = false;
      });
    },
    toWeek() {
      this.startDate = dayjs().subtract(7, "day").format("YYYY-MM-DD");
      this.sliderClass.bgWeekBox = true;
      this.sliderClass.bgMonthBox = false;
      this.onGetPageData();
    },
    toMonth() {
      this.startDate = dayjs().subtract(30, "day").format("YYYY-MM-DD");
      this.sliderClass.bgWeekBox = false;
      this.sliderClass.bgMonthBox = true;
      this.onGetPageData();
    },
  },
  mounted() {
    this.onGetPageData();
    this.renderTimer = setInterval(() => {
      if (this.sliderClass.bgWeekBox) {
        this.toMonth();
      } else {
        this.toWeek();
      }
    }, 20000);
  },
  beforeRouteLeave() {
    clearInterval(this.renderTimer);
  },
};
</script>

<style>
.bgBottomLeftBox {
  background-image: url("@/assets/svg/Monitor/BottomLeft/Box.svg");
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}
.bgWeekBox {
  background-image: url("@/assets/svg/Monitor/BottomLeft/WeekActive.svg");
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}
.bgMonthBox {
  background-image: url("@/assets/svg/Monitor/BottomLeft/MonthActive.svg");
}

.deptBody {
  height: calc(100% - 5.07vh);
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
