|
|
@@ -2,11 +2,13 @@ import PageContainerBehavior from "../../../../core/behavior/page-container.beha
|
|
|
import tickleBehavior, {
|
|
|
getTickleContext,
|
|
|
} from "../../../../core/behavior/tickle.behavior";
|
|
|
+import { handleWeChatPayment } from "../../../../utils/util";
|
|
|
import {
|
|
|
orderListMethod,
|
|
|
orderCancelMethod,
|
|
|
orderPayMethod,
|
|
|
} from "../../request";
|
|
|
+
|
|
|
// module/article/pages/order-list/order-list.ts
|
|
|
Page({
|
|
|
behaviors: [PageContainerBehavior, tickleBehavior],
|
|
|
@@ -20,7 +22,8 @@ Page({
|
|
|
id: "",
|
|
|
statusObj: {
|
|
|
0: "待付款",
|
|
|
- 6: "待收货",
|
|
|
+ // 6: "待收货",
|
|
|
+ 6: "已付款",
|
|
|
345: "交易成功",
|
|
|
2: "交易关闭",
|
|
|
},
|
|
|
@@ -35,15 +38,15 @@ Page({
|
|
|
payingId: '',
|
|
|
showAddress: false,
|
|
|
// 节流控制
|
|
|
- throttleTimers: {} as Record<string, boolean>, // 存储各个按钮的节流定时器
|
|
|
+ throttleTimers: {} as Record<string, boolean>,
|
|
|
+ expandedItems: {} as Record<string, boolean>,
|
|
|
},
|
|
|
computed: {},
|
|
|
- // 节流函数 - 防止短时间内重复点击
|
|
|
+ // 节流 - 防止短时间内重复点击
|
|
|
throttle(func: Function, delay: number = 1000, key: string = "default") {
|
|
|
return (...args: any[]) => {
|
|
|
// 如果该按钮正在节流中,直接返回
|
|
|
if (this.data.throttleTimers[key]) {
|
|
|
- console.log(`按钮 ${key} 正在节流中,忽略点击`);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -70,18 +73,9 @@ Page({
|
|
|
console.log(options, "options");
|
|
|
const tab = options?.tab || "all";
|
|
|
this.setData({ currentTab: tab });
|
|
|
- // this.filterOrdersList(tab);
|
|
|
},
|
|
|
onShow() {
|
|
|
this.filterOrdersList(this.data.currentTab);
|
|
|
- // 读取地址
|
|
|
- // if (JSON.stringify(this.data.selectedAddress) !== "{}") {
|
|
|
- // this.setData({
|
|
|
- // name: this.data.selectedAddress?.liaison,
|
|
|
- // phone: this.data.selectedAddress?.phone,
|
|
|
- // address: this.data.selectedAddress?.fullAddress,
|
|
|
- // });
|
|
|
- // }
|
|
|
},
|
|
|
// 切换tab
|
|
|
onTabChange(event: any) {
|
|
|
@@ -119,7 +113,35 @@ Page({
|
|
|
} else {
|
|
|
item.showAddress = true;
|
|
|
}
|
|
|
+ console.log(item.items, "item============");
|
|
|
+ if (item.items && Array.isArray(item.items)) {
|
|
|
+ item.items = item.items.map((subItem: any) => {
|
|
|
+ return {
|
|
|
+ id: subItem.id || '',
|
|
|
+ name: subItem.conditioningProgramName || '',
|
|
|
+ description: (() => {
|
|
|
+ const dose = subItem?.convertDose ?? '';
|
|
|
+ const unit = subItem?.convertUnit ?? '次';
|
|
|
+ return `${dose} ${unit}`;
|
|
|
+ })(),
|
|
|
+ // isOffline: subItem?.isOffline,
|
|
|
+ photo: subItem.conditioningProgramPhoto || '',
|
|
|
+ price: subItem.totalPrice || 0,
|
|
|
+ quantity: subItem?.totalMeasure || 0,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 批量初始化展开状态为false(默认折叠)
|
|
|
+ const expandedItems: Record<string, boolean> = {};
|
|
|
+ res.data.forEach((item: any) => {
|
|
|
+ if (!this.data.expandedItems[item.id]) {
|
|
|
+ expandedItems[item.id] = false;
|
|
|
+ }
|
|
|
});
|
|
|
+ if (Object.keys(expandedItems).length > 0) {
|
|
|
+ this.setData({ expandedItems: { ...this.data.expandedItems, ...expandedItems } });
|
|
|
+ }
|
|
|
this.setData({ orders: res.data });
|
|
|
}
|
|
|
},
|
|
|
@@ -136,14 +158,18 @@ Page({
|
|
|
case "pending":
|
|
|
this.getOrderList("0");
|
|
|
break;
|
|
|
- // 待收货订单
|
|
|
- case "received":
|
|
|
+ // 已付款订单
|
|
|
+ case "paid":
|
|
|
this.getOrderList("6");
|
|
|
break;
|
|
|
// 交易完成订单
|
|
|
case "completed":
|
|
|
this.getOrderList("345");
|
|
|
break;
|
|
|
+ // 交易关闭订单
|
|
|
+ case "closed":
|
|
|
+ this.getOrderList("2");
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -156,13 +182,36 @@ Page({
|
|
|
if (this.data.payingId) return; // 防重复
|
|
|
this.setData({ paying: true, payingId: orderId });
|
|
|
try {
|
|
|
- await orderPayMethod(orderId);
|
|
|
- wx.navigateTo({
|
|
|
- url: "/module/article/pages/success-page/success-page?title=订单支付成功",
|
|
|
- });
|
|
|
+ // 调用支付接口
|
|
|
+ const payResult = await orderPayMethod(orderId);
|
|
|
+ if (payResult && payResult.data) {
|
|
|
+ const paymentParams = payResult.data;
|
|
|
+ handleWeChatPayment(paymentParams, (res: any) => {
|
|
|
+ // 支付成功,跳转到成功页面
|
|
|
+ wx.redirectTo({
|
|
|
+ url: "/module/article/pages/success-page/success-page?title=订单支付成功",
|
|
|
+ });
|
|
|
+ }, (error: any) => {
|
|
|
+ this.setData({ paying: false, payingId: '' });
|
|
|
+ if (error.errMsg === 'requestPayment:fail cancel') {
|
|
|
+ wx.showToast({
|
|
|
+ title: "支付已取消",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: error.errMsg || "支付失败,请重试",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: payResult.errMsg,
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ }
|
|
|
} catch (error: any) {
|
|
|
- this.setData({ paying: false, payingId: '' });
|
|
|
- // getTickleContext.call(this).showWarnMessage(error.errMsg);
|
|
|
wx.showToast({
|
|
|
title: error.errMsg,
|
|
|
icon: "none",
|
|
|
@@ -184,10 +233,6 @@ Page({
|
|
|
title: "暂未开通",
|
|
|
icon: "none",
|
|
|
});
|
|
|
- // const id = event.currentTarget.dataset.id;
|
|
|
- // wx.navigateTo({
|
|
|
- // url: `/module/article/pages/see-logistics/see-logistics?id=${id}`,
|
|
|
- // });
|
|
|
},
|
|
|
2000,
|
|
|
"logistics"
|
|
|
@@ -199,8 +244,7 @@ Page({
|
|
|
(event: any) => {
|
|
|
const orderStatus = event.currentTarget.dataset.status;
|
|
|
const id = event.currentTarget.dataset.id;
|
|
|
- console.log(orderStatus, "切换地址");
|
|
|
- // 根据订单状态判断是否可以切换地址. 待支付状态下可以切换地址
|
|
|
+ // 根据订单状态判断是否可以切换地址. 待付款状态下可以切换地址
|
|
|
if (orderStatus === "0") {
|
|
|
wx.navigateTo({
|
|
|
url:
|
|
|
@@ -284,16 +328,30 @@ Page({
|
|
|
// 订单详情
|
|
|
onOrderDetail(e: any) {
|
|
|
const id = e.currentTarget.dataset.id;
|
|
|
- // const status = e.currentTarget.dataset.status;
|
|
|
- wx.navigateTo({
|
|
|
- url: `/module/article/pages/order-detail/order-detail?id=${id}`,
|
|
|
- });
|
|
|
+ const status = e.currentTarget.dataset.status;
|
|
|
+ console.log(status, "status");
|
|
|
+ if (status === '0') {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: `/module/order/pages/order-detail/order-detail?id=${id}&status=${status}`,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: `/module/order/pages/other-detail/other-detail?id=${id}&status=${status}`,
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
//回到我的页面
|
|
|
-goMine() {
|
|
|
- console.log("goMine");
|
|
|
- wx.redirectTo({
|
|
|
- url: "/pages/mine/mine",
|
|
|
- });
|
|
|
-}
|
|
|
+ goMine() {
|
|
|
+ wx.redirectTo({
|
|
|
+ url: "/pages/mine/mine",
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 切换服务包展开/收起
|
|
|
+ toggleServicePackages(e: any) {
|
|
|
+ const orderId = e.currentTarget.dataset.id;
|
|
|
+ const currentExpanded = this.data.expandedItems[orderId] || false;
|
|
|
+ this.setData({
|
|
|
+ [`expandedItems[${orderId}]`]: !currentExpanded,
|
|
|
+ });
|
|
|
+ },
|
|
|
});
|