|
|
|
@ -240,7 +240,16 @@ |
|
|
|
desc: '快捷安全', |
|
|
|
icon: '/static/payment/alipay.png' |
|
|
|
} |
|
|
|
] |
|
|
|
], |
|
|
|
// 状态文本映射 |
|
|
|
STATUS_TEXT_MAP: { |
|
|
|
'pending_payment': '待付款', |
|
|
|
'paid': '已付款', |
|
|
|
'completed': '已完成', |
|
|
|
'cancelled': '已取消', |
|
|
|
'refunding': '退款中', |
|
|
|
'refunded': '已退款' |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
@ -279,7 +288,7 @@ |
|
|
|
async initPage() { |
|
|
|
await this.loadStudentInfo() |
|
|
|
await this.loadOrders() |
|
|
|
this.updateStatusCounts() |
|
|
|
this.calculateOrderStats() |
|
|
|
}, |
|
|
|
|
|
|
|
async loadStudentInfo() { |
|
|
|
@ -312,7 +321,6 @@ |
|
|
|
async loadOrders() { |
|
|
|
this.loading = true |
|
|
|
try { |
|
|
|
console.log('加载订单列表:', this.studentId) |
|
|
|
|
|
|
|
// 调用真实的订单列表接口 |
|
|
|
const response = await apiRoute.xy_orderTableList({ |
|
|
|
@ -332,10 +340,8 @@ |
|
|
|
// 处理分页信息 |
|
|
|
this.hasMore = response.data?.current_page < response.data?.last_page |
|
|
|
|
|
|
|
// 计算订单统计 |
|
|
|
this.calculateOrderStats() |
|
|
|
this.applyStatusFilter() |
|
|
|
console.log('订单数据加载成功:', this.ordersList) |
|
|
|
// 更新订单显示 |
|
|
|
this.updateOrderDisplay() |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: response.msg || '获取订单列表失败', |
|
|
|
@ -417,42 +423,31 @@ |
|
|
|
|
|
|
|
changeStatus(status) { |
|
|
|
this.activeStatus = status |
|
|
|
this.applyStatusFilter() |
|
|
|
this.updateOrderDisplay() |
|
|
|
}, |
|
|
|
|
|
|
|
applyStatusFilter() { |
|
|
|
updateOrderDisplay() { |
|
|
|
// 同时更新过滤列表和统计数据 |
|
|
|
if (this.activeStatus === 'all') { |
|
|
|
this.filteredOrders = [...this.ordersList] |
|
|
|
} else { |
|
|
|
this.filteredOrders = this.ordersList.filter(order => order.status === this.activeStatus) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
calculateOrderStats() { |
|
|
|
// 更新标签页统计 |
|
|
|
const counts = {} |
|
|
|
this.ordersList.forEach(order => { |
|
|
|
counts[order.status] = (counts[order.status] || 0) + 1 |
|
|
|
}) |
|
|
|
|
|
|
|
this.statusTabs.forEach(tab => { |
|
|
|
if (tab.value === 'all') { |
|
|
|
tab.count = this.ordersList.length |
|
|
|
} else { |
|
|
|
tab.count = counts[tab.value] || 0 |
|
|
|
} |
|
|
|
tab.count = tab.value === 'all' ? this.ordersList.length : (counts[tab.value] || 0) |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getStatusText(status) { |
|
|
|
const statusMap = { |
|
|
|
'pending_payment': '待付款', |
|
|
|
'paid': '已付款', |
|
|
|
'completed': '已完成', |
|
|
|
'cancelled': '已取消', |
|
|
|
'refunding': '退款中', |
|
|
|
'refunded': '已退款' |
|
|
|
} |
|
|
|
return statusMap[status] || status |
|
|
|
return this.STATUS_TEXT_MAP[status] || status |
|
|
|
}, |
|
|
|
|
|
|
|
formatDate(dateString) { |
|
|
|
@ -464,8 +459,67 @@ |
|
|
|
return `${month}-${day} ${hours}:${minutes}` |
|
|
|
}, |
|
|
|
|
|
|
|
// 通用工具方法 |
|
|
|
updateOrderStatus(orderId, statusUpdates) { |
|
|
|
const orderIndex = this.ordersList.findIndex(o => o.id === orderId) |
|
|
|
if (orderIndex !== -1) { |
|
|
|
Object.assign(this.ordersList[orderIndex], statusUpdates) |
|
|
|
} |
|
|
|
this.updateOrderDisplay() |
|
|
|
}, |
|
|
|
|
|
|
|
showOperationSuccess(message, callback) { |
|
|
|
uni.showToast({ |
|
|
|
title: message, |
|
|
|
icon: 'success' |
|
|
|
}) |
|
|
|
if (callback) callback() |
|
|
|
}, |
|
|
|
|
|
|
|
handleError(error, message) { |
|
|
|
console.error(`${message}:`, error) |
|
|
|
uni.showToast({ |
|
|
|
title: message, |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
simulateDelay(ms = 1000) { |
|
|
|
return new Promise(resolve => setTimeout(resolve, ms)) |
|
|
|
}, |
|
|
|
|
|
|
|
getCurrentTimestamp() { |
|
|
|
return new Date().toISOString().slice(0, 19).replace('T', ' ') |
|
|
|
}, |
|
|
|
|
|
|
|
// 统一订单操作处理 |
|
|
|
async executeOrderOperation(operation, config) { |
|
|
|
const { order, statusKey, statusValue, delay = 1000, successMessage, errorMessage, callback } = config |
|
|
|
|
|
|
|
try { |
|
|
|
if (operation.loadingKey) { |
|
|
|
this[operation.loadingKey] = true |
|
|
|
} |
|
|
|
|
|
|
|
await this.simulateDelay(delay) |
|
|
|
|
|
|
|
const updates = { [statusKey]: statusValue } |
|
|
|
if (operation.additionalUpdates) { |
|
|
|
Object.assign(updates, operation.additionalUpdates) |
|
|
|
} |
|
|
|
|
|
|
|
this.updateOrderStatus(order.id, updates) |
|
|
|
this.showOperationSuccess(successMessage, callback) |
|
|
|
} catch (error) { |
|
|
|
this.handleError(error, errorMessage) |
|
|
|
} finally { |
|
|
|
if (operation.loadingKey) { |
|
|
|
this[operation.loadingKey] = false |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
async viewOrderDetail(order) { |
|
|
|
console.log('查看订单详情:', order) |
|
|
|
|
|
|
|
try { |
|
|
|
uni.showLoading({ title: '加载中...' }) |
|
|
|
@ -521,49 +575,24 @@ |
|
|
|
async confirmPayment() { |
|
|
|
if (!this.selectedOrder || this.paying) return |
|
|
|
|
|
|
|
this.paying = true |
|
|
|
try { |
|
|
|
console.log('确认支付:', { |
|
|
|
order_id: this.selectedOrder.id, |
|
|
|
payment_method: this.selectedPaymentMethod |
|
|
|
}) |
|
|
|
|
|
|
|
// 模拟支付 |
|
|
|
await new Promise(resolve => setTimeout(resolve, 2000)) |
|
|
|
const mockResponse = { code: 1, message: '支付成功' } |
|
|
|
|
|
|
|
if (mockResponse.code === 1) { |
|
|
|
uni.showToast({ |
|
|
|
title: '支付成功', |
|
|
|
icon: 'success' |
|
|
|
}) |
|
|
|
|
|
|
|
// 更新订单状态 |
|
|
|
const orderIndex = this.ordersList.findIndex(o => o.id === this.selectedOrder.id) |
|
|
|
if (orderIndex !== -1) { |
|
|
|
this.ordersList[orderIndex].status = 'paid' |
|
|
|
this.ordersList[orderIndex].payment_method = this.selectedPaymentMethod |
|
|
|
this.ordersList[orderIndex].payment_time = new Date().toISOString().slice(0, 19).replace('T', ' ') |
|
|
|
await this.executeOrderOperation( |
|
|
|
{ |
|
|
|
loadingKey: 'paying', |
|
|
|
additionalUpdates: { |
|
|
|
payment_method: this.selectedPaymentMethod, |
|
|
|
payment_time: this.getCurrentTimestamp() |
|
|
|
} |
|
|
|
|
|
|
|
this.closePaymentPopup() |
|
|
|
this.applyStatusFilter() |
|
|
|
this.updateStatusCounts() |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: mockResponse.message || '支付失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
}, |
|
|
|
{ |
|
|
|
order: this.selectedOrder, |
|
|
|
statusKey: 'status', |
|
|
|
statusValue: 'paid', |
|
|
|
delay: 2000, |
|
|
|
successMessage: '支付成功', |
|
|
|
errorMessage: '支付失败', |
|
|
|
callback: () => this.closePaymentPopup() |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('支付失败:', error) |
|
|
|
uni.showToast({ |
|
|
|
title: '支付失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} finally { |
|
|
|
this.paying = false |
|
|
|
} |
|
|
|
) |
|
|
|
}, |
|
|
|
|
|
|
|
async cancelOrder(order) { |
|
|
|
@ -572,48 +601,24 @@ |
|
|
|
content: '确定要取消此订单吗?', |
|
|
|
success: async (res) => { |
|
|
|
if (res.confirm) { |
|
|
|
try { |
|
|
|
console.log('取消订单:', order.id) |
|
|
|
|
|
|
|
// 模拟取消订单 |
|
|
|
await new Promise(resolve => setTimeout(resolve, 500)) |
|
|
|
const mockResponse = { code: 1, message: '取消成功' } |
|
|
|
|
|
|
|
if (mockResponse.code === 1) { |
|
|
|
uni.showToast({ |
|
|
|
title: '取消成功', |
|
|
|
icon: 'success' |
|
|
|
}) |
|
|
|
|
|
|
|
// 更新订单状态 |
|
|
|
const orderIndex = this.ordersList.findIndex(o => o.id === order.id) |
|
|
|
if (orderIndex !== -1) { |
|
|
|
this.ordersList[orderIndex].status = 'cancelled' |
|
|
|
} |
|
|
|
|
|
|
|
this.applyStatusFilter() |
|
|
|
this.updateStatusCounts() |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: mockResponse.message || '取消失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
await this.executeOrderOperation( |
|
|
|
{}, |
|
|
|
{ |
|
|
|
order, |
|
|
|
statusKey: 'status', |
|
|
|
statusValue: 'cancelled', |
|
|
|
delay: 500, |
|
|
|
successMessage: '取消成功', |
|
|
|
errorMessage: '取消失败' |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('取消订单失败:', error) |
|
|
|
uni.showToast({ |
|
|
|
title: '取消失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
viewRefundDetail(order) { |
|
|
|
console.log('查看退款详情:', order) |
|
|
|
const refundInfo = `订单号:${order.order_no}\n退款金额:¥${order.refund_amount || order.total_amount}\n退款时间:${order.refund_time || '处理中'}` |
|
|
|
const refundInfo = `订单号:${order.order_no}\n退款金额:¥${order.refund_amount || order.total_amount}\n退款时间:${order.refund_time || '处理中'}` |
|
|
|
uni.showModal({ |
|
|
|
title: '退款详情', |
|
|
|
content: refundInfo, |
|
|
|
|