<template>
  <div class="renyuan">
    <div class="block1">
      <layout-title title="定位基础信息"/>
      <div class="options">
        <div v-for="(item,index) in block1OptionsList" :key="index" class="option">
          <div class="imger">
            <img :src="item.img" alt="">
          </div>
          <div class="info">
            <div class="label">{{ item.title }}</div>
            <div class="text"><count-to :start-val="0" :end-val="item.count" :duration="3600"/></div>
          </div>
        </div>
      </div>
    </div>
    <div class="block2">
      <layout-title title="定位状态数据"/>
      <div class="options">
        <div class="bg"/>
        <div v-for="(item,index) in block2OptionsList" :key="index" class="option">
          <div class="label">{{ item.title }}：</div>
          <div class="info">
            <span class="count"><count-to :start-val="0" :end-val="item.count" :duration="3600"/></span>
            <span class="company">条</span>
          </div>
        </div>
      </div>
    </div>
    <div class="block3">
      <layout-title title="定位标签状态"/>
      <div class="content">
        <div class="options">
          <div
            v-for="(item,index) in block3OptionsList"
            :key="index"
            :class="['title', {active:index === block3OptionsIndex}]"
            @click="block3OptionsClick(index)"
          >
            {{ item }}
          </div>
        </div>
        <div v-show="block3OptionsIndex=== 0" class="table">
          <div class="tr">
            <div class="td">卡号</div>
            <div class="td">姓名</div>
            <div class="td">状态</div>
          </div>
          <div v-for="(item,index) in block3List" :key="index" class="tr">
            <div class="td">{{ item.cardNo }}</div>
            <div class="td">{{ item.name }}</div>
            <div class="td">{{ item.cardType }}</div>
          </div>
        </div>

        <div v-show="block3OptionsIndex=== 1" class="table">
          <div class="tr">
            <div class="td">车牌号</div>
            <div class="td">状态</div>
          </div>
          <div v-for="(item,index) in block4List" :key="index" class="tr">
            <div class="td">{{ item.name }}</div>
            <div class="td">在线</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import layoutTitle from './title.vue'
import CountTo from 'vue-count-to'
import { requestFN } from '../../../utils/request'

export default {
  components: {
    CountTo,
    layoutTitle
  },
  data() {
    return {
      block1OptionsList: [
        {
          title: '在线员工',
          img: require('../../../assets/map/renyuan/img1ico1.png'),
          count: 0
        },
        {
          title: '在线车辆',
          img: require('../../../assets/map/renyuan/img1ico2.png'),
          count: 0
        },
        {
          title: '内部人员',
          img: require('../../../assets/map/renyuan/img1ico3.png'),
          count: 0
        },
        {
          title: '外协人员',
          img: require('../../../assets/map/renyuan/img1ico4.png'),
          count: 0
        },
        {
          title: '临时人员',
          img: require('../../../assets/map/renyuan/img1ico5.png'),
          count: 0
        }
      ],
      block2OptionsList: [
        {
          title: '电子围栏告警',
          count: 0
        },
        {
          title: '静超时告警',
          count: 0
        },
        {
          title: '超员/缺员告警',
          count: 0
        },
        {
          title: '离岗告警',
          count: 0
        },
        {
          title: '车辆超速告警',
          count: 0
        },
        {
          title: 'SOS求救',
          count: 0
        }
      ],
      block3OptionsList: ['人员定位统计', '车辆定位统计'],
      block3OptionsIndex: 0,
      block3List: [],
      block4List: [],
      timer: ''
    }
  },
  mounted() {
    this.obtainPersonnelData()
    this.personPositioningStatistics()
    this.startPersonnelDataTimer() // 定时获取
    this.obtainCarData()
    this.carPositioningStatistics()
    // this.getAlarmNum()
  },
  destroyed() {
    clearInterval(this.timer) // 关闭定时器
  },
  methods: {
    // 定时五分钟执行一次
    startPersonnelDataTimer() {
      this.timer = setInterval(() => {
        this.obtainPersonnelData()
        this.personPositioningStatistics()
      }, 300000)
    },
    // 车辆定位统计
    carPositioningStatistics() {
      requestFN(
        '/map/carPositioningStatistics',
        { route: '/region/access/getCarRealLocationDataInfor' }
      ).then((data) => {
        this.block4List = data.varList
      }).catch((e) => {
      })
    },
    // 告警
    getAlarmNum() {
      requestFN(
        '/map/getCfdAlarmNum',
        {}
      ).then((data) => {
        data.data.data.forEach(alarm => {
          switch (alarm.type) {
            case '1':
              break
            case '2':
              this.block2OptionsList[3].count += alarm.total
              break
            case '3':
              this.block2OptionsList[2].count += alarm.total
              break
            case '4':
              this.block2OptionsList[2].count += alarm.total
              break
            case '5':
              this.block2OptionsList[1].count = alarm.total
              break
            case '6':
              this.block2OptionsList[5].count += alarm.total
              break
            case '7':
              this.block2OptionsList[0].count = alarm.total
              break
            default:
              break
          }
        })
      }).catch((e) => {
      })
    },
    // 获取车辆数量信息
    obtainCarData() {
      requestFN(
        '/map/getCurrentCarData',
        { route: '/region/access/areaCarType' }
      ).then((data) => {
        this.block1OptionsList.forEach((item, index) => {
          if (item.title === '在线车辆') {
            this.block1OptionsList[index].count = data.pd.onlineCarCount
          }
        })
      }).catch((e) => {
      })
    },
    // 人员定位统计
    personPositioningStatistics() {
      requestFN(
        '/map/personPositioningStatistics',
        { route: '/deploy/psnmgt/getAllEmployees' }
      ).then((data) => {
        this.block3List = data.varList
      }).catch((e) => {
      })
    },
    // 获取人员数量信息
    obtainPersonnelData() {
      requestFN(
        '/map/getCurrentPersonnelData',
        { route: '/deploy/psnmgt/getTheCurrentLocationOfAllEmployeesWhosePersonnelCardsAreOnline' }
      ).then((data) => {
        this.block1OptionsList.forEach((item, index) => {
          if (item.title === '在线员工') {
            this.block1OptionsList[index].count = data.pd.onlinePersonCount
          }
          if (item.title === '内部人员') {
            this.block1OptionsList[index].count = data.pd.internalPersonCount
          }
          if (item.title === '外协人员') {
            this.block1OptionsList[index].count = data.pd.outsourcingPersonCount
          }
          if (item.title === '临时人员') {
            this.block1OptionsList[index].count = data.pd.temporaryPersonCount
          }
        })
        this.block2OptionsList.forEach((item, index) => {
          if (item.title === '临时人员') {
            this.block2OptionsList[index].count = data.pd.temporaryPersonCount
          }
        })
      }).catch((e) => {
      })
    },
    block3OptionsClick(index) {
      this.block3OptionsIndex = index
    }

  }
}
</script>

<style lang="scss" scoped>
.renyuan {
  .title {
    background-image: url("../../../assets/map/menjin/title_on.png");
    background-size: 100% 100%;
    background-repeat: no-repeat;
    width: 113px;
    height: 26px;
    font-size: 14px;
    line-height: 26px;
    text-align: center;
    color: #fff;

    &.active {
      background-image: url("../../../assets/map/menjin/title.png");
    }
  }

  .block1 {
    width: 410px;
    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));

    .options {
      padding: 10px 15px;
      border: 1px solid;
      border-image: linear-gradient(to bottom, rgba(58, 122, 149, 0), rgba(58, 122, 149, 1)) 1;
      border-top: none;
      display: flex;
      flex-wrap: wrap;

      .option {
        display: flex;
        width: 50%;
        align-items: center;
        margin-top: 10px;

        &:nth-child(-n+2) {
          margin-top: 0;
        }

        .imger {
          width: 50px;
          height: 50px;
          background-image: url("../../../assets/map/menjin/img1.png");
          background-size: 100% 100%;
          background-repeat: no-repeat;
          text-align: center;
          margin-left: 20px;

          img {
            width: 30px;
            height: 30px;
            animation: scale 2s infinite;
            margin-top: 10px;
          }
        }

        .info {
          color: #FFFFFF;
          margin-left: 10px;

          .label {
            font-size: 12px;
            height: 25px;
            line-height: 25px;
          }

          .text {
            font-size: 24px;
            background: linear-gradient(to top, #48bbf0, #ffffff);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: bold;
            font-family: "PingFang SC", "Helvetica Neue", "Hiragino Sans GB", "Segoe UI", "Microsoft YaHei", "微软雅黑", sans-serif;
            margin-top: -5px;
          }
        }
      }
    }
  }

  .block2 {
    width: 410px;
    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));
    margin-top: 10px;

    .options {
      padding: 10px 15px;
      border: 1px solid;
      border-image: linear-gradient(to bottom, rgba(58, 122, 149, 0), rgba(58, 122, 149, 1)) 1;
      border-top: none;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      align-items: center;
      position: relative;
      height: 244px;

      .bg {
        background-image: url("../../../assets/map/renyuan/img2.png");
        background-size: 100% 100%;
        background-repeat: no-repeat;
        width: 287px;
        height: 244px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
      }

      .option {
        flex-basis: 35%;
        text-align: center;

        .label {
          font-size: 14px;
          color: #fff;
        }

        .info {
          .count {
            font-size: 24px;
            background: linear-gradient(to top, #48bbf0, #ffffff);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: bold;
            font-family: "PingFang SC", "Helvetica Neue", "Hiragino Sans GB", "Segoe UI", "Microsoft YaHei", "微软雅黑", sans-serif;
          }

          .company {
            font-size: 14px;
            color: #fff;
          }
        }
      }
    }
  }

  .block3 {
    margin-top: 10px;
    width: 410px;
    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));

    .content {
      border: 1px solid;
      border-image: linear-gradient(to bottom, rgba(58, 122, 149, 0), rgba(58, 122, 149, 1)) 1;
      border-top: none;
      padding: 10px;

      .options {
        display: flex;
        justify-content: flex-end;

        .title {
          cursor: pointer;
        }
      }

      .table {
        margin-top: 5px;

        .tr {
          display: flex;

          &:nth-child(odd) {
            background-color: rgba(42, 86, 158, 0.53);
          }

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

@keyframes scale {
  0% {
    transform: scale(0.9);
  }
  50% {
    transform: scale(0.8);
  }
  100% {
    transform: scale(0.9);
  }
}
</style>
