follow.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // pages/follow/follow.js
  2. const $api = require('../../utils/api.js').API;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. list:[],
  9. page: 1,
  10. total: 0,
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. wx.showLoading({
  17. title: '正在加载',
  18. })
  19. this.setData({
  20. type:options.type,
  21. id:options.id
  22. })
  23. this.getFollow()
  24. if(options.type == 2){
  25. wx.setNavigationBarTitle({
  26. title: '粉丝',
  27. })
  28. }
  29. },
  30. next: function () {
  31. if (this.data.list.length < this.data.total) {
  32. const page = this.data.page + 1
  33. this.setData({
  34. page: page
  35. })
  36. this.getFollow()
  37. }
  38. },
  39. getFollow() {
  40. var list = this.data.list
  41. if(this.data.type == 1){
  42. $api.getMyFollow({
  43. page: this.data.page, page_size: 20,user_id:this.data.id
  44. }).then(res => {
  45. wx.hideLoading()
  46. res.data.data.list.forEach(item => {
  47. list.push(item)
  48. })
  49. this.setData({
  50. list: list,
  51. total: res.data.data.total
  52. })
  53. })
  54. }else{
  55. $api.getFans({
  56. page: this.data.page, page_size: 20,user_id:this.data.id
  57. }).then(res => {
  58. wx.hideLoading()
  59. res.data.data.list.forEach(item => {
  60. list.push(item)
  61. })
  62. this.setData({
  63. list: list,
  64. total: res.data.data.total
  65. })
  66. })
  67. }
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面显示
  76. */
  77. onShow: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面隐藏
  81. */
  82. onHide: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面卸载
  86. */
  87. onUnload: function () {
  88. },
  89. /**
  90. * 页面相关事件处理函数--监听用户下拉动作
  91. */
  92. onPullDownRefresh: function () {
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. */
  97. onReachBottom: function () {
  98. },
  99. /**
  100. * 用户点击右上角分享
  101. */
  102. onShareAppMessage: function () {
  103. }
  104. })