friends-list.js 4.0 KB

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