<!-- 订单查看 - 物流 -->

<template>
  <div v-if="formData.logisticsId == 0 || formData.logisticsId == null"
    style="text-align: center;margin-top: 50px;font-size: 14px;">
    该订单暂无物流记录
  </div>
  <div v-else class="logistics-container">
    <h3 class="rating-title">{{ formData.logisticsNo }}</h3>
    <div class="content" v-if="formData.picUrl">
      <div class="content-image">
        <img :src="formData.picUrl" alt="评价图片" />
      </div>
    </div>
    <div class="details">
      <p class="product-model">{{ deliveryExpress(formData.logisticsId) }}</p>
      <p class="first-aftersale">运费：{{ fenToYuan(formData.deliveryPrice) }}元</p>
      <p class="first-aftersale">发货时间：{{ formData.deliveryType }}</p>
      <p class="logistics-comment" :title="formData.remark">备注：{{ formData.remark }}</p>
    </div>
  </div>
</template>

<script lang="ts" setup>
// import { computed } from 'vue'
import { propTypes } from '@/utils/propTypes'
import * as TradeOrderApi from '@/api/mall/trade/order'
import { fenToYuan } from '@/utils'
import { formatDate } from '@/utils/formatTime'
import { DICT_TYPE, getDictLabel, getDictObj } from '@/utils/dict'
import * as DeliveryExpressApi from '@/api/mall/trade/delivery/express'

const props = defineProps({
  id: propTypes.number.def(undefined), // 订单ID
  showPickUp: propTypes.bool.def(true) // 显示核销按钮
})
const formData = ref<TradeOrderApi.OrderVO>({
  logs: []
})
const id = props.id
const getOrderLogistics = async () => {
  if (id) {
    const res = (await TradeOrderApi.getOrderLogistics(id)) as TradeOrderApi.OrderVO
    // 没有表单信息则关闭页面返回
    if (!res) {
      message.error('交易订单不存在')
      close()
    }
    formData.value = res
    // console.log(formData.value)
  }
}

const message = useMessage() // 消息弹窗
const deliveryExpress = (id) => {
  for (let index = 0; index < deliveryExpressList.value.length; index++) {
    const element = deliveryExpressList.value[index];
    if (element.id == id) {
      return element.name
    }
  }
}

const deliveryExpressList = ref<DeliveryExpressApi.DeliveryExpressVO[]>([])// 物流公司
onMounted(async () => {
  getOrderLogistics()
  deliveryExpressList.value = await DeliveryExpressApi.getSimpleDeliveryExpressList()
  // await deliveryExpress()
})
</script>

<style src="./OrderComponents.css"  lang="scss" scoped></style>