detail-comment-card.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!-- 商品评论的卡片 -->
  2. <template>
  3. <div class="detail-comment-card ">
  4. <div class="card-header d-flex align-center justify-space-between pb-6">
  5. <div class="resume-header">
  6. <div class="resume-title">
  7. 评价
  8. <span class="des ml-1">({{ state.total }})</span>
  9. </div>
  10. </div>
  11. </div>
  12. <div v-if="state.total === 0" style="margin: 30px auto; color: #777;">期待您的第一个评价</div>
  13. <!-- 评论列表 -->
  14. <div v-else>
  15. <v-tabs v-model="currentTab" align-tabs="start" color="#ff8a04" @update:model-value="onTabsChange">
  16. <v-tab v-for="item of typeList" :key="item.name" :value="item.tab">{{ item.name }}</v-tab>
  17. </v-tabs>
  18. <div class="card-content mt-5 px-3" style="min-height: 300px;">
  19. <template v-if="state.commentList.length">
  20. <div class="comment-box" v-for="item in state.commentList" :key="item.id">
  21. <comment-item :item="item" />
  22. </div>
  23. <CtPagination
  24. :total="query.total"
  25. :page="query.pageNo"
  26. :limit="query.pageSize"
  27. @handleChange="handleChangePage"
  28. ></CtPagination>
  29. </template>
  30. <template v-else>
  31. <div style="margin: 30px auto; color: #777;">暂无数据</div>
  32. </template>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. <script setup>
  38. import { reactive, onBeforeMount, ref } from 'vue';
  39. import { getCommentPage } from '@/api/mall/product'
  40. import commentItem from './comment-item.vue';
  41. const props = defineProps({
  42. goodsId: {
  43. type: [Number, String],
  44. default: 0,
  45. },
  46. });
  47. const state = reactive({
  48. commentList: [], // 评论列表,只展示最近的 3 条
  49. total: 0, // 总评论数
  50. });
  51. const typeList = [
  52. { type: 0, name: '全部' },
  53. { type: 1, name: '好评' },
  54. { type: 2, name: '中评' },
  55. { type: 3, name: '差评' },
  56. ]
  57. const currentTab = ref(0)
  58. const query = ref({
  59. total: 0, // 选项卡
  60. pageNo: 1,
  61. pageSize: 10,
  62. })
  63. async function getList(id) {
  64. id = id || props.goodsId
  65. state.commentList = []
  66. const res = await getCommentPage(
  67. props.goodsId,
  68. query.value.pageNo,
  69. query.value.pageSize,
  70. currentTab.value,
  71. )
  72. // console.log('getCommentPage:', res)
  73. state.commentList = res.list;
  74. query.value.total = res.total // 分页论数
  75. if (!currentTab.value) state.total = res.total // 总评论数
  76. }
  77. const handleChangePage = (index) => {
  78. query.value.pageNo = index
  79. getList()
  80. }
  81. // 切换选项卡
  82. function onTabsChange(e) {
  83. // 加载列表
  84. query.value.pageNo = 1;
  85. query.value.total = 0;
  86. getList()
  87. }
  88. onBeforeMount(() => {
  89. getList()
  90. });
  91. </script>
  92. <style lang="scss" scoped>
  93. .detail-comment-card {
  94. margin: 0 20rpx 20rpx 20rpx;
  95. padding: 20rpx 20rpx 0 20rpx;
  96. .card-header {
  97. .line {
  98. width: 6rpx;
  99. height: 30rpx;
  100. background: linear-gradient(180deg, var(--v-primary-base) 0%, var(--v-primary-lighten1) 100%);
  101. border-radius: 3rpx;
  102. }
  103. .title {
  104. font-size: 30rpx;
  105. font-weight: bold;
  106. line-height: normal;
  107. }
  108. .des {
  109. font-size: 24rpx;
  110. color: #999999;
  111. }
  112. .more-btn {
  113. font-size: 24rpx;
  114. color: var(--v-primary-base);
  115. line-height: normal;
  116. }
  117. .cicon-forward {
  118. font-size: 24rpx;
  119. line-height: normal;
  120. color: var(--v-primary-base);
  121. margin-top: 4rpx;
  122. }
  123. }
  124. }
  125. .comment-box {
  126. border-bottom: 2rpx solid #eeeeee;
  127. &:last-child {
  128. border: none;
  129. }
  130. }
  131. .tabClass {
  132. color: #666;
  133. cursor: pointer;
  134. font-size: 18px;
  135. font-weight: 400;
  136. letter-spacing: 0;
  137. margin-right: 32px;
  138. }
  139. .tabClassAct {
  140. color: #1a1a1a;
  141. font-weight: bold;
  142. }
  143. </style>