feat(order): 支持通过支付订单号查询订单详情

- 引入 vue 的 watch 方法监听订单 ID 变化
- 新增 PayOrderApi 模块用于查询支付订单
- 在 onLoad 中增加对 payOrderNo 参数的处理逻辑
- 通过 payOrderNo 查询 merchantOrderId 并赋值给订单 ID
- 使用 watch 替代 onShow 中直接调用 getOrderDetail 方法
- 修改 PayOrderApi.getOrder 方法支持 no 参数查询
This commit is contained in:
wuKong
2025-11-24 18:49:10 +08:00
parent 86030de73b
commit 59c34db03f
2 changed files with 30 additions and 4 deletions

View File

@@ -259,7 +259,7 @@
<script setup>
import sheep from '@/sheep';
import { onLoad, onShow } from '@dcloudio/uni-app';
import { reactive, ref } from 'vue';
import { reactive, ref, watch } from 'vue';
import { isEmpty } from 'lodash-es';
import {
fen2yuan,
@@ -269,6 +269,7 @@
} from '@/sheep/hooks/useGoods';
import OrderApi from '@/sheep/api/trade/order';
import DeliveryApi from '@/sheep/api/trade/delivery';
import PayOrderApi from '@/sheep/api/pay/order';
import PickUpVerify from '@/pages/order/pickUpVerify.vue';
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
@@ -429,7 +430,11 @@
onShow(async () => {
//onShow中获取订单列表,保证跳转后页面为最新状态
await getOrderDetail(state.orderInfo.id);
//options.payOrderNo传值的情况下,onLoad 会去查询支付订单
//此时state.orderInfo.id没有值onShow await getOrderDetail会出现异常
//改用watch监听state.orderInfo.id 方式 await getOrderDetail
//await getOrderDetail(state.orderInfo.id);
});
onLoad(async (options) => {
@@ -437,6 +442,17 @@
if (options.id) {
id = options.id;
}
if (options.payOrderNo) {
// 查询支付订单:根据 payOrderNo 取 merchantOrderId merchantOrderId 即 tradeOrderId
// 例小程序商品订单详情path
// -- https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order_center/order_center.html
// -- 配置参考pages/order/detail?payOrderNo=${商品订单号}
// -- ${商品订单号} out_trade_no 为 payOrderNo根据 payOrderNo 取 merchantOrderId merchantOrderId 即 tradeOrderId
const payOrder = await PayOrderApi.getOrder(undefined,undefined, options.payOrderNo);
if (payOrder.code === 0) {
id = payOrder.data?.merchantOrderId || id;
}
}
// TODO 芋艿:【微信物流】下面两个变量,后续接入
state.comeinType = options.comein_type;
if (state.comeinType === 'wechat') {
@@ -444,6 +460,12 @@
}
state.orderInfo.id = id;
});
watch(() => state.orderInfo.id, async (newId) => {
if (newId) {
await getOrderDetail(newId);
}
});
</script>
<style lang="scss" scoped>

View File

@@ -2,11 +2,15 @@ import request from '@/sheep/request';
const PayOrderApi = {
// 获得支付订单
getOrder: (id, sync) => {
getOrder: (id, sync, no) => {
const params = {};
if (id) params.id = id;
if (no) params.no = no;
if (sync !== undefined) params.sync = sync;
return request({
url: '/pay/order/get',
method: 'GET',
params: { id, sync },
params,
});
},
// 提交支付订单