headlist.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. list: [],
  9. noData: 0,
  10. tip: '加载中',
  11. isHideLoadMore: true,
  12. level: ''
  13. },
  14. page: 1,
  15. hasMore: true,
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. let level = options.level || '';
  21. this.setData({ level });
  22. if (!util.check_login()) {
  23. wx.redirectTo({
  24. url: '/lionfish_comshop/pages/user/me',
  25. })
  26. }
  27. wx.showLoading();
  28. this.getList();
  29. },
  30. /**
  31. * 生命周期函数--监听页面显示
  32. */
  33. onShow: function () {
  34. },
  35. getList() {
  36. var token = wx.getStorageSync('token');
  37. var that = this;
  38. if (!that.hasMore) { return; }
  39. this.setData({ isHideLoadMore: false })
  40. app.util.request({
  41. 'url': 'entry/wxapp/user',
  42. 'data': {
  43. controller: 'community.get_head_child_headlist',
  44. token: token,
  45. page: that.page,
  46. level: that.data.level
  47. },
  48. dataType: 'json',
  49. success: function (res) {
  50. wx.hideLoading();
  51. if (res.data.code == 0) {
  52. let oldList = that.data.list;
  53. let list = oldList.concat(res.data.data);
  54. that.setData({ list, isHideLoadMore: true })
  55. } else {
  56. if (that.data.list.length == 0 && that.page == 1) that.setData({ noData: 1 })
  57. that.hasMore = false;
  58. }
  59. }
  60. })
  61. },
  62. /**
  63. * 页面相关事件处理函数--监听用户下拉动作
  64. */
  65. onPullDownRefresh: function () {
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. onReachBottom: function () {
  71. this.page++;
  72. this.getList();
  73. }
  74. })