list.vue 3.4 KB

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