You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
store_node/miniprogram/pages/profile/orders.js

202 lines
5.0 KiB

// pages/profile/orders.js
const toast = require('../../utils/toast.js')
Page({
data: {
currentTab: 'all',
orders: [],
page: 1,
pageSize: 10,
hasMoreOrders: true,
isLoading: false
},
onLoad: function (options) {
// 如果有状态参数,则切换到对应状态选项卡
if (options.status) {
this.setData({
currentTab: options.status
});
}
// 加载订单列表
this.loadOrders(true);
},
// 切换选项卡
switchTab: function (e) {
const tab = e.currentTarget.dataset.tab;
this.setData({
currentTab: tab,
orders: [],
page: 1,
hasMoreOrders: true
});
this.loadOrders(true);
},
// 加载订单列表
loadOrders: function (refresh = false) {
if (this.data.isLoading || (!refresh && !this.data.hasMoreOrders)) {
return;
}
this.setData({ isLoading: true });
if (refresh) {
wx.showLoading({
title: '加载中...',
});
}
// 模拟请求数据
setTimeout(() => {
// 模拟订单数据 - 只保留二手超市相关订单
const mockOrders = [
{
id: 1,
orderType: '二手商品',
status: 'processing',
statusText: '已付款',
title: 'iPad Pro 2021 二手95新',
price: 4500,
image: '/images/ipad.jpg',
createTime: '2023-05-19 10:15'
},
{
id: 2,
orderType: '二手商品',
status: 'completed',
statusText: '已完成',
title: '微积分教材 同济第七版',
price: 20,
image: '/images/book.jpg',
createTime: '2023-05-17 16:20'
},
{
id: 3,
orderType: '二手商品',
status: 'refund',
statusText: '退款中',
title: '自行车 捷安特 ATX',
price: 800,
image: '/images/bike.jpg',
createTime: '2023-05-16 09:30'
},
{
id: 4,
orderType: '二手商品',
status: 'waiting',
statusText: '待付款',
title: 'AirPods Pro 二代',
price: 1200,
image: '/images/airpods.jpg',
createTime: '2023-05-15 14:20'
},
{
id: 5,
orderType: '二手商品',
status: 'completed',
statusText: '已完成',
title: '学习桌 可调节高度',
price: 150,
image: '/images/table.jpg',
createTime: '2023-05-14 11:45'
}
];
// 根据当前选项卡筛选订单
let filteredOrders = this.data.currentTab === 'all' ?
mockOrders :
mockOrders.filter(item => item.status === this.data.currentTab);
// 模拟分页
const start = (this.data.page - 1) * this.data.pageSize;
const end = start + this.data.pageSize;
const pageOrders = filteredOrders.slice(start, end);
// 更新数据
if (refresh) {
this.setData({
orders: pageOrders,
hasMoreOrders: pageOrders.length === this.data.pageSize,
page: this.data.page + 1,
isLoading: false
});
wx.hideLoading();
wx.stopPullDownRefresh();
} else {
this.setData({
orders: [...this.data.orders, ...pageOrders],
hasMoreOrders: pageOrders.length === this.data.pageSize,
page: this.data.page + 1,
isLoading: false
});
}
}, 1000);
},
// 加载更多
loadMore: function () {
if (!this.data.isLoading && this.data.hasMoreOrders) {
this.loadOrders();
}
},
//雷雨田2025.8.30添加
confirmOrder() {
if (!this.data.address) {
wx.showToast({ title: '请选择地址', icon: 'none' })
return
}
wx.showToast({ title: '下单成功', icon: 'success' })
},
// 下拉刷新
onPullDownRefresh: function () {
this.setData({
page: 1,
hasMoreOrders: true
});
this.loadOrders(true);
},
// 查看订单详情
viewOrderDetail: function (e) {
const orderId = e.currentTarget.dataset.id;
wx.navigateTo({
url: `/pages/profile/order_detail?id=${orderId}`
});
},
// 取消订单
cancelOrder: function (e) {
const orderId = e.currentTarget.dataset.id;
wx.showModal({
title: '确认取消',
content: '确定要取消此订单吗?',
success: (res) => {
if (res.confirm) {
// 模拟取消订单
wx.showLoading({
title: '处理中...',
});
setTimeout(() => {
wx.hideLoading();
// 更新本地订单状态或重新加载订单列表
const orders = this.data.orders.filter(item => item.id !== orderId);
this.setData({
orders: orders
});
wx.showToast({
title: '订单已取消',
icon: 'success'
});
}, 1000);
}
}
});
}
})