list.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!-- 商品评论的分页 -->
  2. <template>
  3. <s-layout title="全部评价">
  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. const state = reactive({
  35. id: 0, // 商品 SPU 编号
  36. type: [
  37. { type: 0, name: '全部' },
  38. { type: 1, name: '好评' },
  39. { type: 2, name: '中评' },
  40. { type: 3, name: '差评' },
  41. ],
  42. currentTab: 0, // 选中的 TAB
  43. loadStatus: '',
  44. pagination: {
  45. list: [],
  46. total: 0,
  47. pageNo: 1,
  48. pageSize: 10,
  49. },
  50. });
  51. // 切换选项卡
  52. function onTabsChange(e) {
  53. state.currentTab = e.index;
  54. // 加载列表
  55. state.pagination.pageNo = 1;
  56. state.pagination.list = [];
  57. state.pagination.total = 0;
  58. getList();
  59. }
  60. async function getList() {
  61. // 加载列表
  62. state.loadStatus = 'loading';
  63. let res = await CommentApi.getCommentPage(
  64. state.id,
  65. state.pagination.pageNo,
  66. state.pagination.pageSize,
  67. state.type[state.currentTab].type,
  68. );
  69. if (res.code !== 0) {
  70. return;
  71. }
  72. console.log(res)
  73. // 合并列表
  74. state.pagination.list = _.concat(state.pagination.list, res.data.list);
  75. state.pagination.total = res.data.total;
  76. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  77. }
  78. // 加载更多
  79. function loadMore() {
  80. if (state.loadStatus === 'noMore') {
  81. return;
  82. }
  83. state.pagination.pageNo++;
  84. getList();
  85. }
  86. onLoad((options) => {
  87. state.id = options.id;
  88. getList();
  89. });
  90. // 上拉加载更多
  91. onReachBottom(() => {
  92. loadMore();
  93. });
  94. </script>
  95. <style lang="scss" scoped>
  96. .list-item {
  97. padding: 32rpx 30rpx 20rpx 20rpx;
  98. background: #fff;
  99. .avatar {
  100. width: 52rpx;
  101. height: 52rpx;
  102. border-radius: 50%;
  103. }
  104. .nickname {
  105. font-size: 26rpx;
  106. font-weight: 500;
  107. color: #999999;
  108. }
  109. .create-time {
  110. font-size: 24rpx;
  111. font-weight: 500;
  112. color: #c4c4c4;
  113. }
  114. .content-title {
  115. font-size: 26rpx;
  116. font-weight: 400;
  117. color: #666666;
  118. line-height: 42rpx;
  119. }
  120. .content-img {
  121. width: 174rpx;
  122. height: 174rpx;
  123. }
  124. .cicon-info-o {
  125. font-size: 26rpx;
  126. color: #c4c4c4;
  127. }
  128. .foot-title {
  129. font-size: 24rpx;
  130. font-weight: 500;
  131. color: #999999;
  132. }
  133. }
  134. .btn-box {
  135. width: 100%;
  136. height: 120rpx;
  137. background: #fff;
  138. border-top: 2rpx solid #eee;
  139. }
  140. .tab-btn {
  141. width: 130rpx;
  142. height: 62rpx;
  143. background: #eeeeee;
  144. border-radius: 31rpx;
  145. font-size: 28rpx;
  146. font-weight: 400;
  147. color: #999999;
  148. border: 1px solid #e5e5e5;
  149. margin-right: 10rpx;
  150. }
  151. </style>