list.vue 3.5 KB

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