protocol.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // lionfish_comshop/pages/user/protocol.js
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. list: [],
  11. noMore: false
  12. },
  13. token: '',
  14. pageNum: 1,
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. status.setNavBgColor();
  20. var token = wx.getStorageSync('token');
  21. this.token = token;
  22. this.get_list();
  23. },
  24. /**
  25. * 获取列表
  26. */
  27. get_list: function(){
  28. let that = this;
  29. wx.showLoading();
  30. app.util.request({
  31. url: 'entry/wxapp/index',
  32. data: {
  33. controller: 'article.get_article_list',
  34. token: this.token,
  35. page: this.pageNum
  36. },
  37. dataType: 'json',
  38. success: function (res) {
  39. wx.hideLoading();
  40. if (res.data.code == 0) {
  41. let oldList = that.data.list;
  42. let list = res.data.data;
  43. let h = {};
  44. if(list.length < 30) h.noMore = true;
  45. list = list.concat(oldList);
  46. h.list = list;
  47. that.pageNum++;
  48. that.setData(h)
  49. } else {
  50. let h = {};
  51. h.noMore = true;
  52. if(that.pageNum == 1) h.noData = true;
  53. that.setData(h)
  54. }
  55. }
  56. })
  57. },
  58. onReachBottom: function() {
  59. this.data.noMore || this.get_list();
  60. }
  61. })