friends-list.js 4.1 KB

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