Commit e95bf192 by liimin

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

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