// pages/distribution/order.js Page({ data: { currentTab: 'all', orders: [], loading: false, page: 1, hasMore: true }, onLoad: function (options) { this.loadOrders() }, // 切换标签 switchTab: function (e) { const tab = e.currentTarget.dataset.tab if (tab === this.data.currentTab) return this.setData({ currentTab: tab, orders: [], page: 1, hasMore: true }) this.loadOrders() }, // 加载订单数据 loadOrders: function () { if (!this.data.hasMore || this.data.loading) return this.setData({ loading: true }) // 模拟API请求 setTimeout(() => { const newOrders = this.getMockOrders() this.setData({ orders: [...this.data.orders, ...newOrders], loading: false, page: this.data.page + 1, hasMore: newOrders.length === 10 // 假设每页10条数据 }) }, 500) }, // 下拉刷新 onPullDownRefresh: function () { this.setData({ orders: [], page: 1, hasMore: true }) this.loadOrders() wx.stopPullDownRefresh() }, // 触底加载更多 loadMore: function () { this.loadOrders() }, // 模拟订单数据(实际开发时替换为真实API) getMockOrders: function () { const statusMap = { pending: '待付款', paid: '已付款', completed: '已完成' } return Array(10).fill(0).map((_, index) => ({ id: this.data.page * 10 + index, createTime: '2025-01-10 11:30:00', status: ['pending', 'paid', 'completed'][Math.floor(Math.random() * 3)], get statusText() { return statusMap[this.status] }, goodsImage: '/static/images/default-goods.png', goodsName: '示例商品名称商品名称商品名称商品名称', price: (Math.random() * 1000).toFixed(2), quantity: Math.floor(Math.random() * 5) + 1, commission: (Math.random() * 100).toFixed(2), get totalAmount() { return (this.price * this.quantity).toFixed(2) } })) } })