Commit e95bf192 by liimin

refactor(order): 重构订单详情页面的按钮逻辑

- 移除了 afterSaleDetail 页面中不必要的样式属性
- 重构了 OrderActionButtons 组件中的按钮逻辑
- 引入了枚举常量,提高了代码的可读性和可维护性
- 优化了条件判断,使按钮显示逻辑更加清晰
- 格式化了代码,提高了代码的整洁度
1 parent 2b2de282
...@@ -121,8 +121,6 @@ ...@@ -121,8 +121,6 @@
border-radius: 20rpx; border-radius: 20rpx;
border: 2rpx solid #dcdfe6; border: 2rpx solid #dcdfe6;
font-size: 24rpx; font-size: 24rpx;
margin-left: 12rpx;
color: #1b233d;
} }
.submit-btn { .submit-btn {
border-color: var(--btnColor); border-color: var(--btnColor);
......
// packageMine/pages/order/index/components/orderActionButtons.js // packageMine/pages/order/index/components/orderActionButtons.js
// 定义枚举常量
const OrderStatus = {
PENDING_PAYMENT: 1, // 待付款
PROCESSING: 2, // 处理中
SHIPPED: 3, // 已发货
DELIVERED: 4, // 已送达
COMPLETED: 5, // 已完成
CANCELLED: 6, // 已取消
REFUNDED: 7, // 已退款
CLOSED: 8, // 已关闭
AFTER_SALE: 9, // 售后中
};
const OrderSource = {
SPECIAL: 5, // 特殊订单(如金币兑换)
};
const AfterSaleStatus = {
PROCESSING: 1, // 售后处理中
};
const DeliveryType = {
EXPRESS: 2, // 快递发货
};
const CouponStatus = {
USED: 2, // 已使用
EXPIRED: 3, // 已过期
};
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -7,18 +38,18 @@ Component({ ...@@ -7,18 +38,18 @@ Component({
item: { item: {
type: Object, type: Object,
value: {}, value: {},
observer: function() { observer: function () {
// 当item变化时重新计算按钮 // 当item变化时重新计算按钮
this.updateButtons(); this.updateButtons();
} },
}, },
hasUserInfo: { hasUserInfo: {
type: Boolean, type: Boolean,
value: false, value: false,
observer: function() { observer: function () {
// 当hasUserInfo变化时重新计算按钮 // 当hasUserInfo变化时重新计算按钮
this.updateButtons(); this.updateButtons();
} },
}, },
}, },
...@@ -27,7 +58,7 @@ Component({ ...@@ -27,7 +58,7 @@ Component({
*/ */
data: { data: {
buttons: [], buttons: [],
orderItem: {} orderItem: {},
}, },
/** /**
...@@ -37,160 +68,194 @@ Component({ ...@@ -37,160 +68,194 @@ Component({
// 获取当前订单应该显示的按钮 // 获取当前订单应该显示的按钮
getButtons() { getButtons() {
const { item, hasUserInfo } = this.data; const { item, hasUserInfo } = this.data;
// 待付款状态按钮策略 // 待付款状态按钮策略
if (item.orderStatus == 1) { if (item.orderStatus == OrderStatus.PENDING_PAYMENT) {
const buttons = [{ const buttons = [
text: '取消付款', {
type: 'cancelPay', text: "取消付款",
class: 'btn pay', type: "cancelPay",
handler: this.onCancelPay.bind(this) class: "btn pay",
}]; handler: this.onCancelPay.bind(this),
},
];
if (item.orderSource != 4) { if (item.orderSource != 4) {
buttons.push({ buttons.push({
text: '去支付', text: "去支付",
type: 'pay', type: "pay",
class: 'btn pay', class: "btn pay",
handler: this.onPay.bind(this) handler: this.onPay.bind(this),
}); });
} }
return buttons; return buttons;
} }
// 特殊订单查看详情策略 // 特殊订单查看详情策略
if (item.orderSource == 5 && (item.orderStatus == 2 || item.orderStatus == 7)) { if (
return [{ item.orderSource == OrderSource.SPECIAL &&
text: '查看详情', (item.orderStatus == OrderStatus.PROCESSING ||
type: 'viewDetail', item.orderStatus == OrderStatus.REFUNDED)
class: 'btn pay', ) {
handler: this.onToGoldDetail.bind(this) return [
}]; {
text: "查看详情",
type: "viewDetail",
class: "btn pay",
handler: this.onToGoldDetail.bind(this),
},
];
} }
// 售后中订单按钮策略 // 售后中订单按钮策略
if (item.afterSaleStatus) { if (item.afterSaleStatus) {
const buttons = []; const buttons = [];
if (item.afterSaleStatus == 1) { if (item.afterSaleStatus == AfterSaleStatus.PROCESSING) {
buttons.push({ buttons.push({
text: '取消售后', text: "取消售后",
type: 'cancelOrder', type: "cancelOrder",
class: 'btn pay', class: "btn pay",
handler: this.onCancelOrder.bind(this) handler: this.onCancelOrder.bind(this),
}); });
} }
buttons.push({ buttons.push({
text: '售后详情', text: "售后详情",
type: 'afterSaleDetail', type: "afterSaleDetail",
class: 'btn', class: "btn",
handler: this.onAfterSaleDetail.bind(this) handler: this.onAfterSaleDetail.bind(this),
}); });
return buttons; return buttons;
} }
// 进行中订单按钮策略 // 进行中订单按钮策略
if (item.orderStatus > 2 && item.orderStatus < 9) { if (
item.orderStatus > OrderStatus.PENDING_PAYMENT &&
item.orderStatus < OrderStatus.AFTER_SALE
) {
const buttons = []; const buttons = [];
// 售后按钮 // 售后按钮
if (item.payPrice > 0 && item.orderSource != 4 && if (
!(item.relatedUserCouponStatus == 2 || item.relatedUserCouponStatus == 3)) { item.payPrice > 0 &&
item.orderSource != 4 &&
!(
item.relatedUserCouponStatus == CouponStatus.USED ||
item.relatedUserCouponStatus == CouponStatus.EXPIRED
)
) {
buttons.push({ buttons.push({
text: '售后', text: "售后",
type: 'afterSale', type: "afterSale",
class: 'btn', class: "btn",
handler: this.onAfterSale.bind(this) handler: this.onAfterSale.bind(this),
}); });
} }
// 确认收货按钮 // 确认收货按钮
if (item.deliveryType == 2 && item.orderStatus == 4) { if (
item.deliveryType == DeliveryType.EXPRESS &&
item.orderStatus == OrderStatus.SHIPPED
) {
buttons.push({ buttons.push({
text: '确认收货', text: "确认收货",
type: 'confirmReceipt', type: "confirmReceipt",
class: 'btn confirm', class: "btn confirm",
handler: this.onConfirmReceipt.bind(this) handler: this.onConfirmReceipt.bind(this),
}); });
} }
// 待评价订单 // 待评价订单
if (item.orderGoods.length == 1 && !hasUserInfo && if (
(item.orderStatus == 5 || item.orderStatus == 8)) { item.orderGoods.length == 1 &&
if (item.evaluatedFlag == 'Y') { !hasUserInfo &&
(item.orderStatus == OrderStatus.COMPLETED ||
item.orderStatus == OrderStatus.CLOSED)
) {
if (item.evaluatedFlag == "Y") {
buttons.push({ buttons.push({
text: '查看评价', text: "查看评价",
type: 'viewEvaluate', type: "viewEvaluate",
class: 'btn confirm', class: "btn confirm",
handler: this.onLookEvaluate.bind(this) handler: this.onLookEvaluate.bind(this),
}); });
} else { } else {
if (!hasUserInfo) { if (!hasUserInfo) {
buttons.push({ buttons.push({
text: '立即评价', text: "立即评价",
type: 'getUserProfile', type: "getUserProfile",
class: 'btn confirm userProfile', class: "btn confirm userProfile",
handler: this.onGetUserProfile.bind(this) handler: this.onGetUserProfile.bind(this),
}); });
} else { } else {
buttons.push({ buttons.push({
text: '立即评价', text: "立即评价",
type: 'evaluate', type: "evaluate",
class: 'btn confirm', class: "btn confirm",
handler: this.onEvaluate.bind(this) handler: this.onEvaluate.bind(this),
}); });
} }
} }
} }
return buttons; return buttons;
} }
// 待评价订单(独立情况) // 待评价订单(独立情况)
if (item.orderGoods.length == 1 && !hasUserInfo && if (
(item.orderStatus == 5 || item.orderStatus == 8)) { item.orderGoods.length == 1 &&
if (item.evaluatedFlag == 'Y') { !hasUserInfo &&
return [{ (item.orderStatus == OrderStatus.COMPLETED ||
text: '查看评价', item.orderStatus == OrderStatus.CLOSED)
type: 'viewEvaluate', ) {
class: 'btn confirm', if (item.evaluatedFlag == "Y") {
handler: this.onLookEvaluate.bind(this) return [
}]; {
text: "查看评价",
type: "viewEvaluate",
class: "btn confirm",
handler: this.onLookEvaluate.bind(this),
},
];
} else { } else {
if (!hasUserInfo) { if (!hasUserInfo) {
return [{ return [
text: '立即评价', {
type: 'getUserProfile', text: "立即评价",
class: 'btn confirm userProfile', type: "getUserProfile",
handler: this.onGetUserProfile.bind(this) class: "btn confirm userProfile",
}]; handler: this.onGetUserProfile.bind(this),
},
];
} else { } else {
return [{ return [
text: '立即评价', {
type: 'evaluate', text: "立即评价",
class: 'btn confirm', type: "evaluate",
handler: this.onEvaluate.bind(this) class: "btn confirm",
}]; handler: this.onEvaluate.bind(this),
},
];
} }
} }
} }
// 默认返回空数组 // 默认返回空数组
return []; return [];
}, },
// 更新按钮 // 更新按钮
updateButtons() { updateButtons() {
const buttons = this.getButtons(); const buttons = this.getButtons();
this.setData({ this.setData({
buttons, buttons,
orderItem: this.data.item orderItem: this.data.item,
}); });
}, },
// 按钮点击事件处理 // 按钮点击事件处理
onButtonClick(e) { onButtonClick(e) {
const { index } = e.currentTarget.dataset; const { index } = e.currentTarget.dataset;
...@@ -199,10 +264,11 @@ Component({ ...@@ -199,10 +264,11 @@ Component({
button.handler(e); button.handler(e);
} }
}, },
// 取消付款 // 取消付款
onCancelPay(e) { onCancelPay(e) {
let { orderCode } = e.currentTarget.dataset.item || e.currentTarget.dataset; let { orderCode } =
e.currentTarget.dataset.item || e.currentTarget.dataset;
wx.showModal({ wx.showModal({
title: "温馨提示", title: "温馨提示",
content: "请问您是否要取消付款", content: "请问您是否要取消付款",
...@@ -278,21 +344,22 @@ Component({ ...@@ -278,21 +344,22 @@ Component({
// 售后 // 售后
onAfterSale(e) { onAfterSale(e) {
let { let {
item: { orderCode, payPrice,goodsNumber }, item: { orderCode, payPrice, goodsNumber },
} = e.currentTarget.dataset; } = e.currentTarget.dataset;
wx.p.router.go( wx.p.router.go(
"/packageMine/pages/order/afterSale_step_two/afterSale_step_two", "/packageMine/pages/order/afterSale_step_two/afterSale_step_two",
{ {
orderCode, orderCode,
refundPrice: payPrice, refundPrice: payPrice,
refundCount:goodsNumber refundCount: goodsNumber,
} }
); );
}, },
// 确认收货 // 确认收货
onConfirmReceipt(e) { onConfirmReceipt(e) {
let { orderCode } = e.currentTarget.dataset.item || e.currentTarget.dataset; let { orderCode } =
e.currentTarget.dataset.item || e.currentTarget.dataset;
wx.showModal({ wx.showModal({
title: "温馨提示", title: "温馨提示",
content: "是否确认收货", content: "是否确认收货",
...@@ -342,7 +409,8 @@ Component({ ...@@ -342,7 +409,8 @@ Component({
// 取消订单 // 取消订单
onCancelOrder(e) { onCancelOrder(e) {
let { orderCode } = e.currentTarget.dataset.item || e.currentTarget.dataset; let { orderCode } =
e.currentTarget.dataset.item || e.currentTarget.dataset;
wx.showModal({ wx.showModal({
title: "温馨提示", title: "温馨提示",
content: "请问您是否要取消售后", content: "请问您是否要取消售后",
...@@ -378,11 +446,11 @@ Component({ ...@@ -378,11 +446,11 @@ Component({
}); });
}, },
}, },
lifetimes: { lifetimes: {
attached() { attached() {
// 组件实例进入页面节点树时执行 // 组件实例进入页面节点树时执行
this.updateButtons(); this.updateButtons();
}
}
});
\ No newline at end of file \ No newline at end of file
},
},
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!