index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <view style="height: 100%;">
  3. <view class='evaluate-list'>
  4. <view class='generalComment acea-row row-between-wrapper'>
  5. <view class='acea-row row-middle font-color'>
  6. <view class='evaluate'>评分</view>
  7. <view class='start' :class="'star'+ Math.round(replyData.scores)" />
  8. </view>
  9. <view><text class='font-color'>{{ 100.0 * replyData.goodCount / replyData.count }}%</text>好评率</view>
  10. </view>
  11. <view class='nav acea-row row-middle'>
  12. <view class='item' :class='type === 0 ? "bg-color":""' @click='changeType(0)'>全部({{replyData.count}})
  13. </view>
  14. <view class='item' :class='type === 1 ? "bg-color":""' @click='changeType(1)'>好评({{replyData.goodCount}})
  15. </view>
  16. <view class='item' :class='type === 2 ? "bg-color":""' @click='changeType(2)'>中评({{replyData.mediocreCount}})
  17. </view>
  18. <view class='item' :class='type === 3 ? "bg-color":""' @click='changeType(3)'>差评({{replyData.negativeCount}})
  19. </view>
  20. </view>
  21. <userEvaluation :reply="reply"></userEvaluation>
  22. </view>
  23. <view class='loadingicon acea-row row-center-wrapper'>
  24. <text class='loading iconfont icon-jiazai' :hidden='!loading'></text>{{loadTitle}}
  25. </view>
  26. <view class='noCommodity' v-if="replyData.count === 0 && page > 1">
  27. <view class='pictrue'>
  28. <image src='../static/noEvaluate.png' />
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import userEvaluation from '@/components/userEvaluation';
  35. import * as ProductCommentApi from '@/api/product/comment.js';
  36. export default {
  37. components: {
  38. userEvaluation
  39. },
  40. data() {
  41. return {
  42. replyData: {}, // 评论统计
  43. product_id: 0, // 商品编号
  44. reply: [], // 评论列表
  45. type: 0,
  46. loading: false,
  47. loadend: false,
  48. loadTitle: '加载更多',
  49. page: 1,
  50. limit: 20
  51. };
  52. },
  53. /**
  54. * 生命周期函数--监听页面加载
  55. */
  56. onLoad: function(options) {
  57. if (!options.productId) {
  58. return this.$util.Tips({
  59. title: '缺少参数'
  60. }, {
  61. tab: 3,
  62. url: 1
  63. });
  64. }
  65. this.productId = options.productId;
  66. },
  67. onShow: function() {
  68. this.getProductReplyCount();
  69. this.getProductReplyList();
  70. },
  71. methods: {
  72. /**
  73. * 获取评论统计数据
  74. */
  75. getProductReplyCount: function() {
  76. ProductCommentApi.getCommentStatistics(this.productId).then(res => {
  77. res.data.count = res.data.goodCount + res.data.mediocreCount + res.data.negativeCount;
  78. this.$set(this, 'replyData', res.data);
  79. });
  80. },
  81. /**
  82. * 分页获取评论
  83. */
  84. getProductReplyList: function() {
  85. if (this.loadend || this.loading) {
  86. return;
  87. }
  88. this.loading = true;
  89. this.loadTitle = '';
  90. ProductCommentApi.getCommentPage({
  91. spuId: this.productId,
  92. type: this.type,
  93. pageNo: this.page,
  94. pageSize: this.limit,
  95. }).then(res => {
  96. const list = res.data.list;
  97. const loadend = list.length < this.limit;
  98. this.reply = this.$util.SplitArray(list, this.reply);
  99. this.$set(this, 'reply', this.reply);
  100. this.loading = false;
  101. this.loadend = loadend;
  102. this.loadTitle = loadend ? "😕人家是有底线的~~" : "加载更多";
  103. this.page = this.page + 1;
  104. }).catch(err => {
  105. this.loading = false;
  106. this.loadTitle = '加载更多'
  107. });
  108. },
  109. /**
  110. * 点击事件切换
  111. */
  112. changeType: function(e) {
  113. let type = parseInt(e);
  114. if (type === this.type) {
  115. return;
  116. }
  117. this.type = type;
  118. this.page = 1;
  119. this.loadend = false;
  120. this.$set(this, 'reply', []);
  121. this.getProductReplyList();
  122. }
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom: function() {
  128. this.getProductReplyList();
  129. },
  130. }
  131. </script>
  132. <style lang="scss">
  133. page {
  134. background-color: #fff;
  135. height: 100%;
  136. }
  137. .evaluate-list{
  138. padding: 30rpx 0 0 0;
  139. background-color: #fff;
  140. }
  141. .evaluate-list .generalComment {
  142. padding: 0 30rpx;
  143. margin-top: 1rpx;
  144. background-color: #fff;
  145. font-size: 28rpx;
  146. color: #808080;
  147. }
  148. .evaluate-list .generalComment .evaluate {
  149. margin-right: 7rpx;
  150. color: #333333;
  151. font-size: 28rpx;
  152. }
  153. .evaluate-list .nav {
  154. font-size: 24rpx;
  155. color: #282828;
  156. padding: 30rpx;
  157. background-color: #fff;
  158. border-bottom: 1rpx solid #f5f5f5;
  159. }
  160. .evaluate-list .nav .item {
  161. font-size: 24rpx;
  162. color: #282828;
  163. border-radius: 27rpx;
  164. height: 54rpx;
  165. padding: 0 20rpx;
  166. background-color: #f4f4f4;
  167. line-height: 54rpx;
  168. margin-right: 17rpx;
  169. }
  170. .evaluate-list .nav .item.bg-color {
  171. color: #fff;
  172. }
  173. </style>