Comment.vue 3.4 KB

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