<template>
  <div class="mile_warp">
    <table class="table_box">
      <colgroup>
        <col width="20%"/>
        <col width="30%"/>
        <col width="25%"/>
        <col width="25%"/>
      </colgroup>
      <thead>
        <tr>
          <td>排名</td>
          <td>车牌号</td>
          <td>昨日里程<br />(km/h)</td>
          <td>轨迹查询</td>
        </tr>
      </thead>
    </table>
    <div style="width:100%;height:4.5rem;overflow-y:auto;">
      <table class="table_box">
        <colgroup>
          <col width="20%"/>
          <col width="30%"/>
          <col width="25%"/>
          <col width="25%"/>
        </colgroup>
        <tbody>
          <tr v-for="(item, index) in carMile" :key="'car' + index">
            <td>{{ index+ 1}}</td>
            <td>{{ item.cardNo }}</td>
            <td>{{ item.mile }}</td>
            <td><a :href="`https://lcrm3.lunz.cn/#/Equipment/LocatMonitor/Path/${item.key}`" target="_blank">查询</a></td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import { lunzApi, key, carList } from "@/api/data";
export default {
  data() {
    return {
      carList: carList,//车辆设备
      carMile: [],
    }
  },
  mounted() {
    this.queryYesterdayMile();
  },
  methods: {
    //昨日里程
    queryYesterdayMile() {
      lunzApi.getYesterdayMile(key).then(res => {
        let resData = res.Data;
        this.carList.map(item => {
          let idx = resData.findIndex(item2 => item2.Imei == item.deviceId);
          item.mile = idx > -1 ? res.Data[idx].Mile : 0;
          this.carMile.push(item);
        })
        this.carMile.sort((a, b) => {
          return b.mile - a.mile;
        })
      })
    },
  },
}
</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;
      }
    }
    a{
      color:#0e94ea;
      text-decoration: none;
    }
  }
}
</style>