comment.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var app = getApp();
  2. Page({
  3. data: {
  4. commentList: [],
  5. loading: false,
  6. nodata: false,
  7. nomore: false,
  8. },
  9. page: 1,
  10. onLoad: function () {
  11. this.page = 1;
  12. this.loadComment();
  13. },
  14. onShow: function () {
  15. if (!app.globalData.userInfo) {
  16. app.error("请登录后再操作", function () {
  17. setTimeout(function () { wx.navigateBack({}) }, 2000);
  18. });
  19. }
  20. },
  21. onPullDownRefresh: function () {
  22. this.setData({ nodata: false, nomore: false });
  23. this.page = 1;
  24. this.loadComment();
  25. },
  26. onReachBottom: function () {
  27. var that = this;
  28. this.loadComment(function (data) {
  29. if (data.commentList.length == 0) {
  30. app.info("暂无更多数据");
  31. }
  32. });
  33. },
  34. loadComment: function (cb) {
  35. var that = this;
  36. if (that.data.nomore == true || that.data.loading == true) {
  37. return;
  38. }
  39. this.setData({ loading: true });
  40. app.request('/addons/cms/wxapp.my/comment', { page: this.page }, function (data, ret) {
  41. that.setData({
  42. loading: false,
  43. nodata: that.page == 1 && data.commentList.length == 0 ? true : false,
  44. nomore: that.page > 1 && data.commentList.length == 0 ? true : false,
  45. commentList: that.page > 1 ? that.data.commentList.concat(data.commentList) : data.commentList,
  46. });
  47. that.page++;
  48. typeof cb == 'function' && cb(data);
  49. }, function (data, ret) {
  50. that.setData({
  51. loading: false
  52. });
  53. app.error(ret.msg);
  54. });
  55. },
  56. })