list.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!-- 商品评论的分页 -->
  2. <template>
  3. <s-layout :title="$t('review.all_reviews')">
  4. <su-tabs
  5. :list="state.type"
  6. :scrollable="false"
  7. @change="onTabsChange"
  8. :current="state.currentTab"
  9. />
  10. <!-- 评论列表 -->
  11. <view class="ss-m-t-20">
  12. <view class="list-item" v-for="item in state.pagination.list" :key="item">
  13. <comment-item :item="item" />
  14. </view>
  15. </view>
  16. <s-empty v-if="state.pagination.total === 0" text="暂无数据" icon="/static/data-empty.png" />
  17. <!-- 下拉 -->
  18. <uni-load-more
  19. v-if="state.pagination.total > 0"
  20. :status="state.loadStatus"
  21. :content-text="{
  22. contentdown: '上拉加载更多',
  23. }"
  24. @tap="loadMore"
  25. />
  26. </s-layout>
  27. </template>
  28. <script setup>
  29. import CommentApi from '@/sheep/api/product/comment';
  30. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  31. import { reactive } from 'vue';
  32. import _ from 'lodash';
  33. import commentItem from '../components/detail/comment-item.vue';
  34. import { t } from '@/locale'
  35. const state = reactive({
  36. id: 0, // 商品 SPU 编号
  37. type: [
  38. { type: 0, name: t('common.all') },
  39. { type: 1, name: t('review.positive') },
  40. { type: 2, name: t('review.neutral') },
  41. { type: 3, name: t('review.negative') },
  42. ],
  43. currentTab: 0, // 选中的 TAB
  44. loadStatus: '',
  45. pagination: {
  46. list: [],
  47. total: 0,
  48. pageNo: 1,
  49. pageSize: 10,
  50. },
  51. });
  52. // 切换选项卡
  53. function onTabsChange(e) {
  54. state.currentTab = e.index;
  55. // 加载列表
  56. state.pagination.pageNo = 1;
  57. state.pagination.list = [];
  58. state.pagination.total = 0;
  59. getList();
  60. }
  61. async function getList() {
  62. // 加载列表
  63. state.loadStatus = 'loading';
  64. let res = await CommentApi.getCommentPage(
  65. state.id,
  66. state.pagination.pageNo,
  67. state.pagination.pageSize,
  68. state.type[state.currentTab].type,
  69. );
  70. if (res.code !== 0) {
  71. return;
  72. }
  73. console.log(res)
  74. // 合并列表
  75. state.pagination.list = _.concat(state.pagination.list, res.data.list);
  76. state.pagination.total = res.data.total;
  77. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  78. }
  79. // 加载更多
  80. function loadMore() {
  81. if (state.loadStatus === 'noMore') {
  82. return;
  83. }
  84. state.pagination.pageNo++;
  85. getList();
  86. }
  87. onLoad((options) => {
  88. state.id = options.id;
  89. getList();
  90. });
  91. // 上拉加载更多
  92. onReachBottom(() => {
  93. loadMore();
  94. });
  95. </script>
  96. <style lang="scss" scoped>
  97. .list-item {
  98. padding: 32rpx 30rpx 20rpx 20rpx;
  99. background: #fff;
  100. .avatar {
  101. width: 52rpx;
  102. height: 52rpx;
  103. border-radius: 50%;
  104. }
  105. .nickname {
  106. font-size: 26rpx;
  107. font-weight: 500;
  108. color: #999999;
  109. }
  110. .create-time {
  111. font-size: 24rpx;
  112. font-weight: 500;
  113. color: #c4c4c4;
  114. }
  115. .content-title {
  116. font-size: 26rpx;
  117. font-weight: 400;
  118. color: #666666;
  119. line-height: 42rpx;
  120. }
  121. .content-img {
  122. width: 174rpx;
  123. height: 174rpx;
  124. }
  125. .cicon-info-o {
  126. font-size: 26rpx;
  127. color: #c4c4c4;
  128. }
  129. .foot-title {
  130. font-size: 24rpx;
  131. font-weight: 500;
  132. color: #999999;
  133. }
  134. }
  135. .btn-box {
  136. width: 100%;
  137. height: 120rpx;
  138. background: #fff;
  139. border-top: 2rpx solid #eee;
  140. }
  141. .tab-btn {
  142. width: 130rpx;
  143. height: 62rpx;
  144. background: #eeeeee;
  145. border-radius: 31rpx;
  146. font-size: 28rpx;
  147. font-weight: 400;
  148. color: #999999;
  149. border: 1px solid #e5e5e5;
  150. margin-right: 10rpx;
  151. }
  152. </style>