微信小店联盟带货小程序

list.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // pages/order/list.js
  2. Page({
  3. data: {
  4. currentTab: 'all', // 当前选中的标签
  5. orderList: [], // 订单列表
  6. page: 1,
  7. pageSize: 10,
  8. loading: false,
  9. hasMore: true
  10. },
  11. onLoad(options) {
  12. // 如果从个人中心跳转过来,设置对应的标签
  13. if (options.type) {
  14. this.setData({
  15. currentTab: options.type
  16. })
  17. }
  18. this.getOrderList(true)
  19. },
  20. // 切换标签
  21. switchTab(e) {
  22. const type = e.currentTarget.dataset.type
  23. this.setData({
  24. currentTab: type,
  25. orderList: [],
  26. page: 1,
  27. hasMore: true
  28. })
  29. this.getOrderList(true)
  30. },
  31. // 获取订单列表
  32. getOrderList(refresh = false) {
  33. if (this.data.loading || (!this.data.hasMore && !refresh)) return
  34. this.setData({ loading: true })
  35. // TODO: 调用后端API获取订单列表
  36. // 这里先模拟数据
  37. setTimeout(() => {
  38. const mockOrders = [{
  39. id: '1',
  40. createTime: '2024-01-07 12:00:00',
  41. status: 'pending',
  42. statusText: '待结算',
  43. goods: {
  44. id: '1',
  45. image: '/static/images/goods-1.jpg',
  46. name: '商品名称商品名称商品名称商品名称商品名称',
  47. price: '99.00',
  48. count: 1
  49. },
  50. commission: '9.90',
  51. commissionRate: '10'
  52. }, {
  53. id: '2',
  54. createTime: '2024-01-06 15:30:00',
  55. status: 'settled',
  56. statusText: '已结算',
  57. goods: {
  58. id: '2',
  59. image: '/static/images/goods-2.jpg',
  60. name: '商品名称2',
  61. price: '199.00',
  62. count: 2
  63. },
  64. commission: '39.80',
  65. commissionRate: '10',
  66. settlementTime: '2024-01-07 10:00:00'
  67. }, {
  68. id: '3',
  69. createTime: '2024-01-05 09:30:00',
  70. status: 'invalid',
  71. statusText: '无效',
  72. goods: {
  73. id: '3',
  74. image: '/static/images/goods-3.jpg',
  75. name: '商品名称3',
  76. price: '299.00',
  77. count: 1
  78. },
  79. commission: '0.00',
  80. commissionRate: '10',
  81. invalidReason: '订单已取消'
  82. }]
  83. if (refresh) {
  84. this.setData({
  85. orderList: mockOrders,
  86. loading: false,
  87. page: 2
  88. })
  89. } else {
  90. this.setData({
  91. orderList: [...this.data.orderList, ...mockOrders],
  92. loading: false,
  93. page: this.data.page + 1,
  94. hasMore: this.data.page < 3 // 模拟只有3页数据
  95. })
  96. }
  97. }, 500)
  98. },
  99. // 加载更多
  100. loadMore() {
  101. this.getOrderList()
  102. },
  103. // 下拉刷新
  104. onPullDownRefresh() {
  105. this.getOrderList(true)
  106. wx.stopPullDownRefresh()
  107. }
  108. })