order.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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/forward/lhf",
  45. header: {
  46. "Content-Type": "application/json",
  47. "function":"/v1/user/order/list"
  48. },
  49. method: "POST",
  50. data: { openId: that.openId,pageIndex:that.page,pageSize: that.pageSize,userStatus:that.userStatus},
  51. complete: function( res ) {
  52. console.log(res)
  53. if( res == null || res.data == null ) {
  54. console.error( '网络请求失败' );
  55. return;
  56. }
  57. console.log(res.data.data.rows)
  58. //that.count = res.data.data.count
  59. if (res.data.data.rows.orderInfo == null){
  60. that.count = res.data.data.count
  61. that.setData({
  62. goodsList: res.data.data.rows.orderInfo,
  63. lType:"end"
  64. })
  65. } else{
  66. that.count = res.data.data.count
  67. that.data.goodsList = res.data.data.rows.orderInfo
  68. that.setData({
  69. goodsList: that.data.goodsList,
  70. lType:"false"
  71. })
  72. }
  73. }
  74. })
  75. },
  76. changeTabs: function (e){
  77. var that = this
  78. console.log(e)
  79. that.userStatus = e.detail.currentIndex
  80. that.setData({
  81. lType:"loading"
  82. })
  83. wx.request( {
  84. url: link + "/v1/forward/lhf",
  85. header: {
  86. "Content-Type": "application/json",
  87. "function":"/v1/user/order/list"
  88. },
  89. method: "POST",
  90. data: { openId: that.openId,pageIndex:that.page,pageSize: that.pageSize,userStatus:that.userStatus},
  91. complete: function( res ) {
  92. console.log(res)
  93. if( res == null || res.data == null ) {
  94. console.error( '网络请求失败' );
  95. return;
  96. }
  97. console.log(res.data.data.rows.orderInfo)
  98. //that.count = res.data.data.count
  99. if (res.data.data.rows.orderInfo == null){
  100. that.setData({
  101. goodsList: res.data.data.rows.orderInfo,
  102. lType:"end"
  103. })
  104. } else{
  105. that.data.goodsList = res.data.data.rows.orderInfo
  106. that.setData({
  107. goodsList: res.data.data.rows.orderInfo,
  108. lType:"false"
  109. })
  110. }
  111. }
  112. })
  113. },
  114. /**
  115. * 生命周期函数--监听页面初次渲染完成
  116. */
  117. onReady: function () {
  118. },
  119. /**
  120. * 生命周期函数--监听页面显示
  121. */
  122. onShow: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面隐藏
  126. */
  127. onHide: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面卸载
  131. */
  132. onUnload: function () {
  133. },
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh: function () {
  138. },
  139. /**
  140. * 页面上拉触底事件的处理函数
  141. */
  142. onReachBottom: function () {
  143. //获取数据
  144. var that = this;
  145. if (that.page * that.pageSize >= that.count ){
  146. //提示页码到了
  147. that.setData({
  148. lType:"end"
  149. })
  150. return
  151. }
  152. that.page +=1
  153. wx.request( {
  154. url: link + "/v1/forward/lhf",
  155. header: {
  156. "Content-Type": "application/json",
  157. "function":"/v1/user/order/list"
  158. },
  159. method: "POST",
  160. data: { openId: that.openId,pageIndex:that.page,pageSize: that.pageSize,userStatus:that.userStatus},
  161. complete: function( res ) {
  162. wx.hideLoading();
  163. console.log(res)
  164. for (var i = 0; i < res.data.data.rows.orderInfo.length; i++) {
  165. that.data.goodsList.push( res.data.data.rows.orderInfo[i]);
  166. }
  167. that.setData({
  168. goodsList: that.data.goodsList,
  169. })
  170. console.log(res.data.data.goods_search_response)
  171. if( res == null || res.data == null ) {
  172. console.error( '网络请求失败' );
  173. return;
  174. }
  175. }
  176. })
  177. },
  178. /**
  179. * 用户点击右上角分享
  180. */
  181. // onShareAppMessage: function () {
  182. // }
  183. })