<route lang="json5" type="page">
{
  layout: 'default',
  style: {
    navigationBarTitleText: '订单详情',
  },
}
</route>

<template>
  <view class="">
    <wd-cell-group>
      <wd-cell title="订单号" :value="orderDetail.ordersnumber" />
      <wd-cell title="产品名称" :value="orderDetail.ordersproductname" />
      <wd-cell title="产品SN" :value="orderDetail.ordersproductsn" />
      <wd-cell title="订单总金额" :value="`¥${orderDetail.orderstotalprice}`" />
      <wd-cell title="优惠金额" :value="`¥${orderDetail.ordersyhprice}`" />
      <wd-cell title="实付金额" :value="`¥${orderDetail.ordersdiscountprice}`" />
      <wd-cell title="订单状态" :value="getOrderStatus(orderDetail.ordersorderstatus)" />
      <wd-cell title="下单时间" :value="orderDetail.ordersorderdate" />
    </wd-cell-group>

    <!-- 回到订单列表 -->
    <view class="sticky-box-content w-full box-border px-2 pb-2 mt-4">
      <wd-button type="primary" block @click="handleBack">回到订单列表</wd-button>
    </view>
  </view>
</template>

<script lang="ts" setup>
import { useOrderStore } from '@/store/order'
import type { OrderType } from '@/types/order'

const orderStore = useOrderStore()
const currentOrdersId = ref('')
const orderDetail = ref<OrderType>({} as OrderType)

const getOrderDetail = async () => {
  const res = await orderStore.getOrderDetail(currentOrdersId.value)
  orderDetail.value = res
}

const getOrderStatus = (status: number) => {
  const statusMap = {
    0: '待审核',
    1: '已支付',
    2: '已完成',
  }
  return statusMap[status] || '未知状态'
}

function handleBack() {
  uni.navigateTo({
    url: '/pages/order/index',
  })
}

onLoad((query) => {
  currentOrdersId.value = query.ordersid
  getOrderDetail()
})
</script>

<style lang="scss" scoped>
//
</style>
