detail-comment-card.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!-- 商品评论的卡片 -->
  2. <template>
  3. <view class="detail-comment-card bg-white">
  4. <view class="card-header ss-flex ss-col-center ss-row-between ss-p-b-30">
  5. <view class="ss-flex ss-col-center">
  6. <view class="line"></view>
  7. <view class="title ss-m-l-20 ss-m-r-10">{{ $t('common.review')}}</view>
  8. <view class="des">({{ state.total }})</view>
  9. </view>
  10. <view
  11. class="ss-flex ss-col-center"
  12. @tap="sheep.$router.go('/pages/goods/comment/list', { id: goodsId })"
  13. v-if="state.commentList.length > 0"
  14. >
  15. <button class="ss-reset-button more-btn">{{ $t('common.view_all')}}</button>
  16. <text class="cicon-forward" />
  17. </view>
  18. </view>
  19. <!-- 评论列表 -->
  20. <view class="card-content">
  21. <view class="comment-box ss-p-y-30" v-for="item in state.commentList" :key="item.id">
  22. <comment-item :item="item" />
  23. </view>
  24. <s-empty
  25. v-if="state.commentList.length === 0"
  26. paddingTop="0"
  27. icon="/static/comment-empty.png"
  28. :text="t('common.awaiting_your_first_review')"
  29. />
  30. </view>
  31. </view>
  32. </template>
  33. <script setup>
  34. import { reactive, onBeforeMount } from 'vue';
  35. import sheep from '@/sheep';
  36. import CommentApi from '@/sheep/api/product/comment';
  37. import commentItem from './comment-item.vue';
  38. import { t } from '@/locale'
  39. const props = defineProps({
  40. goodsId: {
  41. type: [Number, String],
  42. default: 0,
  43. },
  44. });
  45. const state = reactive({
  46. commentList: [], // 评论列表,只展示最近的 3 条
  47. total: 0, // 总评论数
  48. });
  49. async function getComment(id) {
  50. const { data } = await CommentApi.getCommentPage(id, 1, 3, 0);
  51. state.commentList = data.list;
  52. state.total = data.total;
  53. }
  54. onBeforeMount(() => {
  55. getComment(props.goodsId);
  56. });
  57. </script>
  58. <style lang="scss" scoped>
  59. .detail-comment-card {
  60. margin: 0 20rpx 20rpx 20rpx;
  61. padding: 20rpx 20rpx 0 20rpx;
  62. .card-header {
  63. .line {
  64. width: 6rpx;
  65. height: 30rpx;
  66. background: linear-gradient(180deg, var(--ui-BG-Main) 0%, var(--ui-BG-Main-gradient) 100%);
  67. border-radius: 3rpx;
  68. }
  69. .title {
  70. font-size: 30rpx;
  71. font-weight: bold;
  72. line-height: normal;
  73. }
  74. .des {
  75. font-size: 24rpx;
  76. color: $dark-9;
  77. }
  78. .more-btn {
  79. font-size: 24rpx;
  80. color: var(--ui-BG-Main);
  81. line-height: normal;
  82. }
  83. .cicon-forward {
  84. font-size: 24rpx;
  85. line-height: normal;
  86. color: var(--ui-BG-Main);
  87. margin-top: 4rpx;
  88. }
  89. }
  90. }
  91. .comment-box {
  92. border-bottom: 2rpx solid #eeeeee;
  93. &:last-child {
  94. border: none;
  95. }
  96. }
  97. </style>