Comment.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <!-- 商品评价 -->
  3. <view v-if="!isLoading && list.length" class="goods-comment m-top20">
  4. <view class="item-title dis-flex">
  5. <view class="block-left flex-box">
  6. 商品评价 (<text class="total">{{ total }}条</text>)
  7. </view>
  8. <view class="block-right">
  9. <text @click="onTargetToComment" class="show-more col-9">查看更多</text>
  10. <text class="iconfont icon-arrow-right"></text>
  11. </view>
  12. </view>
  13. <!-- 评论列表 -->
  14. <view class="comment-list">
  15. <view class="comment-item" v-for="(item, index) in list" :key="index">
  16. <view class="comment-item_row dis-flex flex-y-center">
  17. <view class="user-info dis-flex flex-y-center">
  18. <avatar-image class="user-avatar" :url="item.user.avatar_url" :width="50" />
  19. <text class="user-name">{{ item.user.nick_name }}</text>
  20. </view>
  21. <!-- 评星 -->
  22. <view class="star-rating">
  23. <u-rate active-color="#f4a213" :current="rates[item.score]" :disabled="true" />
  24. </view>
  25. </view>
  26. <view class="item-content m-top20">
  27. <text class="f-26 twoline-hide">{{ item.content }}</text>
  28. </view>
  29. <view class="comment-time">{{ item.create_time }}</view>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import AvatarImage from '@/components/avatar-image'
  36. import * as CommentApi from '@/api/comment'
  37. export default {
  38. components: {
  39. AvatarImage
  40. },
  41. props: {
  42. // 商品ID
  43. goodsId: {
  44. type: Number,
  45. default: null
  46. },
  47. // 加载多少条记录 默认2条
  48. limit: {
  49. type: Number,
  50. default: 2
  51. }
  52. },
  53. data() {
  54. return {
  55. // 正在加载
  56. isLoading: true,
  57. // 评星数据转换
  58. rates: { 10: 5, 20: 3, 30: 1 },
  59. // 评价列表数据
  60. list: [],
  61. // 评价总数量
  62. total: 0
  63. }
  64. },
  65. created() {
  66. // 加载评价列表数据
  67. this.getCommentList()
  68. },
  69. methods: {
  70. // 加载评价列表数据
  71. getCommentList() {
  72. const app = this
  73. app.isLoading = true
  74. CommentApi.listRows(app.goodsId, app.limit)
  75. .then(result => {
  76. app.list = result.data.list
  77. app.total = result.data.total
  78. })
  79. .catch(err => err)
  80. .finally(() => app.isLoading = false)
  81. },
  82. // 跳转到评论列表页
  83. onTargetToComment() {
  84. const app = this
  85. app.$navTo('pages/comment/index', { goodsId: app.goodsId })
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .goods-comment {
  92. padding: 20rpx 30rpx;
  93. background-color: #fff;
  94. }
  95. .item-title {
  96. font-size: 28rpx;
  97. margin-bottom: 25rpx;
  98. .total {
  99. margin: 0 4rpx;
  100. }
  101. .show-more {
  102. margin-right: 8rpx;
  103. font-size: 24rpx;
  104. }
  105. }
  106. .comment-item {
  107. padding: 15rpx 5rpx;
  108. margin-bottom: 10rpx;
  109. border-bottom: 1rpx solid #f5f5f5;
  110. &:last-child {
  111. margin-bottom: 0;
  112. border-bottom: none;
  113. }
  114. .comment-item_row {
  115. margin-bottom: 10rpx;
  116. }
  117. }
  118. .user-info {
  119. margin-right: 15rpx;
  120. .user-avatar {
  121. width: 50rpx;
  122. height: 50rpx;
  123. border-radius: 50%;
  124. margin-right: 10rpx;
  125. }
  126. .user-name {
  127. font-size: 24rpx;
  128. }
  129. }
  130. .item-content {
  131. color: #333;
  132. margin: 16rpx 0;
  133. max-height: 76rpx;
  134. line-height: 38rpx;
  135. }
  136. .comment-time {
  137. font-size: 24rpx;
  138. color: #999;
  139. margin-top: 10rpx;
  140. }
  141. </style>