comment.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var api = require('../../config/api.js');
  4. Page({
  5. data: {
  6. comments: [],
  7. allCommentList: [],
  8. picCommentList: [],
  9. type: 0,
  10. valueId: 0,
  11. showType: 0,
  12. allCount: 0,
  13. hasPicCount: 0,
  14. allPage: 1,
  15. picPage: 1,
  16. limit: 20
  17. },
  18. getCommentCount: function() {
  19. let that = this;
  20. util.request(api.CommentCount, {
  21. valueId: that.data.valueId,
  22. type: that.data.type
  23. }).then(function(res) {
  24. if (res.errno === 0) {
  25. that.setData({
  26. allCount: res.data.allCount,
  27. hasPicCount: res.data.hasPicCount
  28. });
  29. }
  30. });
  31. },
  32. getCommentList: function() {
  33. let that = this;
  34. util.request(api.CommentList, {
  35. valueId: that.data.valueId,
  36. type: that.data.type,
  37. limit: that.data.limit,
  38. page: (that.data.showType == 0 ? that.data.allPage : that.data.picPage),
  39. showType: that.data.showType
  40. }).then(function(res) {
  41. if (res.errno === 0) {
  42. if (that.data.showType == 0) {
  43. that.setData({
  44. allCommentList: that.data.allCommentList.concat(res.data.list),
  45. allPage: res.data.page,
  46. comments: that.data.allCommentList.concat(res.data.list)
  47. });
  48. } else {
  49. that.setData({
  50. picCommentList: that.data.picCommentList.concat(res.data.list),
  51. picPage: res.data.page,
  52. comments: that.data.picCommentList.concat(res.data.list)
  53. });
  54. }
  55. }
  56. });
  57. },
  58. onLoad: function(options) {
  59. // 页面初始化 options为页面跳转所带来的参数
  60. this.setData({
  61. type: options.type,
  62. valueId: options.valueId
  63. });
  64. this.getCommentCount();
  65. this.getCommentList();
  66. },
  67. onPullDownRefresh() {
  68. wx.showNavigationBarLoading() //在标题栏中显示加载
  69. this.getCommentCount();
  70. this.getCommentList();
  71. wx.hideNavigationBarLoading() //完成停止加载
  72. wx.stopPullDownRefresh() //停止下拉刷新
  73. },
  74. onReady: function() {
  75. // 页面渲染完成
  76. },
  77. onShow: function() {
  78. // 页面显示
  79. },
  80. onHide: function() {
  81. // 页面隐藏
  82. },
  83. onUnload: function() {
  84. // 页面关闭
  85. },
  86. switchTab: function() {
  87. let that = this;
  88. if (that.data.showType == 0) {
  89. that.setData({
  90. allCommentList: [],
  91. allPage: 1,
  92. comments: [],
  93. showType: 1
  94. });
  95. } else {
  96. that.setData({
  97. picCommentList: [],
  98. picPage: 1,
  99. comments: [],
  100. showType: 0
  101. });
  102. }
  103. this.getCommentList();
  104. },
  105. onReachBottom: function() {
  106. console.log('onPullDownRefresh');
  107. if (this.data.showType == 0) {
  108. if (this.data.allCount / this.data.limit < this.data.allPage) {
  109. return false;
  110. }
  111. this.setData({
  112. 'allPage': this.data.allPage + 1
  113. });
  114. } else {
  115. if (this.data.hasPicCount / this.data.limit < this.data.picPage) {
  116. return false;
  117. }
  118. this.setData({
  119. 'picPage': this.data.picPage + 1
  120. });
  121. }
  122. this.getCommentList();
  123. }
  124. })