topicComment.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. size: 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. size: that.data.size,
  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.data),
  45. allPage: res.data.currentPage,
  46. comments: that.data.allCommentList.concat(res.data.data)
  47. });
  48. } else {
  49. that.setData({
  50. picCommentList: that.data.picCommentList.concat(res.data.data),
  51. picPage: res.data.currentPage,
  52. comments: that.data.picCommentList.concat(res.data.data)
  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. onReady: function() {
  68. // 页面渲染完成
  69. },
  70. onShow: function() {
  71. // 页面显示
  72. },
  73. onHide: function() {
  74. // 页面隐藏
  75. },
  76. onUnload: function() {
  77. // 页面关闭
  78. },
  79. switchTab: function() {
  80. this.setData({
  81. showType: this.data.showType == 1 ? 0 : 1
  82. });
  83. this.getCommentList();
  84. },
  85. onReachBottom: function() {
  86. console.log('onPullDownRefresh');
  87. if (this.data.showType == 0) {
  88. if (this.data.allCount / this.data.size < this.data.allPage) {
  89. return false;
  90. }
  91. this.setData({
  92. 'allPage': this.data.allPage + 1
  93. });
  94. } else {
  95. if (this.data.hasPicCount / this.data.size < this.data.picPage) {
  96. return false;
  97. }
  98. this.setData({
  99. 'picPage': this.data.picPage + 1
  100. });
  101. }
  102. this.getCommentList();
  103. }
  104. })