diff --git a/pages/order/aftersale/apply.vue b/pages/order/aftersale/apply.vue index 48d0109..62d285c 100644 --- a/pages/order/aftersale/apply.vue +++ b/pages/order/aftersale/apply.vue @@ -43,8 +43,8 @@ @tap="state.showModal = true" > 退款金额 - - ¥{{ fen2yuan(state.item.payPrice) }} + + ¥{{ fen2yuan(state.payPrice) }} @@ -130,6 +130,7 @@ order: {}, // 订单 item: {}, // 订单项 config: {}, // 交易配置 + payPrice: 0, // 退款金额:单品取item.payPrice,整单取外层order.payPrice // 售后类型 wayList: [ @@ -157,8 +158,8 @@ // 提交表单 async function submit() { let data = { - orderItemId: state.item.id, - refundPrice: state.item.payPrice, + orderItemId: state.item?.id, + refundPrice: state.payPrice, ...formData, }; const { code } = await AfterSaleApi.createAfterSale(data); @@ -210,22 +211,37 @@ } onLoad(async (options) => { - // 解析参数 - if (!options.id || !options.id) { + // 解析参数:兼容单品入口(传orderId+itemId)和整单入口(传订单对象即props.data.id) + const orderId = parseInt(options.orderId || options.id); + const itemId = options.itemId ? parseInt(options.itemId) : 0; + if (!orderId) { sheep.$helper.toast(`缺少订单信息,请检查`); return; } - state.orderId = options.id; - state.itemId = parseInt(options.itemId); + state.orderId = orderId; + state.itemId = itemId; // 读取订单信息 const { code, data } = await OrderApi.getOrderDetail(state.orderId); if (code !== 0) { return; } - // console.log('aaa',data); state.order = data; - state.item = data.items.find((item) => item.orderId == state.orderId) || {}; + + // 按itemId精确查找订单项(单品入口),否则默认取第1项(整单入口仅用于商品卡片展示) + if (state.itemId > 0) { + state.item = data.items.find((item) => item.id === state.itemId) || {}; + } else { + state.item = data.items?.[0] || {}; + } + + // 退款金额:单品用订单项的payPrice,整单使用订单外层的payPrice(含randomDiscountPrice等优惠抵扣后的值) + if (state.itemId > 0 && state.item?.id) { + state.payPrice = state.item.payPrice; + } else { + state.payPrice = state.order.payPrice; + } + // 设置选项 if (state.order.status === 10) { state.wayList.splice(1, 1);