index.vue 4.8 KB

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