<template>
  <div class="menjin">
    <div class="block1">
      <layout-title title="设备在线情况"/>
      <div class="options">
        <div v-for="(item,index) in block1OptionsList" :key="index" class="option">
          <div class="title active">{{ item.title }}</div>
          <div class="circular">
            <img :src="item.img" alt="">
          </div>
          <div class="label">
            {{ item.label1 }}：<count-to :start-val="0" :end-val="item.count1" :duration="3600"/>
          </div>
          <div v-if="item.label2" class="label">
            {{ item.label2 }}：<count-to :start-val="0" :end-val="item.count2" :duration="3600"/>
          </div>
        </div>
      </div>
    </div>
    <div class="block2">
      <layout-title title="堆料场进出数据"/>
      <div class="options">
        <div v-for="(item,index) in block2OptionsList" v-if="index != 1" :key="index" class="option">
          <div class="title active">{{ item.title }}</div>
          <div class="items">
            <div v-for="(item1,index1) in item.list" :key="index1" class="item">
              <div class="label">
                {{ item1.label }}：<count-to :start-val="0" :end-val="item1.count" :duration="3600"/>
              </div>
            </div>
          </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 class="table">
          <div class="tr">
            <div class="td">卡口名称</div>
            <div class="td">{{ block3OptionsIndex===0 ? '人员':'车牌' }}</div>
            <div class="td">时间</div>
            <div class="td">状态</div>
          </div>
          <div v-for="(item,index) in block3List" :key="index" class="tr">
            <div class="td line1">{{ item.bayonetname }}</div>
            <div class="td">{{ block3OptionsIndex===0 ? item.username:item.carsign }}</div>
            <div class="td line1">{{ item.chtime.substring(11) }}</div>
            <div class="td">{{ item.entrystatusStr }}</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: {
    layoutTitle,
    CountTo
  },
  props: {
    corpInfoId: {
      type: String,
      default: ''
    },
    area: {
      type: String,
      default: ''
    },
    gangkou: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      block1OptionsList: [
        {
          title: '人员闸机数',
          img: require('../../../assets/map/menjin/ico1.png'),
          label1: '在线数',
          count1: 0
          // label2: '离线数',
          // count2: 0
        },
        {
          title: '车辆闸机数',
          img: require('../../../assets/map/menjin/ico2.png'),
          label1: '在线数',
          count1: 0
          // label2: '离线数',
          // count2: 0
        },
        {
          title: '摄像头数',
          img: require('../../../assets/map/menjin/ico3.png'),
          label1: '摄像头数',
          count1: 0
        }
      ],
      block2OptionsList: [
        {
          title: '今日人员情况',
          list: [
            {
              label: '进堆料场人员数',
              count: 0
            },
            {
              label: '出堆料场人员数',
              count: 0
            },
            {
              label: '堆料场内人员数',
              count: 0
            }
          ]
        },
        {
          title: '今日临时情况',
          list: [
            {
              label: '临时进堆料场人员数',
              count: 0
            },
            {
              label: '临时出堆料场人员数',
              count: 0
            },
            {
              label: '临时堆料场内人员数',
              count: 0
            }
          ]
        },
        {
          title: '今日车辆情况',
          list: [
            {
              label: '进堆料场车辆数',
              count: 0
            },
            {
              label: '出堆料场车辆数',
              count: 0
            },
            {
              label: '堆料场内车辆数',
              count: 0
            }
          ]
        }
      ],
      block3OptionsList: ['人员闸机', '车辆闸机'],
      block3OptionsIndex: 1,
      block3List: [
      ]
    }
  },
  created() {
    this.listPerpleCarGateMachine(1)
    this.getOnlineGateMachine()
    this.getDoorManagement()
    this.obtainPersonnelData()
    this.obtainCarData()
  },
  methods: {
    // 获取车辆数量信息
    obtainCarData() {
      requestFN(
        '/map/getCurrentCarData',
        { route: '/region/access/areaCarType' }
      ).then((data) => {
        this.block2OptionsList[2].list[2].count = data.pd.onlineCarCount
      }).catch((e) => {
      })
    },
    getOnlineGateMachine() {
      requestFN(
        '/map/getOnlineGateEquipment', {
          AREA: this.area,
          CORP_INFO_ID: this.corpInfoId,
          GANGKOU: this.gangkou
        }
      ).then((data) => {
        /* this.block1OptionsList[0].count1 = data.onlinePerGate
        this.block1OptionsList[0].count2 = data.offlinePerGate
        this.block1OptionsList[1].count1 = data.onlineCarGate
        this.block1OptionsList[1].count2 = data.offlineCarGate
        this.block1OptionsList[2].count1 = data.cameraCount*/
        this.block1OptionsList[0].count1 = data.onlinePerGate + data.offlinePerGate
        // this.block1OptionsList[0].count2 =
        this.block1OptionsList[1].count1 = data.onlineCarGate + data.offlineCarGate
        // this.block1OptionsList[1].count2 =
        this.block1OptionsList[2].count1 = data.cameraCount
      }).catch((e) => {
        console.log(e)
      })
    },
    getDoorManagement() {
      // /map/getDoorManagement
      requestFN(
        '/map/getDoorManagement', {
          AREA: this.area,
          CORPINFO_ID: this.corpInfoId,
          GANGKOU: this.gangkou,
          id: '12'
        }
      ).then((data) => {
        // this.block2OptionsList[0].list[0].count = data.inpeopleGate
        // this.block2OptionsList[0].list[1].count = data.outpeopleGate
        this.block2OptionsList[2].list[0].count = data.invehicleGate
        this.block2OptionsList[2].list[1].count = data.outvehicleGate
      }).catch((e) => {
        console.log(e)
      })
    },
    block3OptionsClick(index) {
      this.block3OptionsIndex = index
      this.listPerpleCarGateMachine(index)
    },

    listPerpleCarGateMachine(type) {
      requestFN(
        '/map/getCfdDoorWayRecords',
        {
          id: '12',
          TYPE: type
        }
      ).then((data) => {
        this.block3List = data.data
      }).catch((e) => {
      })
    },
    obtainPersonnelData() {
      requestFN(
        '/map/getCurrentPersonnelData',
        { route: '/deploy/psnmgt/getTheCurrentLocationOfAllEmployeesWhosePersonnelCardsAreOnline' }
      ).then((data) => {
        this.block2OptionsList[0].list[2].count = data.pd.onlinePersonCount
        this.block2OptionsList[0].list[0].count = data.pd.onlinePersonCount + 3
        this.block2OptionsList[0].list[1].count = 3
      }).catch((e) => {
        console.log(e)
      })
    },
    getDoorWayRecords(index) {
      requestFN(
        '/map/getDoorWayRecords?showCount=7&currentPage=1', {
          AREA: this.area,
          CORPINFO_ID: this.corpInfoId,
          GANGKOU: this.gangkou,
          INDEX: index
        }
      ).then((data) => {
        this.block3List = data.varList
        this.$forceUpdate()
      }).catch((e) => {
        console.log(e)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.menjin {
  .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 {
      display: flex;
      justify-content: space-between;
      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;

      .option {
        display: flex;
        flex-direction: column;
        align-items: center;

        .circular {
          margin-top: 5px;
          background-image: url("../../../assets/map/menjin/img1.png");
          background-size: 100% 100%;
          background-repeat: no-repeat;
          width: 50px;
          height: 50px;
          text-align: center;
          padding-top: 13px;

          img {
            width: 30px;
            height: 26px;
            animation: scale 2s infinite;
          }
        }

        .label {
          margin-top: 5px;
          font-size: 12px;
          color: #fff;
        }
      }
    }
  }

  .block2 {
    margin-top: 10px;
    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;

      .option {
        .items {
          display: flex;
          flex-wrap: wrap;
          margin-bottom: 10px;

          .item {
            margin-top: 10px;
            font-size: 12px;
            color: #fff;
            flex-basis: 50%;
          }
        }
      }
    }
  }

  .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;

            &:nth-child(2) {
              flex: none;
              flex-basis: 140px;
            }
            &:nth-child(4) {
              flex-basis: 20px;
            }

            &.green {
              color: #7ccf41;
            }

            &.yellow {
              color: #ffcb05;
            }
          }
        }
      }
    }
  }
}

@keyframes scale {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.8);
  }
  100% {
    transform: scale(1);
  }
}

.line1 {
  width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
