comment.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <!-- 商品評論页面 -->
  2. <template>
  3. <view>
  4. <view class="edgeInsetTop"></view>
  5. <view class="wanl-goods-comment">
  6. <view class="padding-bj bg-white margin-bottom-bj head">
  7. <view class="padding-bottom-bj solid-bottom">
  8. {{ $t('mall.comment.goodRate') }}
  9. <text class="margin-left-xs wanl-orange">{{ statisticsData.rate }}%</text>
  10. </view>
  11. <view>
  12. <view @tap="onTag('')" class="cu-tag round" :class="{ active: tag === '' }">{{ $t('mall.comment.all') }} ({{ statisticsData.total }})</view>
  13. <view @tap="onTag('good')" class="cu-tag round" :class="{ active: tag === 'good' }">{{ $t('mall.comment.good') }} ({{ statisticsData.good }})</view>
  14. <view @tap="onTag('pertinent')" class="cu-tag round" :class="{ active: tag === 'pertinent' }">{{ $t('mall.comment.pertinent') }} ({{ statisticsData.pertinent }})</view>
  15. <view @tap="onTag('poor')" class="cu-tag round" :class="{ active: tag === 'poor' }">{{ $t('mall.comment.poor') }} ({{ statisticsData.poor }})</view>
  16. <view @tap="onTag('figure')" class="cu-tag round" :class="{ active: tag === 'figure' }">{{ $t('mall.comment.withImage') }} ({{ statisticsData.figure }})</view>
  17. </view>
  18. </view>
  19. <view class="list padding-bj radius-bock" v-for="item in listData" :key="item.id">
  20. <view class="userinfo">
  21. <view class="avatar">
  22. <view class="cu-avatar round margin-right-xs"
  23. :style="{ backgroundImage: 'url(' + (item.user && item.user.avatar || '') + ')' }"></view>
  24. <view class="text-sm">
  25. <view>{{ (item.user && item.user.nickname) || $t('mall.comment.anonymous') }}</view>
  26. <view class="text-gray">{{ item.createtime || '' }}</view>
  27. </view>
  28. </view>
  29. <view class="rate-stars">
  30. <text v-for="n in 5" :key="n" class="rate-star"
  31. :class="n <= item.score ? 'filled' : ''">★</text>
  32. </view>
  33. </view>
  34. <view class="details">
  35. <view class="margin-bottom-sm">{{ item.content }}</view>
  36. <view class="text-gray text-sm">{{ $t('mall.comment.spec') }} {{ item.suk }}</view>
  37. </view>
  38. <view class="grid flex-sub grid-square"
  39. :class="[item.images && item.images.length > 3 ? 'col-3' : 'col-' + (item.images ? item.images.length : 0)]"
  40. v-if="item.images && item.images.length !== 0">
  41. <view class="bg-img" v-for="(image, index) in item.images" :key="index"
  42. @tap="previewImage(item.images, index)"
  43. :style="{ backgroundImage: 'url(' + image + ')' }"></view>
  44. </view>
  45. </view>
  46. <view class="load-more" v-if="listData.length > 0">
  47. <text v-if="status === 'loading'">{{ $t('common.loading') }}</text>
  48. <text v-else-if="status === 'noMore'">{{ $t('common.noMore') }}</text>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import { pullMallProductComment } from '@/features/mall/mall-gateway'
  55. export default {
  56. data() {
  57. return {
  58. listData: [],
  59. statisticsData: {
  60. rate: 0,
  61. good: 0,
  62. pertinent: 0,
  63. poor: 0,
  64. figure: 0,
  65. total: 0
  66. },
  67. reload: false,
  68. current_page: 1,
  69. last_page: 1,
  70. goods_id: 0,
  71. tag: '',
  72. status: 'loading'
  73. }
  74. },
  75. onLoad(option) {
  76. this.goods_id = option.id
  77. this.tag = option.tag ? option.tag : ''
  78. this.loadData()
  79. },
  80. onPullDownRefresh() {
  81. this.current_page = 1
  82. this.reload = true
  83. this.loadData()
  84. },
  85. onReachBottom() {
  86. if (this.current_page >= this.last_page) {
  87. this.status = 'noMore'
  88. } else {
  89. this.reload = false
  90. this.current_page += 1
  91. this.status = 'loading'
  92. this.loadData()
  93. }
  94. },
  95. methods: {
  96. async loadData() {
  97. try {
  98. const res = await pullMallProductComment({
  99. id: this.goods_id,
  100. page: this.current_page,
  101. tag: this.tag
  102. })
  103. uni.stopPullDownRefresh()
  104. this.listData = this.reload ? res.list : this.listData.concat(res.list)
  105. this.current_page = res.currentPage
  106. this.last_page = res.lastPage
  107. this.statisticsData = res.statistics
  108. this.status = res.list.length === 0 || this.current_page >= this.last_page ? 'noMore' : 'more'
  109. } catch (e) {
  110. uni.stopPullDownRefresh()
  111. this.status = 'noMore'
  112. }
  113. },
  114. previewImage(images, index) {
  115. const imgArr = images || []
  116. uni.previewImage({
  117. urls: imgArr,
  118. current: imgArr[index],
  119. indicator: 'number'
  120. })
  121. },
  122. onTag(tag) {
  123. this.current_page = 1
  124. this.reload = true
  125. this.tag = tag
  126. this.loadData()
  127. }
  128. }
  129. }
  130. </script>
  131. <style scoped>
  132. .edgeInsetTop {
  133. padding-top: var(--status-bar-height, 44px);
  134. }
  135. .wanl-goods-comment .head .cu-tag {
  136. height: 60rpx;
  137. background-color: #ffeee3;
  138. color: #383736;
  139. padding: 0 25rpx;
  140. margin: 25rpx 15rpx 0 0;
  141. }
  142. .wanl-goods-comment .head .cu-tag.active {
  143. background-color: #fe6600;
  144. color: white;
  145. }
  146. .wanl-goods-comment .list {
  147. margin-bottom: 25rpx;
  148. background-color: white;
  149. padding-bottom: 0;
  150. }
  151. .wanl-goods-comment .list .userinfo {
  152. display: flex;
  153. justify-content: space-between;
  154. align-items: center;
  155. }
  156. .wanl-goods-comment .list .userinfo .avatar {
  157. display: flex;
  158. align-items: center;
  159. }
  160. .wanl-goods-comment .list .details {
  161. margin: 20rpx 0;
  162. }
  163. .rate-stars {
  164. display: flex;
  165. }
  166. .rate-star {
  167. font-size: 28rpx;
  168. color: #ddd;
  169. }
  170. .rate-star.filled {
  171. color: #ffca00;
  172. }
  173. .load-more {
  174. text-align: center;
  175. padding: 30rpx 0;
  176. color: #999;
  177. font-size: 24rpx;
  178. }
  179. .bg-img {
  180. background-size: cover;
  181. background-position: center;
  182. }
  183. .grid-square .bg-img {
  184. padding-bottom: 100%;
  185. }
  186. </style>