index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view :style="colorStyle">
  3. <view class='evaluate-list'>
  4. <view class='generalComment acea-row row-between-wrapper'>
  5. <view class='acea-row row-middle'>
  6. <view class='evaluate'>{{$t(`评分`)}}</view>
  7. <view class='start' :class="'star'+replyData.reply_star"></view>
  8. </view>
  9. <view>{{$t(`好评率`)}}<text class='font-num'>{{replyData.reply_chance}}%</text></view>
  10. </view>
  11. <view class='nav acea-row row-middle'>
  12. <view class='item' :class='type==0 ? "bg-color":""' @click='changeType(0)'>
  13. {{$t(`全部`)}}({{replyData.sum_count}})
  14. </view>
  15. <view class='item' :class='type==1 ? "bg-color":""' @click='changeType(1)'>
  16. {{$t(`好评`)}}({{replyData.good_count}})
  17. </view>
  18. <view class='item' :class='type==2 ? "bg-color":""' @click='changeType(2)'>
  19. {{$t(`中评`)}}({{replyData.in_count}})
  20. </view>
  21. <view class='item' :class='type==3 ? "bg-color":""' @click='changeType(3)'>
  22. {{$t(`差评`)}}({{replyData.poor_count}})
  23. </view>
  24. </view>
  25. <userEvaluation :reply="reply"></userEvaluation>
  26. <view class='loadingicon acea-row row-center-wrapper' v-if="reply.length>0">
  27. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  28. </view>
  29. <view class='noCommodity' v-if="reply.length==0">
  30. <view class='emptyBox'>
  31. <image :src="imgHost + '/statics/images/noMessage.png'"></image>
  32. </view>
  33. <view class="text">
  34. {{$t(`暂无评论`)}}
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import {
  42. getReplyList,
  43. getReplyConfig
  44. } from '@/api/store.js';
  45. import userEvaluation from '@/components/userEvaluation';
  46. import colors from '@/mixins/color.js';
  47. import {
  48. HTTP_REQUEST_URL
  49. } from '@/config/app';
  50. import {
  51. toLogin
  52. } from '@/libs/login.js';
  53. import {
  54. mapGetters
  55. } from "vuex";
  56. export default {
  57. components: {
  58. userEvaluation
  59. },
  60. mixins: [colors],
  61. computed: mapGetters(['isLogin']),
  62. data() {
  63. return {
  64. imgHost: HTTP_REQUEST_URL,
  65. replyData: {},
  66. product_id: 0,
  67. reply: [],
  68. type: 0,
  69. loading: false,
  70. loadend: false,
  71. loadTitle: this.$t(`加载更多`),
  72. page: 1,
  73. limit: 20
  74. };
  75. },
  76. /**
  77. * 生命周期函数--监听页面加载
  78. */
  79. onLoad(options) {
  80. let that = this;
  81. if (!options.product_id) return that.$util.Tips({
  82. title: that.$t(`缺少参数`)
  83. }, {
  84. tab: 3,
  85. url: 1
  86. });
  87. that.product_id = options.product_id;
  88. },
  89. onShow() {
  90. if (this.isLogin) {
  91. this.getProductReplyCount();
  92. this.getProductReplyList();
  93. } else {
  94. toLogin()
  95. }
  96. },
  97. methods: {
  98. /**
  99. * 获取评论统计数据
  100. *
  101. */
  102. getProductReplyCount: function() {
  103. let that = this;
  104. getReplyConfig(that.product_id).then(res => {
  105. that.$set(that, 'replyData', res.data);
  106. });
  107. },
  108. /**
  109. * 分页获取评论
  110. */
  111. getProductReplyList: function() {
  112. let that = this;
  113. if (that.loadend) return;
  114. if (that.loading) return;
  115. that.loading = true;
  116. that.loadTitle = '';
  117. getReplyList(that.product_id, {
  118. page: that.page,
  119. limit: that.limit,
  120. type: that.type,
  121. }).then(res => {
  122. let list = res.data,
  123. loadend = list.length < that.limit;
  124. that.reply = that.$util.SplitArray(list, that.reply);
  125. that.$set(that, 'reply', that.reply);
  126. that.loading = false;
  127. that.loadend = loadend;
  128. that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
  129. that.page = that.page + 1;
  130. }).catch(err => {
  131. that.loading = false,
  132. that.loadTitle = that.$t(`加载更多`)
  133. });
  134. },
  135. /*
  136. * 点击事件切换
  137. * */
  138. changeType: function(e) {
  139. let type = parseInt(e);
  140. if (type == this.type) return;
  141. this.type = type;
  142. this.page = 1;
  143. this.loadend = false;
  144. this.$set(this, 'reply', []);
  145. this.getProductReplyList();
  146. }
  147. },
  148. /**
  149. * 页面上拉触底事件的处理函数
  150. */
  151. onReachBottom: function() {
  152. this.getProductReplyList();
  153. },
  154. }
  155. </script>
  156. <style lang="scss">
  157. page {
  158. background-color: #fff;
  159. }
  160. .evaluate-list .generalComment {
  161. height: 94rpx;
  162. padding: 0 30rpx;
  163. margin-top: 1rpx;
  164. background-color: #fff;
  165. font-size: 28rpx;
  166. color: #808080;
  167. }
  168. .evaluate-list .generalComment .evaluate {
  169. margin-right: 7rpx;
  170. }
  171. .evaluate-list .nav {
  172. font-size: 24rpx;
  173. color: #282828;
  174. padding: 0 30rpx 32rpx 30rpx;
  175. background-color: #fff;
  176. border-bottom: 1rpx solid #f5f5f5;
  177. }
  178. .evaluate-list .nav .item {
  179. font-size: 24rpx;
  180. color: #282828;
  181. border-radius: 6rpx;
  182. height: 54rpx;
  183. padding: 0 20rpx;
  184. background-color: #f4f4f4;
  185. line-height: 54rpx;
  186. margin-right: 17rpx;
  187. }
  188. .evaluate-list .nav .item.bg-color {
  189. color: #fff;
  190. }
  191. .noCommodity {
  192. background-color: #fff;
  193. padding-bottom: 30rpx;
  194. padding-top: 100rpx;
  195. .text {
  196. padding-top: 40rpx;
  197. text-align: center;
  198. color: #aaa;
  199. }
  200. .emptyBox {
  201. text-align: center;
  202. padding-top: 20rpx;
  203. .tips {
  204. color: #aaa;
  205. font-size: 26rpx;
  206. text-align: center;
  207. }
  208. image {
  209. width: 414rpx;
  210. height: 304rpx;
  211. }
  212. }
  213. }
  214. </style>