init
This commit is contained in:
472
miniprogram/pages/order/components/order-button-bar/index.js
Normal file
472
miniprogram/pages/order/components/order-button-bar/index.js
Normal file
@@ -0,0 +1,472 @@
|
||||
import Toast from 'tdesign-miniprogram/toast/index';
|
||||
import Dialog from 'tdesign-miniprogram/dialog/index';
|
||||
import { OrderButtonTypes } from '../../config';
|
||||
import { config } from '../../../../config/index';
|
||||
|
||||
Component({
|
||||
options: {
|
||||
addGlobalClass: true,
|
||||
},
|
||||
properties: {
|
||||
order: {
|
||||
type: Object,
|
||||
observer(order) {
|
||||
// 判定有传goodsIndex ,则认为是商品button bar, 仅显示申请售后按钮
|
||||
if (this.properties?.goodsIndex !== null) {
|
||||
const goods = order.goodsList[Number(this.properties.goodsIndex)];
|
||||
this.setData({
|
||||
buttons: {
|
||||
left: [],
|
||||
right: (goods.buttons || []).filter((b) => b.type == OrderButtonTypes.APPLY_REFUND),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 订单的button bar 不显示申请售后按钮
|
||||
const buttonsRight = (order.buttons || [])
|
||||
// .filter((b) => b.type !== OrderButtonTypes.APPLY_REFUND)
|
||||
.map((button) => {
|
||||
//邀请好友拼团按钮
|
||||
if (button.type === OrderButtonTypes.INVITE_GROUPON && order.groupInfoVo) {
|
||||
const {
|
||||
groupInfoVo: { groupId, promotionId, remainMember, groupPrice },
|
||||
goodsList,
|
||||
} = order;
|
||||
const goodsImg = goodsList?.[0]?.imgUrl;
|
||||
const goodsName = goodsList?.[0]?.name;
|
||||
return {
|
||||
...button,
|
||||
openType: 'share',
|
||||
dataShare: {
|
||||
goodsImg,
|
||||
goodsName,
|
||||
groupId,
|
||||
promotionId,
|
||||
remainMember,
|
||||
groupPrice,
|
||||
storeId: order.storeId,
|
||||
},
|
||||
};
|
||||
}
|
||||
return button;
|
||||
});
|
||||
// 删除订单按钮单独挪到左侧
|
||||
const deleteBtnIndex = buttonsRight.findIndex((b) => b.type === OrderButtonTypes.DELETE);
|
||||
let buttonsLeft = [];
|
||||
if (deleteBtnIndex > -1) {
|
||||
buttonsLeft = buttonsRight.splice(deleteBtnIndex, 1);
|
||||
}
|
||||
this.setData({
|
||||
buttons: {
|
||||
left: buttonsLeft,
|
||||
right: buttonsRight,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
goodsIndex: {
|
||||
type: Number,
|
||||
value: null,
|
||||
},
|
||||
isBtnMax: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
|
||||
data: {
|
||||
order: {},
|
||||
buttons: {
|
||||
left: [],
|
||||
right: [],
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
// 点击【订单操作】按钮,根据按钮类型分发
|
||||
onOrderBtnTap(e) {
|
||||
const { type } = e.currentTarget.dataset;
|
||||
switch (type) {
|
||||
case OrderButtonTypes.DELETE:
|
||||
this.onDelete(this.data.order);
|
||||
break;
|
||||
case OrderButtonTypes.CANCEL:
|
||||
this.onCancel(this.data.order);
|
||||
break;
|
||||
case OrderButtonTypes.CONFIRM:
|
||||
this.onConfirm(this.data.order);
|
||||
break;
|
||||
case OrderButtonTypes.PAY:
|
||||
this.onPay(this.data.order);
|
||||
break;
|
||||
case OrderButtonTypes.REMIND_SHIP:
|
||||
this.onRemindShip(this.data.order);
|
||||
break;
|
||||
case OrderButtonTypes.APPLY_REFUND:
|
||||
this.onApplyRefund(this.data.order);
|
||||
break;
|
||||
case OrderButtonTypes.VIEW_REFUND:
|
||||
this.onViewRefund(this.data.order);
|
||||
break;
|
||||
case OrderButtonTypes.COMMENT:
|
||||
this.onAddComment(this.data.order);
|
||||
break;
|
||||
case OrderButtonTypes.INVITE_GROUPON:
|
||||
//分享邀请好友拼团
|
||||
break;
|
||||
case OrderButtonTypes.REBUY:
|
||||
this.onBuyAgain(this.data.order);
|
||||
}
|
||||
},
|
||||
|
||||
onCancel(order) {
|
||||
Dialog.confirm({
|
||||
title: '确认取消订单',
|
||||
content: '确定要取消这个订单吗?取消后无法恢复。',
|
||||
confirmBtn: '确认取消',
|
||||
cancelBtn: '我再想想',
|
||||
})
|
||||
.then(() => {
|
||||
// 显示加载状态
|
||||
wx.showLoading({
|
||||
title: '取消中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 调用取消订单API
|
||||
wx.request({
|
||||
url: `${config.apiBase}/orders/${order.orderNo}/cancel`,
|
||||
method: 'PUT',
|
||||
header: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${wx.getStorageSync('token')}`
|
||||
},
|
||||
data: {
|
||||
order_no: order.orderNo
|
||||
},
|
||||
success: (res) => {
|
||||
wx.hideLoading();
|
||||
|
||||
if (res.statusCode === 200 && res.data.code === 200) {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '订单取消成功',
|
||||
icon: 'check-circle',
|
||||
});
|
||||
|
||||
// 触发刷新事件
|
||||
this.triggerEvent('refresh');
|
||||
} else {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: res.data.message || '取消订单失败',
|
||||
icon: 'error',
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
wx.hideLoading();
|
||||
console.error('取消订单失败:', err);
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '网络错误,请重试',
|
||||
icon: 'error',
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
// 用户取消操作,不做任何处理
|
||||
});
|
||||
},
|
||||
|
||||
onConfirm(order) {
|
||||
Dialog.confirm({
|
||||
title: '确认是否已经收到货?',
|
||||
content: '确认收货后,订单将完成,无法撤销。',
|
||||
confirmBtn: '确认收货',
|
||||
cancelBtn: '取消',
|
||||
})
|
||||
.then(() => {
|
||||
// 显示加载状态
|
||||
wx.showLoading({
|
||||
title: '确认中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 调用确认收货API
|
||||
wx.request({
|
||||
url: `${config.apiBase}/orders/${order.orderNo}/receive`,
|
||||
method: 'PUT',
|
||||
header: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${wx.getStorageSync('token')}`
|
||||
},
|
||||
data: {
|
||||
order_no: order.orderNo
|
||||
},
|
||||
success: (res) => {
|
||||
wx.hideLoading();
|
||||
|
||||
if (res.statusCode === 200 && res.data.code === 200) {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '确认收货成功',
|
||||
icon: 'check-circle',
|
||||
});
|
||||
|
||||
// 触发刷新事件
|
||||
this.triggerEvent('refresh');
|
||||
} else {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: res.data.message || '确认收货失败',
|
||||
icon: 'error',
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
wx.hideLoading();
|
||||
console.error('确认收货失败:', err);
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '网络错误,请重试',
|
||||
icon: 'error',
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
// 用户取消操作,不做任何处理
|
||||
});
|
||||
},
|
||||
|
||||
onPay(order) {
|
||||
// 显示加载状态
|
||||
wx.showLoading({
|
||||
title: '创建支付订单...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 调用支付API
|
||||
wx.request({
|
||||
url: `${config.apiBase}/payment/create`,
|
||||
method: 'POST',
|
||||
header: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${wx.getStorageSync('token')}`
|
||||
},
|
||||
data: {
|
||||
orderNo: order.orderNo,
|
||||
paymentMethod: 'wechat'
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200 && res.data.code === 200) {
|
||||
const paymentData = res.data.data;
|
||||
|
||||
// 如果返回了微信支付参数,调用微信支付SDK
|
||||
if (paymentData && paymentData.payInfo) {
|
||||
wx.hideLoading();
|
||||
wx.showLoading({ title: '调起微信支付...' });
|
||||
|
||||
try {
|
||||
const payInfo = typeof paymentData.payInfo === 'string'
|
||||
? JSON.parse(paymentData.payInfo)
|
||||
: paymentData.payInfo;
|
||||
|
||||
console.log('微信支付参数:', payInfo);
|
||||
|
||||
wx.requestPayment({
|
||||
timeStamp: payInfo.timeStamp,
|
||||
nonceStr: payInfo.nonceStr,
|
||||
package: payInfo.package,
|
||||
signType: payInfo.signType || 'RSA',
|
||||
paySign: payInfo.paySign,
|
||||
success: (payRes) => {
|
||||
wx.hideLoading();
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '支付成功',
|
||||
icon: 'check-circle',
|
||||
});
|
||||
|
||||
// 触发刷新事件
|
||||
this.triggerEvent('refresh');
|
||||
},
|
||||
fail: (payErr) => {
|
||||
wx.hideLoading();
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: payErr.errMsg || '支付失败',
|
||||
icon: 'error',
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (parseErr) {
|
||||
wx.hideLoading();
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '支付参数解析失败',
|
||||
icon: 'error',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 如果没有返回微信支付参数,可能是模拟支付成功
|
||||
wx.hideLoading();
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '支付成功',
|
||||
icon: 'check-circle',
|
||||
});
|
||||
|
||||
// 触发刷新事件
|
||||
this.triggerEvent('refresh');
|
||||
}
|
||||
} else {
|
||||
wx.hideLoading();
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: res.data.message || '创建支付订单失败',
|
||||
icon: 'error',
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
wx.hideLoading();
|
||||
console.error('支付失败:', err);
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '网络错误,请重试',
|
||||
icon: 'error',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onRemindShip(order) {
|
||||
// 显示加载状态
|
||||
wx.showLoading({
|
||||
title: '发送提醒...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 调用提醒发货API
|
||||
wx.request({
|
||||
url: `${config.apiBase}/orders/${order.orderNo}/remind-ship`,
|
||||
method: 'PUT',
|
||||
header: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${wx.getStorageSync('token')}`
|
||||
},
|
||||
success: (res) => {
|
||||
wx.hideLoading();
|
||||
|
||||
if (res.statusCode === 200 && res.data.code === 200) {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '提醒发货成功,商家将尽快处理',
|
||||
icon: 'check-circle',
|
||||
});
|
||||
} else {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: res.data.message || '提醒发货失败',
|
||||
icon: 'error',
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
wx.hideLoading();
|
||||
console.error('提醒发货失败:', err);
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '网络错误,请重试',
|
||||
icon: 'error',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onBuyAgain() {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '你点击了再次购买',
|
||||
icon: 'check-circle',
|
||||
});
|
||||
},
|
||||
|
||||
onApplyRefund(order) {
|
||||
console.log('[订单按钮] 点击申请退款按钮', { orderNo: order?.orderNo, goodsIndex: this.properties.goodsIndex });
|
||||
|
||||
// 如果是商品级别的退款申请(有goodsIndex)
|
||||
if (this.properties.goodsIndex !== null) {
|
||||
const goods = order.goodsList[this.properties.goodsIndex];
|
||||
const params = {
|
||||
orderNo: order.orderNo,
|
||||
skuId: goods?.skuId ?? goods?.id ?? '19384938948343',
|
||||
spuId: goods?.spuId ?? goods?.productId ?? '28373847384343',
|
||||
orderStatus: order.status,
|
||||
logisticsNo: order.logisticsNo,
|
||||
price: goods?.price ?? goods?.actualPrice ?? 89,
|
||||
num: goods?.num ?? goods?.buyQuantity ?? 1,
|
||||
createTime: order.createTime,
|
||||
orderAmt: order.totalAmount,
|
||||
payAmt: order.amount,
|
||||
canApplyReturn: true,
|
||||
};
|
||||
const paramsStr = Object.keys(params)
|
||||
.map((k) => `${k}=${params[k]}`)
|
||||
.join('&');
|
||||
wx.navigateTo({ url: `/pages/order/apply-service/index?${paramsStr}` });
|
||||
} else {
|
||||
// 订单级别的退款申请,跳转到订单详情页
|
||||
if (order?.orderNo) {
|
||||
wx.navigateTo({
|
||||
url: `/pages/order/order-detail/index?orderNo=${order.orderNo}`
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onViewRefund(order) {
|
||||
console.log('[订单按钮] 点击查看退款按钮', { orderNo: order?.orderNo });
|
||||
|
||||
// 跳转到售后列表页面
|
||||
wx.navigateTo({
|
||||
url: '/pages/order/after-service-list/index'
|
||||
});
|
||||
},
|
||||
|
||||
/** 添加订单评论 */
|
||||
onAddComment(order) {
|
||||
// 如果订单只有一个商品,直接跳转到评论页面
|
||||
if (order?.goodsList?.length === 1) {
|
||||
const orderItem = order.goodsList[0];
|
||||
wx.navigateTo({
|
||||
url: `/pages/order/comment/index?orderNo=${order.orderNo}&orderItemId=${orderItem.id}`,
|
||||
});
|
||||
} else {
|
||||
// 如果有多个商品,跳转到评论列表页面让用户选择
|
||||
wx.navigateTo({
|
||||
url: `/pages/order/comment-list/index?orderNo=${order.orderNo}`,
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-toast": "tdesign-miniprogram/toast/toast",
|
||||
"t-dialog": "tdesign-miniprogram/dialog/dialog"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<view class="btn-bar">
|
||||
<view class="left">
|
||||
<t-button
|
||||
wx:for="{{buttons.left}}"
|
||||
wx:key="type"
|
||||
wx:for-item="leftBtn"
|
||||
size="extra-small"
|
||||
shape="round"
|
||||
t-class="{{isBtnMax ? 't-button--max':'t-button'}} order-btn delete-btn"
|
||||
hover-class="order-btn--active"
|
||||
catchtap="onOrderBtnTap"
|
||||
data-type="{{leftBtn.type}}"
|
||||
>
|
||||
{{leftBtn.name}}
|
||||
</t-button>
|
||||
</view>
|
||||
<view class="right">
|
||||
<t-button
|
||||
wx:for="{{buttons.right}}"
|
||||
wx:key="type"
|
||||
wx:for-item="rightBtn"
|
||||
size="extra-small"
|
||||
variant="{{ rightBtn.primary ? 'base' : 'outline'}}"
|
||||
shape="round"
|
||||
t-class="{{isBtnMax ? 't-button--max':'t-button'}} order-btn {{rightBtn.primary ? 'primary' : 'normal'}}"
|
||||
hover-class="order-btn--active"
|
||||
catchtap="onOrderBtnTap"
|
||||
data-type="{{rightBtn.type}}"
|
||||
open-type="{{ rightBtn.openType }}"
|
||||
data-share="{{ rightBtn.dataShare }}"
|
||||
>
|
||||
{{rightBtn.name}}
|
||||
</t-button>
|
||||
</view>
|
||||
</view>
|
||||
<t-toast id="t-toast" />
|
||||
<t-dialog id="t-dialog" />
|
||||
@@ -0,0 +1,54 @@
|
||||
:host {
|
||||
width: 100%;
|
||||
}
|
||||
.btn-bar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
line-height: 1;
|
||||
}
|
||||
.btn-bar .order-btn {
|
||||
line-height: 1;
|
||||
/* border-radius: unset; */
|
||||
/* min-width: 160rpx; */
|
||||
}
|
||||
|
||||
.btn-bar .right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.btn-bar .t-button {
|
||||
width: 160rpx;
|
||||
font-weight: 400;
|
||||
margin-left: 24rpx;
|
||||
}
|
||||
.btn-bar .t-button--max {
|
||||
width: 176rpx;
|
||||
margin-left: 24rpx;
|
||||
|
||||
--td-button-extra-small-height: 72rpx;
|
||||
}
|
||||
|
||||
.btn-bar .left .delete-btn {
|
||||
font-size: 22rpx;
|
||||
}
|
||||
.btn-bar .left .delete-btn::after {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.btn-bar .right .normal {
|
||||
--td-button-default-color: #333333;
|
||||
--td-button-default-border-color: #dddddd;
|
||||
}
|
||||
|
||||
.btn-bar .right .primary {
|
||||
--td-button-default-color: #fff;
|
||||
--td-button-default-bg-color: #fa4126;
|
||||
--td-button-default-border-color: #fa4126;
|
||||
--td-button-default-active-bg-color: #fa42269c;
|
||||
}
|
||||
|
||||
.t-button {
|
||||
--td-button-default-color: #000;
|
||||
--td-button-primary-text-color: #fa4126;
|
||||
}
|
||||
Reference in New Issue
Block a user