index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/order/index.js
  2. /***
  3. * 订单查询
  4. */
  5. const app = getApp()
  6. import * as API_Order from '../../api/order.js'
  7. import * as Common from '../../utils/common.js'
  8. import {
  9. $wuxToptips,
  10. $wuxToast,
  11. $wuxLoading,
  12. $wuxDialog
  13. } from '../../wux/index.js'
  14. Page({
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. pageParam: {
  20. page_size: 10,
  21. page_no: 1,
  22. order_status: 'ALL'
  23. },
  24. finished: false,
  25. orderList: [],
  26. loading:true
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function(options) {
  32. const bool_o2o=app.globalData.authorInfo.boolO2o
  33. if(bool_o2o===0){
  34. wx.redirectTo({
  35. url:'/pages/noshop/index'
  36. })
  37. }
  38. },
  39. /**
  40. * 生命周期函数--监听页面初次渲染完成
  41. */
  42. onReady: function() {
  43. },
  44. /**
  45. * 生命周期函数--监听页面显示
  46. */
  47. onShow: function() {
  48. //下拉刷新时,可能用户未登录,再返回此页时顶部会一直显示加载状态,这里首先隐藏加载状态
  49. wx.hideNavigationBarLoading()
  50. this.setData({
  51. ['pageParam.page_no']: 1,
  52. finished: false
  53. })
  54. this.getOrderData()
  55. Common.getCurrentShopData().then(res => {
  56. this.getTabBar().init()
  57. })
  58. },
  59. /**
  60. * 生命周期函数--监听页面隐藏
  61. */
  62. onHide: function() {
  63. },
  64. /**
  65. * 生命周期函数--监听页面卸载
  66. */
  67. onUnload: function() {
  68. },
  69. /**
  70. * 页面相关事件处理函数--监听用户下拉动作
  71. */
  72. onPullDownRefresh: function() {
  73. wx.showNavigationBarLoading()
  74. this.setData({
  75. ['pageParam.page_no']: 1,
  76. finished: false,
  77. })
  78. this.getOrderData().then(res => {
  79. wx.hideNavigationBarLoading()
  80. wx.stopPullDownRefresh()
  81. }).catch(error => {
  82. wx.hideNavigationBarLoading()
  83. wx.stopPullDownRefresh()
  84. })
  85. },
  86. /**
  87. * 页面上拉触底事件的处理函数
  88. */
  89. onReachBottom: function() {
  90. if (!this.data.finished) {
  91. this.setData({
  92. ['pageParam.page_no']: this.data.pageParam.page_no + 1
  93. })
  94. this.getOrderData()
  95. }
  96. },
  97. /**
  98. * 用户点击右上角分享
  99. */
  100. onShareAppMessage: function() {
  101. },
  102. getOrderData() {
  103. return new Promise((resolve, reject) => {
  104. let that = this
  105. const authorInfo=app.globalData.authorInfo
  106. if(authorInfo===null||authorInfo===''){ //授权信息不存,不发起请求
  107. return
  108. }
  109. if (authorInfo.boolO2o===0){ //非o2o店铺 不发起请求
  110. return
  111. }
  112. $wuxLoading().show({
  113. text: '加载中...',
  114. })
  115. API_Order.getOrderList(that.data.pageParam).then(res => {
  116. const {
  117. data
  118. } = res
  119. let orders = []
  120. if (that.data.orderList.length === 0 || that.data.pageParam.page_no === 1) {
  121. orders = [...data]
  122. } else {
  123. orders = that.data.orderList
  124. orders.push(...data)
  125. }
  126. if (data.length < 10) {
  127. that.setData({
  128. finished: true
  129. })
  130. }
  131. that.setData({
  132. orderList: orders,
  133. loading:false
  134. })
  135. $wuxLoading().hide()
  136. resolve(res)
  137. }).catch(error => {
  138. $wuxToptips().error({
  139. icon: 'cancel',
  140. hidden: false,
  141. text: error?error.error:error.message,
  142. duration: 3000
  143. })
  144. that.setData({
  145. loading: false
  146. })
  147. reject(error)
  148. })
  149. })
  150. }
  151. })