<template>
  <el-row :gutter="20" class="monitoring-top">
    <el-col :span="24" :xs="24" :sm="12" :md="12" :lg="6" :xl="6" v-for="(item, index) in funcList" :key="index">
      <div class="item">
        <div class="item-left">
          <div class="item-left-head">
            <div class="title">{{ item.title }}</div>
            <div class="en">{{ item.en }}</div>
          </div>
          <div class="item-left-bottom">
            <div class="num" :style="{ color: item.color }">{{ item.num }}</div>
            <div class="unit">个</div>
          </div>
        </div>
        <div class="item-img">
          <img :src="item.icon" />
        </div>
      </div>
    </el-col>
  </el-row>
</template>
<script setup>
import { statisticsCount } from "@/api/index";
import { onMounted, ref } from "vue";
import handcuffs from "@/assets/img/handcuffs.png";
import onLine from "@/assets/img/onLine.png";
import report from "@/assets/img/report.png";
import newly from "@/assets/img/newly.png";

let funcList = ref([
  { title: "手铐总数", en: "SHOUKAOZONGSHU", icon: handcuffs, num: 0, color: "##71DDF9" },
  { title: "在线数量", en: "ZAIXIANSHULIANG", icon: onLine, num: 0, color: "##71DDF9" },
  { title: "告警数量", en: "GAOJINGSHULIANG", icon: report, num: 0, color: "#8B51FD" },
  { title: "较昨日新增", en: "JIAOZUORIXINZENG", icon: newly, num: 0, color: "#FF6905" },
]);

const getStatisticsCount = () => {
  statisticsCount().then((res) => {
    funcList.value[0].num = res?.deviceTotal || 0;
    funcList.value[1].num = res?.onlineCount || 0;
    funcList.value[2].num = res?.warnCount || 0;
    funcList.value[3].num = res?.addCount || 0;
  });
};
onMounted(() => {
  getStatisticsCount();
});
</script>
<style scoped lang="less">
.monitoring-top {
  display: flex;
  justify-content: space-between;
  .item {
    height: 160px;
    margin-bottom: 20px;
    padding: 25px 33px 16px 36px;
    box-sizing: border-box;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 5px;
    box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.12);
    position: relative;
    .item-left {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .item-left-head {
        .title {
          font-size: 18px;
          color: #061550;
        }
        .en {
          color: #787878;
          font-size: 8px;
        }
      }
      .item-left-bottom {
        display: flex;
        align-items: baseline;
        .num {
          color: #ff0303;
          font-size: 60px;
        }
        .unit {
          color: #ff0303;
          font-size: 20px;
        }
      }
    }
    .item-img {
      position: absolute;
      right: 20px;
      top: 20px;
      width: 80px;
      height: 80px;
      flex-shrink: 0;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>
