<template>
  <view class="content">
    <view class="card">
      <u-cell-group :border="false">
        <u-cell>
          <view slot="title" class="title">车牌号</view>
          <view slot="label" class="mt-10">{{ info.LICENCE_NO }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">车牌类型</view>
          <view slot="label" class="mt-10">{{ VEHICLE_LICENSE_PLATE_TYPE_MAP[info.LICENCE_TYPE] }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">车辆类型</view>
          <view slot="label" class="mt-10">{{ VEHICLE_TYPE_MAP[info.VEHICLE_TYPE] }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">范围</view>
          <view slot="label" class="mt-10">{{ VEHICLE_PORT_MAP[info.portId] }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">车辆所属部门</view>
          <view slot="label" class="mt-10">{{ info.DEPT_NAME }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">车辆归属人</view>
          <view slot="label" class="mt-10">{{ info.USER_NAME }}</view>
        </u-cell>
        <u-cell v-if="info.drivingImgs && info.drivingImgs.length > 0">
          <view slot="title" class="title">行驶证照片：</view>
          <view slot="label" class="mt-10">
            <view style="display: flex;flex-wrap: wrap">
              <view v-for="item in info.drivingImgs" :key="item" class="ml-10 mt-10">
                <u--image :showLoading="true" :src="item.FILEPATH" width="80px" height="80px"
                          @click="previewImage(item.FILEPATH, info.drivingImgs)"></u--image>
              </view>
            </view>
          </view>
        </u-cell>
        <u-cell v-if="info.vehicleImgs && info.vehicleImgs.length > 0" >
          <view slot="title" class="title">车辆照片：</view>
          <view slot="label" class="mt-10">
            <view style="display: flex;flex-wrap: wrap">
              <view v-for="item in info.vehicleImgs" :key="item" class="ml-10 mt-10">
                <u--image :showLoading="true" :src="item.FILEPATH" width="80px" height="80px"
                          @click="previewImage(item.FILEPATH, info.vehicleImgs)"></u--image>
              </view>
            </view>
          </view>
        </u-cell>
      </u-cell-group>
    </view>
  </view>
</template>

<script>
import { getVehiclemessageView, getVehicleTypeList } from "@/api";

export default {
  data() {
    return {
      info: {},
      VEHICLE_LICENSE_PLATE_TYPE_MAP: {
        0: "白牌",
        1: "蓝牌",
        2: "黄牌",
        3: "绿牌",
        4: "黑牌",
      },
      VEHICLE_TYPE_MAP: {},
      VEHICLE_PORT_MAP: {
        0: "全部",
        1: "东港区",
        2: "西港区",
      }
    }
  },
  onShow() {
    this.getData()
    this.getVehicleTypes();
  },
  methods: {
    async getData() {
      const resData = await getVehiclemessageView({VEHICLE_ID: this.$route.query.VEHICLE_ID });
      this.info = resData.pd;
      for (let i = 0; i < resData.pd.drivingImgs?.length; i++) {
        this.info.drivingImgs[i].FILEPATH = this.$filePath + resData.pd.drivingImgs[i].filepath;
      }
      for (let i = 0; i < resData.pd.vehicleImgs?.length; i++) {
        this.info.vehicleImgs[i].FILEPATH = this.$filePath + resData.pd.vehicleImgs[i].filepath;
      }
    },
    async getVehicleTypes() {
      const { list } = await getVehicleTypeList();
      const TYPE_LIST = [];
      for (let i = 0; i < list.length; i++){
        TYPE_LIST.push({id: list[i].BIANMA, name: list[i].NAME})
      }
      const TYPE_MAP = new Map(TYPE_LIST.map(item => [item.id, item.name]));
      // 如果你需要将 Map 转换为普通对象
      this.VEHICLE_TYPE_MAP = Object.fromEntries(TYPE_MAP);
    }
  }
}
</script>

<style scoped lang="scss">

</style>
