list.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!-- 页面 -->
  2. <template>
  3. <s-layout :title="$t('goods.comment.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="$t('goods.comment.noData')" 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: $t('activity.index.uploadMore'),
  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 { code, data } = await sheep.$api.goods.getType(id);
  60. if (code === 1) {
  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.code === 1) {
  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. }
  105. </style>