comment.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. this.setData({
  69. allCommentList: [],
  70. allPage: 1,
  71. picCommentList: [],
  72. picPage: 1,
  73. comments: []
  74. });
  75. wx.showNavigationBarLoading() //在标题栏中显示加载
  76. this.getCommentCount();
  77. this.getCommentList();
  78. wx.hideNavigationBarLoading() //完成停止加载
  79. wx.stopPullDownRefresh() //停止下拉刷新
  80. },
  81. onReady: function() {
  82. // 页面渲染完成
  83. },
  84. onShow: function() {
  85. // 页面显示
  86. },
  87. onHide: function() {
  88. // 页面隐藏
  89. },
  90. onUnload: function() {
  91. // 页面关闭
  92. },
  93. switchTab: function() {
  94. let that = this;
  95. if (that.data.showType == 0) {
  96. that.setData({
  97. allCommentList: [],
  98. allPage: 1,
  99. comments: [],
  100. showType: 1
  101. });
  102. } else {
  103. that.setData({
  104. picCommentList: [],
  105. picPage: 1,
  106. comments: [],
  107. showType: 0
  108. });
  109. }
  110. this.getCommentList();
  111. },
  112. onReachBottom: function() {
  113. if (this.data.showType == 0) {
  114. if (this.data.allCount / this.data.limit < this.data.allPage) {
  115. return false;
  116. }
  117. this.setData({
  118. 'allPage': this.data.allPage + 1
  119. });
  120. } else {
  121. if (this.data.hasPicCount / this.data.limit < this.data.picPage) {
  122. return false;
  123. }
  124. this.setData({
  125. 'picPage': this.data.picPage + 1
  126. });
  127. }
  128. this.getCommentList();
  129. }
  130. })