1
0

comment.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. orderId: 0,
  12. showType: 0,
  13. allCount: 0,
  14. hasPicCount: 0,
  15. allPage: 1,
  16. picPage: 1,
  17. size: 20
  18. },
  19. getCommentCount: function () {
  20. let that = this;
  21. util.request(api.CommentCount, { valueId: that.data.valueId, typeId: that.data.typeId, orderId: that.data.orderId }).then(function (res) {
  22. if (res.errno === 0) {
  23. that.setData({
  24. allCount: res.data.allCount,
  25. hasPicCount: res.data.hasPicCount
  26. });
  27. }
  28. });
  29. },
  30. getCommentList: function () {
  31. let that = this;
  32. util.request(api.CommentList, {
  33. valueId: that.data.valueId,
  34. typeId: that.data.typeId,
  35. orderId: that.data.orderId,
  36. size: that.data.size,
  37. page: (that.data.showType == 0 ? that.data.allPage : that.data.picPage),
  38. showType: that.data.showType
  39. }).then(function (res) {
  40. if (res.errno === 0) {
  41. if (that.data.showType == 0) {
  42. that.setData({
  43. allCommentList: res.data.data,
  44. allPage: res.data.currentPage,
  45. comments: res.data.data,
  46. });
  47. } else {
  48. that.setData({
  49. picCommentList: res.data.data,
  50. picPage: res.data.currentPage,
  51. comments: res.data.data
  52. });
  53. }
  54. }
  55. });
  56. },
  57. onLoad: function (options) {
  58. // 页面初始化 options为页面跳转所带来的参数
  59. if (options.typeId) {
  60. this.setData({
  61. typeId: options.typeId
  62. });
  63. }
  64. if (options.valueId) {
  65. this.setData({
  66. valueId: options.valueId,
  67. });
  68. }
  69. if (options.orderId) {
  70. this.setData({
  71. orderId: options.orderId
  72. });
  73. }
  74. this.getCommentCount();
  75. this.getCommentList();
  76. },
  77. onReady: function () {
  78. // 页面渲染完成
  79. },
  80. onShow: function () {
  81. // 页面显示
  82. },
  83. onHide: function () {
  84. // 页面隐藏
  85. },
  86. onUnload: function () {
  87. // 页面关闭
  88. },
  89. switchTab: function () {
  90. this.setData({
  91. showType: this.data.showType == 1 ? 0 : 1
  92. });
  93. this.getCommentList();
  94. },
  95. onReachBottom: function () {
  96. console.log('onPullDownRefresh');
  97. if (this.data.showType == 0) {
  98. if (this.data.allCount / this.data.size < this.data.allPage) {
  99. return false;
  100. }
  101. this.setData({
  102. 'allPage': this.data.allPage + 1
  103. });
  104. } else {
  105. if (this.data.hasPicCount / this.data.size < this.data.picPage) {
  106. return false;
  107. }
  108. this.setData({
  109. 'picPage': this.data.picPage + 1
  110. });
  111. }
  112. this.getCommentList();
  113. },
  114. previewPic(e) {
  115. let url = e.currentTarget.dataset.url;
  116. let urls = [];
  117. urls[0] = url;
  118. wx.previewImage({
  119. urls
  120. })
  121. }
  122. })