Commit cb134b98 by liimin

refactor(order): 使用 mock 数据调试订单详情页面

- 添加了 mock 订单数据用于调试
- 实现了订单信息的格式化处理,包括价格数据和优惠券信息
1 parent 2a2e7b22
// packageMine/pages/order/index/components/bottom/bottom.js
Component({
})
\ No newline at end of file \ No newline at end of file
{
"component": true,
"style": "v2"
}
\ No newline at end of file \ No newline at end of file
<view class="block">
<slot></slot>
</view>
\ No newline at end of file \ No newline at end of file
.block{
border-radius: 16rpx;
background-color: #fff;
padding: var(--margin);
}
\ No newline at end of file \ No newline at end of file
...@@ -33,16 +33,124 @@ Page({ ...@@ -33,16 +33,124 @@ Page({
2: "已发货", 2: "已发货",
3: "已收货", 3: "已收货",
}, },
// Mock数据用于调试
mockOrderInfo: {
orderStatus: 5, // 已收货
orderSource: 1,
deliveryCompany: "顺丰快递",
deliveryNumber: "SF1234567890",
deliveryStatus: 3,
merchantName: "海马刀官方旗舰店",
activityBigImg: "https://picsum.photos/200/200",
activityName: "洗车服务券",
orderGoods: [
{
id: "106",
goodsImage: "https://picsum.photos/200/200",
goodsName: "洗车服务券",
specificationData: "1次洗车服务",
retailPrice: "299.00",
activityPrice: null,
goodsNumber: 1,
},
{
id: "107",
goodsImage: "https://picsum.photos/200/200?random=1",
goodsName: "打蜡服务券",
specificationData: "1次打蜡服务",
retailPrice: "199.00",
activityPrice: "159.00",
goodsNumber: 2,
},
],
time: "2023.05.20 12:00:00",
orderCode: "2023052012000001",
shipAddress: "广东省深圳市南山区科技园南区R2-B三楼301室",
outTradeNo: "PAY2023052012000001",
orderPrice: "798.00",
expressFee: "0.00",
payPrice: "699.00",
subOrderCoupon: {
denomination: true,
discountAmount: 10000, // 100元
},
relatedUserCoupon: [
{
discountType: 2,
useChannel: 1,
id: "coupon001",
receiveStartTime: "2023.05.01",
effectiveType: 1,
receiveEndTime: "2023.06.01 23:59:59",
},
],
deliveryType: 1,
orderVerification: {
verificationCode: "VERIFY2023052012000001",
},
},
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
wx.p.router.getRouterParams(options).then(({ orderCode } = {}) => { // 使用mock数据进行调试
if (orderCode) { const useMockData = true; // 设置为true使用mock数据,设置为false使用真实接口
this.getOrderDetail(orderCode);
if (useMockData) {
// 使用mock数据
let { orderObj, mockOrderInfo } = this.data;
// 格式化价格数据
mockOrderInfo.orderGoods.map((e) => {
e.retailPrice = Number(e.retailPrice).toFixed(2);
if (e.activityPrice)
e.activityPrice = Number(e.activityPrice).toFixed(2);
});
mockOrderInfo.orderPrice = Number(mockOrderInfo.orderPrice).toFixed(2);
mockOrderInfo.expressFee = Number(mockOrderInfo.expressFee).toFixed(2);
mockOrderInfo.payPrice = Number(mockOrderInfo.payPrice).toFixed(2);
// 根据订单来源调整订单信息
if (mockOrderInfo.orderSource == 4) {
orderObj[2] = {
label: "商户订单号",
key: "outTradeNo",
};
} }
});
this.setData({
orderInfo: mockOrderInfo,
orderObj,
});
// 设置二维码
if (mockOrderInfo.deliveryType == 1 && mockOrderInfo.orderVerification)
this.setQr(mockOrderInfo.orderVerification.verificationCode);
// 处理优惠券数据
if (mockOrderInfo.relatedUserCoupon) {
let list = mockOrderInfo.relatedUserCoupon.map((item) => {
item.receiveStartTime = item.receiveStartTime;
if (item.effectiveType == 1) {
item.receiveEndTime = item.receiveEndTime;
} else {
item.receiveEndTime = item.receiveEndTime.split(' ')[0];
}
return item;
});
this.setData({
couponsList: list,
});
}
} else {
// 使用真实接口数据
wx.p.router.getRouterParams(options).then(({ orderCode } = {}) => {
if (orderCode) {
this.getOrderDetail(orderCode);
}
});
}
}, },
getOrderDetail(orderCode) { getOrderDetail(orderCode) {
let { orderObj } = this.data; let { orderObj } = this.data;
...@@ -129,4 +237,4 @@ Page({ ...@@ -129,4 +237,4 @@ Page({
qr: QR.createQrCodeImg(`t=1&c=${data}`), qr: QR.createQrCodeImg(`t=1&c=${data}`),
}); });
}, },
}); });
\ No newline at end of file \ No newline at end of file
...@@ -82,13 +82,7 @@ ...@@ -82,13 +82,7 @@
运费: 运费:
<view class="price"><text class="unit">¥</text>{{orderInfo.expressFee}}</view> <view class="price"><text class="unit">¥</text>{{orderInfo.expressFee}}</view>
</view> </view>
<view class="price-item line discounts" wx:if="{{orderInfo.subOrderCoupon.denomination}}">
优惠:
<view class="selected">已选一张</view>
<view class="price"><text class="unit">¥</text>{{(orderInfo.subOrderCoupon.discountAmount)/100}}</view>
</view>
<view class="price-item"> <view class="price-item">
订单金额:
<view class="price sum"><text class="unit">¥</text>{{orderInfo.payPrice}}</view> <view class="price sum"><text class="unit">¥</text>{{orderInfo.payPrice}}</view>
</view> </view>
</view> </view>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!