<template>
  <div class="deviceStatistics card">
    <div class="card-head">
      <div class="title">使用设备统计</div>
    </div>
    <div class="card-chart">
      <div ref="chartRef1" style="width: 100%; height: 100%"></div>
    </div>
  </div>
</template>
<script setup>
import { statisticsUseCount } from "@/api/index";
import { onMounted, ref } from "vue";
import * as echarts from "echarts";
import { useResize } from "@/utils/hooks";

const chartRef1 = ref(null);
let myChart = null;

let option = ref({
  tooltip: {
    trigger: "item",
  },
  legend: {
    right: "left",
  },
  series: {
    type: "pie",
    radius: ["20%", "50%"],
    data: [
      { value: 0, name: "常规模式" },
      { value: 0, name: "户外押送" },
      { value: 0, name: "审讯模式" },
    ],
  },
});
const getStatisticsUseCount = () => {
  statisticsUseCount().then((res) => {
    option.value.series.data = [
      { value: res.defaultCount, name: "常规模式" },
      { value: res.outsideCount, name: "户外押送" },
      { value: res.monitorCount, name: "审讯模式" },
    ];
    myChart.setOption(option.value);
  });
};
useResize(() => {
  myChart.resize();
});
onMounted(() => {
  myChart = echarts.init(chartRef1.value);
  myChart.setOption(option);
  getStatisticsUseCount();
});
</script>
<style scoped lang="less">
.card {
  height: 100%;
  background: #ffffff;
  padding: 16px 10px;
  box-sizing: border-box;
  position: relative;
  display: flex;
  border-radius: 5px;
  box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.12);
  margin-bottom: 20px;
  .card-chart {
    height: 90%;
    width: 100%;
    margin-top: 30px;
  }

  .card-head {
    position: absolute;
    color: #061451;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transform: translateX(-10px);
    margin-bottom: 20px;
    .title {
      &::before {
        display: inline-block;
        margin-right: 10px;
        content: "";
        width: 2px;
        height: 14px;
        border-radius: 20px;
        background: #061451;
      }
    }
    .search {
      display: flex;
      align-items: center;
    }
  }
}
</style>
