<template>
  <div class="deviceWarn">
    <div class="title-top" @click="getDetail">预警管控系统</div>
    <div class="toggle-search">
      <div class="status-yx">
        <div class="now-name">
          <i style="margin: 0px 5px 0px 5px">
            <SvgIcon class="icon" size="14" name="internet-bad" />
          </i>
          <span style="color: #fff">{{ !nowStatus ? '报警信息' : '网络断开' }}</span>
        </div>

        <!-- <div class="now-status">{{ !nowStatus ? nowStatus : 0 }}</div> -->
        <div class="now-status">{{ nowStatus }}</div>
      </div>
    </div>
    <div class="warn-contents">
      <div class="warn-box" v-for="(item, index) in warnList" :key="index">
        <div class="warn-icon">
          <img :src="item.icon" alt="" />
        </div>
        <div class="warn-text">
          <div class="text-n">
            {{ item.name }}
          </div>
        </div>
        <div class="warn-val">
          <div class="val-n"> {{ item.val }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { ref, reactive, defineProps, watch } from 'vue';
  import { SvgIcon } from '/@/components/Icon';
  import { getAssetURL } from '/@/utils/ui';
  let props = defineProps({
    warnData: Array,
  });

  const emit = defineEmits(['goDetail']);
  let nowStatus = ref<any>(0);
  let warnList = reactive<any[]>([
    { name: '报警', icon: getAssetURL('home-container/warning/warn-icon.png'), val: 0 },
    { name: '重大风险预警', icon: getAssetURL('home-container/warning/warn-icon.png'), val: 0 },
    { name: '较大风险预警', icon: getAssetURL('home-container/warning/warn-icon1.png'), val: 0 },
    { name: '一般风险预警', icon: getAssetURL('home-container/warning/warn-icon2.png'), val: 0 },
    { name: '低风险预警', icon: getAssetURL('home-container/warning/warn-icon3.png'), val: 0 },
  ]);

  //跳转详情
  function getDetail() {
    emit('goDetail', 'warning');
  }
  watch(
    () => props.warnData,
    (val) => {
      val.forEach((el) => {
        nowStatus.value = el.netstatus.val;
        warnList[0].val = el.red.val;
        warnList[1].val = el.alarm.val;
        warnList[2].val = el.orange.val;
        warnList[3].val = el.yellow.val;
        warnList[4].val = el.blue.val;
      });
    },
    {
      deep: true,
    }
  );
</script>

<style lang="less" scoped>
  @font-face {
    font-family: 'douyuFont';
    src: url('../../../../../assets/font/douyuFont.otf');
  }

  .deviceWarn {
    width: 100%;
    height: 100%;
    position: relative;

    .title-top {
      position: absolute;
      top: 9px;
      left: 46px;
      color: #fff;
      font-size: 16px;
      font-family: 'douyuFont';
      cursor: pointer;

      &:hover {
        color: #66ffff;
      }
    }

    .toggle-search {
      position: absolute;
      left: 9px;
      top: 37px;
      display: flex;

      .status-yx {
        height: 30px;
        width: 180px;
        background-color: rgba(8, 148, 255, 0.3);
        border: 1px solid #1d80da;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .now-status {
          margin-right: 5px;
          padding-top: 3px;
          font-family: 'douyuFont';
          color: #3df6ff;
        }
      }
    }

    .warn-contents {
      position: absolute;
      top: 66px;
      left: 0;
      height: calc(100% - 66px);
      width: 100%;
      padding: 20px 15px;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;

      .warn-box {
        position: relative;
        width: 396px;
        height: 16px;
        display: flex;
        background: url('../../../../../assets/images/home-container/warn1.png') no-repeat;

        .warn-icon {
          position: absolute;
          left: 10%;
          top: -20px;
          width: 44px;
          height: 35px;

          img {
            width: 100%;
            height: 100%;
          }
        }

        .warn-text {
          width: 168px;
          height: 2px;
          position: absolute;
          left: 22%;
          top: -2px;
          background: url('../../../../../assets/images/home-container/warn7.png') no-repeat;
          background-size: 100% 100%;

          .text-n {
            position: absolute;
            left: 50%;
            top: -10px;
            transform: translate(-50%, 0);
            color: #fff;
          }
        }

        .warn-val {
          position: absolute;
          left: 66%;
          top: -21px;
          width: 94px;
          height: 45px;
          background: url('../../../../../assets/images/home-container/warn8.png') no-repeat;

          .val-n {
            position: absolute;
            left: 50%;
            top: 50%;
            font-size: 14px;
            font-family: 'douyuFont';
            transform: translate(-50%, -52%);
          }
        }

        &:nth-child(1) .val-n {
          color: red;
        }

        &:nth-child(2) .val-n {
          color: #f93825;
        }

        &:nth-child(3) .val-n {
          color: #ff9b17;
        }

        &:nth-child(4) .val-n {
          color: #ffff00;
        }

        &:nth-child(5) .val-n {
          color: #31dbfd;
        }
      }
    }
  }

  :deep .zxm-select-selector {
    width: 100%;
    height: 30px !important;
    padding: 0 11px 0px 25px !important;
    background-color: rgba(8, 148, 255, 0.3) !important;
    border: 1px solid #1d80da !important;
  }

  :deep .zxm-select-selection-item {
    color: #fff !important;
    line-height: 28px !important;
  }

  :deep .zxm-select-arrow {
    color: #fff !important;
  }
</style>
