<template>
  <div class="mile_warp">
    <table class="table_box">
      <colgroup>
        <col width="40%" />
        <col width="30%" />
        <col width="30%" />
      </colgroup>
      <thead>
        <tr>
          <td>时间</td>
          <td>车牌号</td>
          <td>报警信息</td>
        </tr>
      </thead>
    </table>
    <div style="width:100%;height:1.5rem;overflow-y:auto;">
      <table class="table_box">
        <colgroup>
          <col width="40%" />
          <col width="30%" />
          <col width="30%" />
        </colgroup>
        <tbody>
          <tr v-for="(item, index) in carWarn" :key="'car' + index">
            <td>{{ item.TimeStamp }}</td>
            <td>{{ item.carNo }}</td>
            <td :title="item.MESSCONTENT">{{ item.MESSTYPE }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import { lunzApi, key, carList } from "@/api/data";
import { dateFormat } from "@/util/date";
export default {
  data() {
    return {
      carList: carList,//车辆设备
      carWarn: [],
    }
  },
  mounted() {
    this.queryYesterdayMile();
  },
  methods: {
    //报警信息
    queryYesterdayMile() {
      let now = new Date();
      let yesterDay1 = now.setDate(now.getDate() - 1);
      let param = {
        "StartTime": dateFormat(new Date(yesterDay1), 'yyyy-MM-dd'),
        "EndTime": dateFormat(new Date(), 'yyyy-MM-dd')
      }
      lunzApi.getMessInfoByMessType(key, param).then(res => {
        let resData = res.Data;
        resData.map(item => {
          let idx = this.carList.findIndex(item2 => item2.deviceId == item.Imei);
          item.carNo = idx > -1 ? this.carList[idx].cardNo : '-';
          item.TimeStamp = dateFormat(new Date(TimeStamp), 'yyyy-MM-dd hh:mm:ss')
          this.carWarn.push(item);
        })
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.mile_warp {
  width: 100%;
  height: 100%;
  overflow: hidden;

  .table_box {
    width: 100%;

    tr {
      td {
        font-size: 0.18rem;
        color: #fff;
        padding: 0.08rem 0;
      }
    }
  }
}
</style>