topicComment.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. typeId: 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, { valueId: that.data.valueId, typeId: that.data.typeId}).then(function (res) {
  21. if (res.errno === 0) {
  22. that.setData({
  23. allCount: res.data.allCount,
  24. hasPicCount: res.data.hasPicCount
  25. });
  26. }
  27. });
  28. },
  29. getCommentList: function(){
  30. let that = this;
  31. util.request(api.CommentList, {
  32. valueId: that.data.valueId,
  33. typeId: that.data.typeId,
  34. size: that.data.size,
  35. page: (that.data.showType == 0 ? that.data.allPage : that.data.picPage),
  36. showType: that.data.showType
  37. }).then(function (res) {
  38. if (res.errno === 0) {
  39. if (that.data.showType == 0) {
  40. that.setData({
  41. allCommentList: that.data.allCommentList.concat(res.data.data),
  42. allPage: res.data.currentPage,
  43. comments: that.data.allCommentList.concat(res.data.data)
  44. });
  45. } else {
  46. that.setData({
  47. picCommentList: that.data.picCommentList.concat(res.data.data),
  48. picPage: res.data.currentPage,
  49. comments: that.data.picCommentList.concat(res.data.data)
  50. });
  51. }
  52. }
  53. });
  54. },
  55. onLoad: function (options) {
  56. // 页面初始化 options为页面跳转所带来的参数
  57. this.setData({
  58. typeId: options.typeId,
  59. valueId: options.valueId
  60. });
  61. this.getCommentCount();
  62. this.getCommentList();
  63. },
  64. onReady: function () {
  65. // 页面渲染完成
  66. },
  67. onShow: function () {
  68. // 页面显示
  69. },
  70. onHide: function () {
  71. // 页面隐藏
  72. },
  73. onUnload: function () {
  74. // 页面关闭
  75. },
  76. switchTab: function () {
  77. this.setData({
  78. showType: this.data.showType == 1 ? 0 :1
  79. });
  80. this.getCommentList();
  81. },
  82. onReachBottom: function(){
  83. console.log('onPullDownRefresh');
  84. if ( this.data.showType == 0) {
  85. if (this.data.allCount / this.data.size < this.data.allPage) {
  86. return false;
  87. }
  88. this.setData({
  89. 'allPage' : this.data.allPage + 1
  90. });
  91. } else {
  92. if (this.data.hasPicCount / this.data.size < this.data.picPage) {
  93. return false;
  94. }
  95. this.setData({
  96. 'picPage': this.data.picPage + 1
  97. });
  98. }
  99. this.getCommentList();
  100. }
  101. })