<template>
  <div class="app-container print-work">
    <div class="level-title">
      <h1>卡口信息</h1>
      <div class="level-btns">卡口编号:{{ id }}</div>
    </div>
    <table class="table-ui">
      <tr>
        <td class="bbg-transparent">卡口类型</td>
        <td >
          <template v-if="type.indexOf('PERSON') > -1">
            <span>
              人卡
            </span>
          </template>
          <template v-else>
            <span>
              车卡
            </span>
          </template>
        </td>
        <td class="bbg-transparent">卡口位置</td>
        <td >
          <span>
            {{ infoname }}
          </span>
        </td>
      </tr>

      <!--      <tr>-->
      <!--        <td class="bbg-transparent">卡口位置名称</td>-->
      <!--        <td colspan="3" >{{ '秦皇岛市北京区石家庄镇唐山村' }}</td>-->
      <!--      </tr>-->

      <tr>
        <td class="bbg-transparent">卡口状态</td>
        <td colspan="3" >{{ '在线' }}</td>
      </tr>
    </table>
    <div class="level-title martop">
      <h1>进出记录</h1>
    </div>
    <table class="table-ui">
      <tr v-if="type.indexOf('PERSON') > -1 ">
        <td colspan="4" style="padding: 0;">
          <table class="table-vi">
            <tr class="bbg-transparent">
              <td>序号</td>
              <td>进出位置</td>
              <td>人员姓名</td>
              <td>工号</td>
              <td>进出状态</td>
              <td>进出时间</td>
            </tr>
            <tr v-for="(item, index) in measuresList" :key="item.empNo">
              <td style="text-align: center">{{ index + 1 }}</td>
              <td>{{ item.bayonetname }}</td>
              <td>{{ item.username }}</td>
              <td>{{ item.empNo }}</td>
              <td>{{ item.entrystatusStr }}</td>
              <td>{{ item.chtime }}</td>
            </tr>
          </table>
        </td>
      </tr>
      <tr v-if="type.indexOf('CAR') > -1">
        <td colspan="4" style="padding: 0;">
          <table class="table-vi">
            <tr class="bbg-transparent">
              <td>序号</td>
              <td>进出位置</td>
              <td>车牌号</td>
              <td>操作状态</td>
              <td>进出状态</td>
              <td>进出时间</td>
            </tr>
            <tr v-for="(item, index) in measuresList" :key="item.empNo">
              <td style="text-align: center">{{ index + 1 }}</td>
              <td>{{ item.bayonetname }}</td>
              <td>{{ item.carsign }}</td>
              <td>{{ item.opstatusStr }}</td>
              <td>{{ item.entrystatusStr }}</td>
              <td>{{ item.chtime }}</td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
import { requestFN } from '@/utils/request'
import moment from 'moment'

export default {
  props: {
    id: {
      type: String,
      default() {
        return ''
      }
    },
    type: {
      type: String,
      default() {
        return ''
      }
    },
    infoname: {
      type: String,
      default() {
        return ''
      }
    },
    gangkou: {
      type: String,
      default() {
        return ''
      }
    }
  },
  data() {
    return {
      config: config,
      ISOTHER: false,
      info: {
        OTHER_PROTECTIVE_MEASURES: []
      },
      measuresList: [],
      measuresScheduleList: [],
      icon_type: ''
    }
  },
  created() {
    this.getData()
    this.startPersonnelDataTimer()
    // this.type = this.type.substring(0, this.type.length - 5)
  },
  destroyed() {
    clearInterval(this.timer) // 关闭定时器
  },
  methods: {
    formatDate(date, format) {
      if (date) {
        return moment(date).format(format)
      } else {
        return ''
      }
    },
    getData() {
      requestFN(
        '/map/getGatesInAndOutNumById',
        {
          id: this.id,
          TYPE: this.type.indexOf('00004') > -1 ? this.type.substring(0, this.type.length - 5) : this.type,
          GANGKOU: this.gangkou,
          status: '0'
        }
      ).then((data) => {
        this.info = data.pd
        this.measuresList = data.data

        if (!this.info.OTHER_PROTECTIVE_MEASURES) {
          this.info.OTHER_PROTECTIVE_MEASURES = []
        } else {
          this.info.OTHER_PROTECTIVE_MEASURES = this.info.OTHER_PROTECTIVE_MEASURES.split(';_;')
        }
        this.info.OTHER_PROTECTIVE_MEASURES.some((item, index) => {
          if (this.validStr(item)) {
            this.ISOTHER = true
            return true
          }
        })
      }).catch((e) => {
      })
    },
    // 定时一分钟执行一次
    startPersonnelDataTimer() {
      this.timer = setInterval(() => {
        this.getDataschedule()
        for (let i = 0; i < this.measuresScheduleList.length; i++) {
          this.measuresList.push(this.measuresScheduleList[i])
        }
      }, 60000)
    },
    getDataschedule() {
      requestFN(
        '/map/getGatesInAndOutNumById',
        {
          id: this.id,
          TYPE: this.type.indexOf('00004') > -1 ? this.type.substring(0, this.type.length - 5) : this.type,
          GANGKOU: this.gangkou,
          status: '1'
        }
      ).then((data) => {
        this.measuresScheduleList = data.data
      }).catch((e) => {
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.martop {
  margin-top: 20px;
}
</style>
