order.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // pages/order/order.js
  2. const app = getApp()
  3. const link = app.globalData.url
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. page:1,
  10. pageSize:10,
  11. openId:"",
  12. userStatus:0,
  13. goodsList:[],
  14. count:0
  15. },
  16. _asyncData() {
  17. this.setData({
  18. scrollAbleTabs: [
  19. {
  20. tab: '本人订单',
  21. key: '4'
  22. },
  23. {
  24. tab: '好友订单',
  25. key: '1'
  26. }, {
  27. tab: '朋友订单',
  28. key: '6'
  29. }
  30. ],
  31. });
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function (options) {
  37. var that = this;
  38. that.page = 1
  39. that.pageSize = 18
  40. that.openId = wx.getStorageSync('openId')
  41. that.userStatus = 0
  42. // setTimeout(that._asyncData, 0);
  43. wx.request( {
  44. url: link + "/v1/user/order/list",
  45. header: {
  46. "Content-Type": "application/json"
  47. },
  48. method: "POST",
  49. data: { openId: that.openId,pageIndex:that.page,pageSize: that.pageSize,userStatus:that.userStatus},
  50. complete: function( res ) {
  51. console.log(res)
  52. if( res == null || res.data == null ) {
  53. console.error( '网络请求失败' );
  54. return;
  55. }
  56. console.log(res.data.data.rows)
  57. //that.count = res.data.data.count
  58. if (res.data.data.rows.orderInfo == null){
  59. that.count = res.data.data.count
  60. that.setData({
  61. goodsList: res.data.data.rows.orderInfo,
  62. lType:"end"
  63. })
  64. } else{
  65. that.count = res.data.data.count
  66. that.data.goodsList = res.data.data.rows.orderInfo
  67. that.setData({
  68. goodsList: that.data.goodsList,
  69. lType:"false"
  70. })
  71. }
  72. }
  73. })
  74. },
  75. changeTabs: function (e){
  76. var that = this
  77. console.log(e)
  78. that.userStatus = e.detail.currentIndex
  79. that.setData({
  80. lType:"loading"
  81. })
  82. wx.request( {
  83. url: link + "/v1/user/order/list",
  84. header: {
  85. "Content-Type": "application/json"
  86. },
  87. method: "POST",
  88. data: { openId: that.openId,pageIndex:that.page,pageSize: that.pageSize,userStatus:that.userStatus},
  89. complete: function( res ) {
  90. console.log(res)
  91. if( res == null || res.data == null ) {
  92. console.error( '网络请求失败' );
  93. return;
  94. }
  95. console.log(res.data.data.rows.orderInfo)
  96. //that.count = res.data.data.count
  97. if (res.data.data.rows.orderInfo == null){
  98. that.setData({
  99. goodsList: res.data.data.rows.orderInfo,
  100. lType:"end"
  101. })
  102. } else{
  103. that.data.goodsList = res.data.data.rows.orderInfo
  104. that.setData({
  105. goodsList: res.data.data.rows.orderInfo,
  106. lType:"false"
  107. })
  108. }
  109. }
  110. })
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面隐藏
  124. */
  125. onHide: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面卸载
  129. */
  130. onUnload: function () {
  131. },
  132. /**
  133. * 页面相关事件处理函数--监听用户下拉动作
  134. */
  135. onPullDownRefresh: function () {
  136. },
  137. /**
  138. * 页面上拉触底事件的处理函数
  139. */
  140. onReachBottom: function () {
  141. //获取数据
  142. var that = this;
  143. if (that.page * that.pageSize >= that.count ){
  144. //提示页码到了
  145. that.setData({
  146. lType:"end"
  147. })
  148. return
  149. }
  150. that.page +=1
  151. wx.request( {
  152. url: link + "/v1/user/order/list",
  153. header: {
  154. "Content-Type": "application/json"
  155. },
  156. method: "POST",
  157. data: { openId: that.openId,pageIndex:that.page,pageSize: that.pageSize,userStatus:that.userStatus},
  158. complete: function( res ) {
  159. wx.hideLoading();
  160. console.log(res)
  161. for (var i = 0; i < res.data.data.rows.orderInfo.length; i++) {
  162. that.data.goodsList.push( res.data.data.rows.orderInfo[i]);
  163. }
  164. that.setData({
  165. goodsList: that.data.goodsList,
  166. })
  167. console.log(res.data.data.goods_search_response)
  168. if( res == null || res.data == null ) {
  169. console.error( '网络请求失败' );
  170. return;
  171. }
  172. }
  173. })
  174. },
  175. /**
  176. * 用户点击右上角分享
  177. */
  178. // onShareAppMessage: function () {
  179. // }
  180. })