detail-comment-card.vue 2.6 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">评价</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">查看全部</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="期待您的第一个评价"
  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. const props = defineProps({
  39. goodsId: {
  40. type: [Number, String],
  41. default: 0,
  42. },
  43. });
  44. const state = reactive({
  45. commentList: [], // 评论列表,只展示最近的 3 条
  46. total: 0, // 总评论数
  47. });
  48. async function getComment(id) {
  49. const { data } = await CommentApi.getCommentPage(id, 1, 3, 0);
  50. state.commentList = data.list;
  51. state.total = data.total;
  52. }
  53. onBeforeMount(() => {
  54. getComment(props.goodsId);
  55. });
  56. </script>
  57. <style lang="scss" scoped>
  58. .detail-comment-card {
  59. margin: 0 20rpx 20rpx 20rpx;
  60. padding: 20rpx 20rpx 0 20rpx;
  61. .card-header {
  62. .line {
  63. width: 6rpx;
  64. height: 30rpx;
  65. background: linear-gradient(180deg, var(--ui-BG-Main) 0%, var(--ui-BG-Main-gradient) 100%);
  66. border-radius: 3rpx;
  67. }
  68. .title {
  69. font-size: 30rpx;
  70. font-weight: bold;
  71. line-height: normal;
  72. }
  73. .des {
  74. font-size: 24rpx;
  75. color: $dark-9;
  76. }
  77. .more-btn {
  78. font-size: 24rpx;
  79. color: var(--ui-BG-Main);
  80. line-height: normal;
  81. }
  82. .cicon-forward {
  83. font-size: 24rpx;
  84. line-height: normal;
  85. color: var(--ui-BG-Main);
  86. margin-top: 4rpx;
  87. }
  88. }
  89. }
  90. .comment-box {
  91. border-bottom: 2rpx solid #eeeeee;
  92. &:last-child {
  93. border: none;
  94. }
  95. }
  96. </style>