<!--
 * @Author: daidai
 * @Date: 2022-02-28 16:16:42
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-07-20 17:57:11
 * @FilePath: \web-pc\src\pages\big-screen\view\indexs\left-center.vue
-->
<template>
  <ul class="user_Overview flex" v-if="data.pageflag">
    <li class="user_Overview-item" style="color: #00fdfa">
      <div class="user_Overview_nums allnum ">
        <dv-digital-flop :config="data.config" style="width:100%;height:100%;" />
      </div>
      <p>总设备数</p>
    </li>
    <li class="user_Overview-item" style="color: #07f7a8">
      <div class="user_Overview_nums online">
        <dv-digital-flop :config="data.onlineconfig" style="width:100%;height:100%;" />
      </div>
      <p>在线数</p>
    </li>
    <li class="user_Overview-item" style="color: #e3b337">
      <div class="user_Overview_nums offline">
        <dv-digital-flop :config="data.offlineconfig" style="width:100%;height:100%;" />

      </div>
      <p>掉线数</p>
    </li>
    <li class="user_Overview-item" style="color: #f5023d">
      <div class="user_Overview_nums laramnum">
        <dv-digital-flop :config="data.laramnumconfig" style="width:100%;height:100%;" />
      </div>
      <p>告警次数</p>
    </li>
  </ul>
  <Reacquire v-else @onclick="getData" line-height="200px">
    重新获取
  </Reacquire>
</template>

<script setup>
import { reactive, onBeforeUnmount, onBeforeMount } from 'vue';
import store from '/@/stores/newDeviceVision/modules/setting'

import { currentPOST } from '/@/api/newDeviceVision/modules'
let style = {
  fontSize: 24
}

const data = reactive({
  options: {},
  userOverview: {
    alarmNum: 0,
    offlineNum: 0,
    onlineNum: 0,
    totalNum: 0,
  },
  pageflag: true,
  timer: null,
  config: {
    number: [100],
    content: '{nt}',
    style: {
      ...style,
      // stroke: "#00fdfa",
      fill: "#00fdfa",
    },
  },
  onlineconfig: {
    number: [0],
    content: '{nt}',
    style: {
      ...style,
      // stroke: "#07f7a8",
      fill: "#07f7a8",
    },
  },
  offlineconfig: {
    number: [0],
    content: '{nt}',
    style: {
      ...style,
      // stroke: "#e3b337",
      fill: "#e3b337",
    },
  },
  laramnumconfig: {
    number: [0],
    content: '{nt}',
    style: {
      ...style,
      // stroke: "#f5023d",
      fill: "#f5023d",
    },
  }

})
// ********* 需要打开**********
//     filters: {
//         numsFilter(msg) {
//             return msg || 0;
//         },
//     },

onBeforeMount(() => {
  getData()
})

onBeforeUnmount(() => {
  clearData()
})

const clearData = (() => {
  if (data.timer) {
    clearInterval(data.timer)
    data.timer = null
  }
})

const getData = (() => {
  data.pageflag = true;
  /*let json = {
    data: {
      alarmNum: 359,
      offlineNum: 3,
      totalNum: 22,
      onlineNum: 123
    }
  };
  this.userOverview = json.data;
  this.onlineconfig = {
      ...this.onlineconfig,
      number: [json.data.onlineNum]
  }
  this.config = {
      ...this.config,
      number: [json.data.totalNum]
  }
  this.offlineconfig = {
      ...this.offlineconfig,
      number: [json.data.offlineNum]
  }
  this.laramnumconfig = {
      ...this.laramnumconfig,
      number: [json.data.alarmNum]
  }
  this.switper() */

  // -- 访问数据接口，获取数据
  currentPOST("big2").then((res) => {
    console.log("设备总览", JSON.stringify(res));
    if (!data.timer) { }
    if (res.success) {
      data.userOverview = res.data;
      data.onlineconfig = {
        ...data.onlineconfig,
        number: [res.data.onlineNum]
      }
      data.config = {
        ...data.config,
        number: [res.data.totalNum]
      }
      data.offlineconfig = {
        ...data.offlineconfig,
        number: [res.data.offlineNum]
      }
      data.laramnumconfig = {
        ...data.laramnumconfig,
        number: [res.data.alarmNum]
      }
      switper()
    } else {
      data.pageflag = false;

    }
  });
})

//轮询
const switper = (() => {
  if (data.timer) {
    return
  }
  let looper = (a) => {
    getData()
  };
  data.timer = setInterval(looper, store.state.echartsAutoTime);
})
</script>
<style lang='scss' scoped>
.user_Overview {
  li {
    flex: 1;

    p {
      text-align: center;
      height: 16px;
      font-size: 16px;
    }

    .user_Overview_nums {
      width: 100px;
      height: 100px;
      text-align: center;
      line-height: 100px;
      font-size: 22px;
      margin: 50px auto 30px;
      background-size: cover;
      background-position: center center;
      position: relative;

      &::before {
        content: '';
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
      }

      &.bgdonghua::before {
        animation: rotating 14s linear infinite;
      }
    }

    .allnum {

      // background-image: url("/src/assets/deviceVision/left_top_lan.png");
      &::before {
        background-image: url("/src/assets/deviceVision/left_top_lan.png");

      }
    }

    .online {
      &::before {
        background-image: url("/src/assets/deviceVision/left_top_lv.png");

      }
    }

    .offline {
      &::before {
        background-image: url("/src/assets/deviceVision/left_top_huang.png");

      }
    }

    .laramnum {
      &::before {
        background-image: url("/src/assets/deviceVision/left_top_hong.png");

      }
    }
  }
}
</style>