Comment.vue 3.5 KB

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