微信小店联盟带货小程序

order.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // pages/distribution/order.js
  2. Page({
  3. data: {
  4. currentTab: 'all',
  5. orders: [],
  6. loading: false,
  7. page: 1,
  8. hasMore: true
  9. },
  10. onLoad: function (options) {
  11. this.loadOrders()
  12. },
  13. // 切换标签
  14. switchTab: function (e) {
  15. const tab = e.currentTarget.dataset.tab
  16. if (tab === this.data.currentTab) return
  17. this.setData({
  18. currentTab: tab,
  19. orders: [],
  20. page: 1,
  21. hasMore: true
  22. })
  23. this.loadOrders()
  24. },
  25. // 加载订单数据
  26. loadOrders: function () {
  27. if (!this.data.hasMore || this.data.loading) return
  28. this.setData({ loading: true })
  29. // 模拟API请求
  30. setTimeout(() => {
  31. const newOrders = this.getMockOrders()
  32. this.setData({
  33. orders: [...this.data.orders, ...newOrders],
  34. loading: false,
  35. page: this.data.page + 1,
  36. hasMore: newOrders.length === 10 // 假设每页10条数据
  37. })
  38. }, 500)
  39. },
  40. // 下拉刷新
  41. onPullDownRefresh: function () {
  42. this.setData({
  43. orders: [],
  44. page: 1,
  45. hasMore: true
  46. })
  47. this.loadOrders()
  48. wx.stopPullDownRefresh()
  49. },
  50. // 触底加载更多
  51. loadMore: function () {
  52. this.loadOrders()
  53. },
  54. // 模拟订单数据(实际开发时替换为真实API)
  55. getMockOrders: function () {
  56. const statusMap = {
  57. pending: '待付款',
  58. paid: '已付款',
  59. completed: '已完成'
  60. }
  61. return Array(10).fill(0).map((_, index) => ({
  62. id: this.data.page * 10 + index,
  63. createTime: '2025-01-10 11:30:00',
  64. status: ['pending', 'paid', 'completed'][Math.floor(Math.random() * 3)],
  65. get statusText() {
  66. return statusMap[this.status]
  67. },
  68. goodsImage: '/static/images/default-goods.png',
  69. goodsName: '示例商品名称商品名称商品名称商品名称',
  70. price: (Math.random() * 1000).toFixed(2),
  71. quantity: Math.floor(Math.random() * 5) + 1,
  72. commission: (Math.random() * 100).toFixed(2),
  73. get totalAmount() {
  74. return (this.price * this.quantity).toFixed(2)
  75. }
  76. }))
  77. }
  78. })