<template>
  <div class="container">
    <div class="block1">
      <layout-title title="人员类型统计" />
      <div class="option">
        <div
          class="list"
          v-for="(item, index) in data.block1OptionsList"
          :key="index"
        >
          <img :src="item.img" alt="" class="img" />
          <div class="label">{{ item.label }}</div>
          <div class="num">
            <count-up :end-val="item.count"></count-up>
          </div>
        </div>
      </div>
    </div>
    <div class="block2">
      <layout-title title="告警类型统计" />
      <div class="option">
        <div
          class="list"
          v-for="(item, index) in data.block2OptionsList"
          :key="index"
        >
          <div class="name">{{ item.label }}</div>
          <div class="num">
            <count-up :end-val="item.total"></count-up>
          </div>
        </div>
      </div>
    </div>
    <div class="block3">
      <layout-title title="人员定位情况" />
      <div class="option">
        <div class="table">
          <div class="tr">
            <div class="td">姓名</div>
            <div class="td">卡号</div>
            <div class="td">电量</div>
          </div>
          <div class="tr" v-for="(item, index) in data.block3List" :key="index">
            <div class="td">{{ item.name }}</div>
            <div class="td">{{ item.cardNo }}</div>
            <div class="td">{{ item.stset + "%" }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import LayoutTitle from "./title.vue";
import CountUp from "vue-countup-v3";
import { nextTick, reactive } from "vue";
import {
  getPersonnelTypeCount,
  getAlarmTypeCount,
  getPersonnelPositioningCount,
} from "@/request/bi/mapApi.js";

const data = reactive({
  block1OptionsList: [
    {
      img: new URL("/src/assets/images/map/img1.png", import.meta.url).href,
      label: "全部人员",
      count: 3500,
    },
  ],
  block2OptionsList: [
    {
      label: "滞留报警",
      count: 3500,
    },
    {
      label: "越界报警",
      count: 235,
    },
    {
      label: "超员报警",
      count: 569,
    },
    {
      label: "缺员报警",
      count: 569,
    },
    {
      label: "静止报警",
      count: 423,
    },
    {
      label: "串岗报警",
      count: 789,
    },
    {
      label: "一键告警",
      count: 236,
    },
    {
      label: "聚集告警",
      count: 214,
    },
    {
      label: "作业告警",
      count: 852,
    },
  ],
  block3List: [
    {
      name: "赵一诺",
      Office: "大堂经理",
      electricity: "30%",
    },
    {
      name: "赵一诺",
      Office: "大堂经理",
      electricity: "30%",
    },
    {
      name: "赵一诺",
      Office: "大堂经理",
      electricity: "30%",
    },
    {
      name: "赵一诺",
      Office: "大堂经理",
      electricity: "30%",
    },
    {
      name: "赵一诺",
      Office: "大堂经理",
      electricity: "30%",
    },
    {
      name: "赵一诺",
      Office: "大堂经理",
      electricity: "30%",
    },
    {
      name: "赵一诺",
      Office: "大堂经理",
      electricity: "30%",
    },
    {
      name: "赵一诺",
      Office: "大堂经理",
      electricity: "30%",
    },
  ],
});
const getPersonnelData = async () => {
  const resData = await getPersonnelTypeCount();
  await nextTick(() => {
    data.block1OptionsList.forEach((item) => {
      item.count = resData.userCount;
    });
  });
};
const getAlarmTypeData = async () => {
  const resData = await getAlarmTypeCount();
  const dataList = resData.data.data.data;
  //  (1=滞留报警,2=串岗报警,3=超员报警,4=缺员报警,5=静止报警,6=一键报警,7=越界报警,8=聚集告警 )
  dataList.forEach((item) => {
    if (item.type === "1") item.label = "滞留报警";
    if (item.type === "2") item.label = "串岗报警";
    if (item.type === "3") item.label = "超员报警";
    if (item.type === "4") item.label = "缺员报警";
    if (item.type === "5") item.label = "静止报警";
    if (item.type === "6") item.label = "一键报警";
    if (item.type === "7") item.label = "越界报警";
    if (item.type === "8") item.label = "聚集告警";
  });
  data.block2OptionsList = dataList;
};
const getPositionData = async () => {
  const resData = await getPersonnelPositioningCount();
  console.log(resData.data.rows);
  data.block3List = resData.data.rows;
};
getPersonnelData();
getAlarmTypeData();
getPositionData();
</script>
<style scoped lang="scss">
.container {
  width: 100%;

  .block1 {
    width: 430px;

    .option {
      width: 100%;
      min-height: 100px;
      background-image: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0),
        rgba(0, 0, 0, 0.8)
      );
      border-radius: 10px;
      border: 1px solid;
      border-image: linear-gradient(
          to bottom,
          rgba(58, 122, 149, 0),
          rgba(16, 188, 236, 1)
        )
        1;
      border-top: none;
      display: flex;
      justify-content: space-around;
      padding: 20px 0;
      text-align: center;

      .list {
        text-align: center;
        width: 33%;

        .img {
          animation: slideY 2s infinite;
        }

        .label {
          margin-top: 5px;
        }

        .num {
          font-size: 24px;
          margin-top: 10px;
          background: linear-gradient(to top, #ffffff, #00a8ff);
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
          font-weight: bold;
          font-family: "Pingfang SC", "Microsoft YaHei", "Monospaced Number",
            "Chinese Quote", -apple-system, BlinkMacSystemFont, "Segoe UI",
            Roboto, "PingFang SC", "Hiragino Sans GB", "Helvetica Neue",
            Helvetica, Arial, sans-serif;
          text-shadow: 0 0 20px #2c67ec;
        }
      }
    }
  }

  .block2 {
    width: 430px;
    margin-top: 10px;

    .option {
      width: 100%;
      min-height: 100px;
      background-image: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0),
        rgba(0, 0, 0, 0.8)
      );
      border-radius: 10px;
      border: 1px solid;
      border-image: linear-gradient(
          to bottom,
          rgba(58, 122, 149, 0),
          rgba(16, 188, 236, 1)
        )
        1;
      border-top: none;
      display: flex;
      padding: 10px;
      text-align: center;
      flex-wrap: wrap;
      justify-content: space-between;

      .list {
        width: 48%;
        background: rgba(20, 88, 177, 0.3);
        border: 1px solid rgba(63, 145, 197, 0.5);
        border-radius: 4px;
        margin-top: 10px;
        display: flex;
        justify-content: space-between;
        padding: 10px;
      }
    }
  }

  .block3 {
    width: 430px;
    margin-top: 10px;

    .tab_list {
    }

    .option {
      width: 100%;
      min-height: 100px;
      background-image: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0),
        rgba(0, 0, 0, 0.8)
      );
      border-radius: 10px;
      border: 1px solid;
      border-image: linear-gradient(
          to bottom,
          rgba(58, 122, 149, 0),
          rgba(16, 188, 236, 1)
        )
        1;
      border-top: none;
      padding: 10px;

      .tab_list {
        display: flex;
        background: rgba(52, 147, 245, 0.3);
        border: 1px solid rgba(63, 145, 197, 0.4);
        border-radius: 2px;
        width: 55%;
        justify-content: space-between;

        .list {
          padding: 8px 10px;
          cursor: pointer;

          &:hover,
          &.active {
            background-image: linear-gradient(
              to bottom,
              rgba(1, 168, 255, 1),
              rgba(17, 74, 152, 1)
            );
          }
        }
      }
      .table {
        margin-top: 5px;

        .tr {
          display: flex;
          &:nth-child(odd) {
            background-color: rgba(42, 86, 158, 0.53);
          }
          .td {
            flex: 1;
            text-align: left;
            font-size: 14px;
            color: #fff;
            padding: 10px 10px;
            &:nth-child(1) {
              flex-basis: 30%;
            }
            &:nth-child(2) {
              flex-basis: 50%;
            }
            &:nth-child(3) {
              flex-basis: 20%;
            }
          }

          .empty {
            flex: 1;
            text-align: center;
            font-size: 12px;
            color: #fff;
            padding: 5px;
          }
        }
      }
    }
  }

  @keyframes slideY {
    0% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(-5px);
    }
    100% {
      transform: translateY(0);
    }
  }
}
</style>
