<template>
  <div class="eq-page">
    <div>
      <div class="eqpage-top">
        <div class="eqtiop-left">
          <div class="eq-left-text1">
            {{ Math.round(countInfo.allOfflineRate * 100) || 0 }}%
          </div>
          <div class="eq-left-text2">在线率</div>
        </div>
        <div class="eqtiop-right">
          <!-- <div class="eq-cont-text">
            <span class="eqimp-text2">设备总数</span>
            <span class="eqimp-text3">{{ countInfo.videoCount || "-" }}</span>
          </div>-->
          <div class="eq-rig-flex-top">
            <div class="eq-rig-flex">
              <div class="eqsta-icon"></div>
              <div>
                <div class="eqimp-text2">在线设备</div>
                <div class="eqimp-text1">
                  {{ countInfo.onLineCount || "-" }}
                </div>
              </div>
            </div>
            <div class="eq-rig-flex">
              <div class="eqsta-icon1"></div>
              <div>
                <div class="eqimp-text2">离线设备</div>
                <div class="eqimp-text1">
                  {{ countInfo.offLineCount || "-" }}
                </div>
              </div>
            </div>
          </div>
          <div class="eq-cont-text"></div>
        </div>
      </div>
      <div class="eq-list-cell eq-list-cell1">
        <div style="width: 25%">单位名称</div>
        <div style="width: 23%">接入总数</div>
        <div style="width: 19%">在线</div>
        <div style="width: 23%">离线</div>
        <div style="width: 20%">在线率</div>
      </div>
      <div v-if="list.length > 0" class="eq-list-cell2-out" style="width: 101%">
        <div
          v-for="(item, index) in list"
          :key="index"
          class="eq-list-cell eq-list-cell2"
        >
          <div class="eq-cell-text1-1">{{ item.orgName }}</div>
          <div class="eq-cell-text2-1">{{ item.allLineCount }}</div>
          <div class="eq-cell-text3-1">{{ item.onLineCount }}</div>
          <div class="eq-cell-text4-1">{{ item.offLineCount }}</div>
          <div class="eq-cell-text5-1">
           {{ (item.allOfflineRate * 100).toFixed(2) }}%
          </div>
        </div>
      </div>
      <div v-else>
        <Empty/>
      </div>
    </div>
    <!-- 屏蔽故障率 -->
    <!-- <div style="margin-top: 30px">
      <div class="eqpage-top">
        <div class="eqtiop-left eqtiop-left2">
          <div class="eq-left-text1">
            {{ (equipmentList?.allOfflineRate * 100).toFixed(2) || 0 }}%
          </div>
          <div class="eq-left-text2">故障率</div>
        </div>
        <div class="eqtiop-right">
          <div class="eq-rig-flex-top">
            <div class="eq-rig-flex">
              <div class="eqsta-icon eqsta-icon-1"></div>
              <div>
                <div class="eqimp-text2">接入数</div>
                <div class="eqimp-text1">
                  {{ accessNumber || "-" }}
                </div>
              </div>
            </div>
            <div class="eq-rig-flex">
              <div class="eqsta-icon1 eqsta-icon1-1"></div>
              <div>
                <div class="eqimp-text2">故障时长/h</div>
                <div class="eqimp-text1">
                  {{ equipmentList?.allOfflineTime || "-" }}
                </div>
              </div>
            </div>
          </div>
          <div class="eq-cont-text"></div>
        </div>
      </div>
      <div class="eq-list-cell eq-list-cell1" style="width: 385px">
        <div style="width: 25%">单位名称</div>
        <div style="width: 23%">接入总数</div>
        <div style="width: 30%">故障时长/h</div>
        <div style="width: 22%">故障率</div>
      </div>
      <div class="eq-list-cell2-out" v-if="list.length > 0" style="width: 101%">
        <div
          v-for="(item, index) in moreDataList"
          :key="index"
          class="eq-list-cell eq-list-cell2"
        >
          <div class="eq-cell-text1" style="width: 25%">{{ item?.orgName }}</div>
          <div class="eq-cell-text2" style="width: 23%">{{ item?.allCount }}</div>

          <div class="eq-cell-text4" style="color: #ffce5a;width: 30%">
            {{ item?.allOfflineTime }}
          </div>
          <div class="eq-cell-text5" style="width: 22%">
            {{ (item.allOfflineRate * 100).toFixed(2) }}%
          </div>
        </div>
      </div>
    </div> -->
  </div>
</template>

<script>
import { GetVideoOnlineTime, videoOnlineRateCount } from "@/api/equipment.js";
import moment from "moment";
import Empty from '@/components/empty.vue'
export default {
  components: { Empty },
  data() {
    return {
      countInfo: {},
      list: [],
      query: {
        level: "0",
        dimension: "",
        timemode: "day",
        timeflag: moment(new Date()).subtract("day").format("yyyyMMDD"),
      }, //全国
      moreQuery: {
        level: "3",
        dimension: "",
        timemode: "day",
        timeflag: moment(new Date()).subtract("day").format("yyyyMMDD"),
      }, //全路段
      equipmentList: [],
      moreDataList: [],
      accessNumber: '',
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 在线设备数量
    async getOnLineCount(subDay = 0) {
      if (subDay) {
        this.query.timeflag = moment(new Date()).subtract(subDay,"day").format("yyyyMMDD")
      }
      const onLineList = await videoOnlineRateCount(this.query);
      if (onLineList.msgState === 'SUCCESS' && onLineList.msgContent.length) {
        this.countInfo = onLineList.msgContent[0] || {}; //全国
      } else {
        // 当天没数据 就查前一天 最多查前两天
        subDay < 2 && this.getOnLineCount(++subDay)
      }
    },
    // 在线设备列表
    async getOnLineList(subDay = 0) {
      if (subDay) {
        this.moreQuery.timeflag = moment(new Date()).subtract(subDay,"day").format("yyyyMMDD")
      }
      const { msgContent, msgState } = await videoOnlineRateCount(this.moreQuery); //全路段
      if (msgState === 'SUCCESS' && msgContent.length) {
        this.list = msgContent; //全路段
      } else {
        // 当天没数据 就查前一天 最多查前两天
        subDay < 2 && this.getOnLineList(++subDay)
      }
    },
    async getList() {
      //  -----------------       在线设备    ---------------
      this.getOnLineCount()
      this.getOnLineList()
      
      

      //     //  -----------------       故障率    ---------------
      //   const dataList = await GetVideoOnlineTime({...this.query, timeflag:moment(new Date()).subtract(1,"day").format("yyyyMMDD")})
      const dataList = await GetVideoOnlineTime({
        ...this.query,
        timeflag: null,
      });
      this.equipmentList = dataList.msgContent[0]; //全国

      //   const  moreList = await GetVideoOnlineTime({...this.moreQuery,timeflag:moment(new Date()).subtract(1,"day").format("yyyyMMDD")})  //全路段
      const moreList = await GetVideoOnlineTime({
        ...this.moreQuery,
        timeflag: null,
      }); //全路段
      this.moreDataList = moreList.msgContent; //全路段
      // this.moreDataList.map((item)=>{
      //   item.allOfflineTime=String(item.allOfflineTime)
      // })
      // console.log(145, this.moreDataList );


      // 计算接入数
      let accessNumber = 0
      this.moreDataList.map(item => {
        item.allCount && (accessNumber += Number(item.allCount))
      })
      this.accessNumber = accessNumber
    },
  },
};
</script>

<style lang="scss" scoped>
.eq-page {
  width: 100%;
  padding: 1px;
  .eqpage-top {
    width: 100%;
    display: flex;
    justify-content: space-around;
    // align-items: center;
    margin-top: 16px;
  }
  .eqtiop-left {
    width: 110px;
    height: 80px;
    background: url("@/assets/images/videoSurveillance/zxlicon.png");
    background-size: 100% 100%;
    text-align: center;
  }
  .eqtiop-left2 {
    background: url("@/assets/images/videoSurveillance/gzlicon.png");
    background-size: 100% 100%;
  }
  .eq-left-text1 {
    position: relative;
    top: -15px;
    font-size: 26px;
    font-family: "DinNextRegular";
    font-weight: bold;
    text-shadow: 0 0 10px #053ffd;
  }
  .eq-left-text2 {
    position: relative;
    top: -20px;
    font-size: 16px;
    font-family: "YouSheBiaoTiHei";
  }
  .eqtiop-right {
    width: 55%;
  }
  .eq-cont-text {
    width: 100%;
    height: 20px;
    line-height: 0;
    text-align: center;
    background: url("@/assets/images/videoSurveillance/video-rig-bg.png");
    background-size: 100% 100%;
  }

  .eq-rig-flex-top {
    margin-top: 10px;
    width: 100%;
    display: flex;
    justify-content: space-between;
  }
  .eq-rig-flex {
    display: flex;
  }
  .eqsta-icon {
    margin-right: 5px;
    width: 45px;
    height: 45px;
    background: url("@/assets/images/videoSurveillance/video-icon2.png");
    background-size: 100% 100%;
  }
  .eqsta-icon-1 {
    background: url("@/assets/images/videoSurveillance/video-icon4.png");
    background-size: 100% 100%;
  }
  .eqsta-icon1 {
    margin-right: 5px;
    width: 45px;
    height: 45px;
    background: url("@/assets/images/videoSurveillance/video-icon3.png");
    background-size: 100% 100%;
  }
  .eqsta-icon1-1 {
    background: url("@/assets/images/videoSurveillance/video-icon5.png");
    background-size: 100% 100%;
  }
  .eqimp-text1 {
    font-size: 18px;
    font-family: "DinNextRegular";
    font-weight: 400;
  }
  .eqimp-text2 {
    color: #83afcf;
  }
  .eqimp-text3 {
    display: inline-block;
    font-size: 22px;
    font-family: "DinNextRegular";
    margin-left: 10px;
  }
  .eq-list-cell {
    width: 90%;
    margin: auto;
    margin-bottom: 5px;
    display: flex;
    background: rgba(35, 62, 92, 0.35);
    border: 1px solid rgba(84, 122, 164, 0.5);
    border-radius: 2px;
  }
  .eq-list-cell1 {
    padding: 8px 12px;
    margin-top: 12px;
    font-size: 12px;
    color: #94a8c6;
  }
  .eq-list-cell2 {
    padding: 2px 12px 6px 12px;
    align-items: center;
  }
  .eq-cell-text1 {
    position: relative;
    top: 2px;
    width: 25%;
    font-size: 14px;
    color: #c9e8ff;
  }
  .eq-cell-text2 {
    width: 18%;
    font-size: 18px;
    font-family: "DinNextRegular";
  }
  .eq-cell-text3 {
    width: 19%;
    color: #65ffc7;
    font-size: 18px;
    font-family: "DinNextRegular";
  }
  .eq-cell-text4 {
    width: 26%;
    color: #ff5a5a;
    font-size: 18px;
    font-family: "DinNextRegular";
  }
  .eq-cell-text5 {
    font-size: 18px;
    font-family: "DinNextRegular";
    width: 17%;
  }

  .eq-cell-text1-1 {
    position: relative;
    top: 2px;
    width: 25%;
    font-size: 14px;
    color: #c9e8ff;
  }
  .eq-cell-text2-1 {
    width: 18%;
    font-size: 18px;
    font-family: "DinNextRegular";
  }
  .eq-cell-text3-1 {
    width: 19%;
    color: #65ffc7;
    font-size: 18px;
    font-family: "DinNextRegular";
  }
  .eq-cell-text4-1 {
    width: 18%;
    color: #ff5a5a;
    font-size: 18px;
    font-family: "DinNextRegular";
  }
  .eq-cell-text5-1 {
    font-size: 18px;
    font-family: "DinNextRegular";
    width: 17%;
  }

  .eq-list-cell2-out {
    // height: calc(45vh - 200px);
    height: calc(90vh - 200px);
    overflow: auto;
  }
}
</style>
