all_comments.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view>
  3. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption">
  4. <view class="all-comments">
  5. <view class="header bg-white" v-if="!isEmpty">
  6. <view class="title xs">
  7. <text class="lighter m-r-10">商品好评率</text>
  8. <text class="primary">{{percent}}</text>
  9. </view>
  10. <view class="tab flex flex-wrap">
  11. <view v-for="(item, index) in categoryList"
  12. :class="'tab-item xs m-r-10 br60 m-b-20 ' + (type == item.id ? 'bg-primary white' : 'bg-gray' )"
  13. :key="index" @tap="onChangType(index)" v-show="item.count">
  14. {{item.name}}({{item.count}})
  15. </view>
  16. </view>
  17. </view>
  18. <view class="main bg-white">
  19. <view class="evaluation-list">
  20. <view v-for="(item, index) in commentList" :key="index" class="evaluation-item">
  21. <view class="user-info flex">
  22. <image class="avatar m-r-20" :src="item.avatar"></image>
  23. <view class="user-name md m-r-10">{{item.nickname}}</view>
  24. <u-rate disabled size="26rpx" :color="colorConfig.primary" v-model="item.goods_comment">
  25. </u-rate>
  26. </view>
  27. <view class="muted xs m-t-10">
  28. <text class="m-r-20">{{item.create_time}}</text>
  29. <text v-show="item.spec_value_str">{{item.spec_value_str}}</text>
  30. </view>
  31. <view v-if="item.comment" class="dec m-t-20">{{item.comment}}</view>
  32. <view class="img m-t-20 flex flex-wrap" v-if="item.image.length">
  33. <view v-for="(imgitem, imgindex) in item.image" :key="imgindex"
  34. class="img-item m-r-20 m-b-20" :data-current="imgitem" :data-uri="item.image"
  35. @tap="previewImage">
  36. <u-image width="160rpx" fit="cover" height="160rpx" radius="6rpx" lazy-load
  37. class="goods-img" :src="imgitem" />
  38. </view>
  39. </view>
  40. <view class="seller-recall-container bg-gray m-t-10" v-if="item.reply">
  41. <view class="lighter">
  42. 商家回复:
  43. <text class="normal">{{item.reply}}</text>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </mescroll-body>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. getCommentList,
  56. getCommentCategory
  57. } from '@/api/store';
  58. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins";
  59. export default {
  60. mixins: [MescrollMixin],
  61. data() {
  62. return {
  63. active: 0,
  64. type: '',
  65. commentList: [],
  66. categoryList: [],
  67. percent: '',
  68. isEmpty: true,
  69. upOption:{
  70. auto: false,
  71. empty: {
  72. icon: '/static/images/goods_null.png',
  73. tip : "暂无评价",
  74. }
  75. },
  76. };
  77. },
  78. onLoad(options) {
  79. this.id = this.$Route.query.id;
  80. },
  81. onShow() {
  82. this.id = this.$Route.query.id;
  83. },
  84. methods: {
  85. async downCallback(page) {
  86. await this.getCommentCategoryFun()
  87. this.mescroll.resetUpScroll();
  88. },
  89. upCallback(page) {
  90. let pageNum = page.num; // 页码, 默认从1开始
  91. let pageSize = page.size; // 页长, 默认每页10条
  92. getCommentList({
  93. type: this.type,
  94. goods_id: this.id,
  95. page_no: pageNum,
  96. page_size: pageSize
  97. }).then(res => {
  98. if (res.code == 1) {
  99. let curPageData = res.data.lists;
  100. let curPageLen = curPageData.length;
  101. let hasNext = !!res.data.more;
  102. if (page.num == 1) this.commentList = [];
  103. this.commentList = this.commentList.concat(curPageData);
  104. this.mescroll.endSuccess(curPageLen, hasNext);
  105. }
  106. })
  107. },
  108. onChangType(index) {
  109. this.active = index
  110. this.type = this.categoryList[index].id
  111. this.commentList = []
  112. this.mescroll.resetUpScroll();
  113. },
  114. getCommentCategoryFun() {
  115. return new Promise(resolve => {
  116. getCommentCategory(this.id).then(res => {
  117. let {
  118. code,
  119. data: {
  120. comment,
  121. percent
  122. }
  123. } = res;
  124. if (code == 1) {
  125. this.categoryList = comment;
  126. this.percent = percent;
  127. this.type = comment[this.active].id
  128. this.isEmpty = !comment[0].count
  129. this.$nextTick(() => resolve());
  130. }
  131. });
  132. });
  133. },
  134. previewImage(e) {
  135. const {
  136. current,
  137. uri
  138. } = e.currentTarget.dataset;
  139. let urls = uri;
  140. uni.previewImage({
  141. current,
  142. // 当前显示图片的http链接
  143. urls // 需要预览的图片http链接列表
  144. });
  145. }
  146. }
  147. };
  148. </script>
  149. <style lang="scss">
  150. .all-comments {
  151. padding-top: 20rpx;
  152. .header {
  153. .title {
  154. padding: 24rpx 26rpx;
  155. border-bottom: var(--border);
  156. }
  157. .tab {
  158. padding: 30rpx 0 10rpx 20rpx;
  159. flex-wrap: wrap;
  160. .tab-item {
  161. padding: 9rpx 29rpx;
  162. }
  163. }
  164. }
  165. .main {
  166. .evaluation-list {
  167. .evaluation-item {
  168. padding: 20rpx;
  169. &:not(:last-of-type) {
  170. border-bottom: $-solid-border;
  171. }
  172. .avatar {
  173. width: 60rpx;
  174. height: 60rpx;
  175. border-radius: 50%;
  176. }
  177. .seller-recall-container {
  178. padding: 24rpx 20rpx;
  179. border-radius: 12rpx;
  180. }
  181. }
  182. }
  183. }
  184. }
  185. </style>