list.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <!-- 积分商城:商品列表 -->
  2. <template>
  3. <s-layout title="积分商城">
  4. <view class="ss-p-20">
  5. <view v-for="item in state.pagination.data" :key="item.id" class="ss-m-b-20">
  6. <s-point-card
  7. size="sl"
  8. :data="item"
  9. priceColor="#FF3000"
  10. @tap="sheep.$router.go('/pages/goods/point', { id: item.id })"
  11. />
  12. </view>
  13. </view>
  14. <s-empty
  15. v-if="state.pagination.total === 0"
  16. icon="/static/goods-empty.png"
  17. text="暂无积分商品"
  18. />
  19. <uni-load-more
  20. v-if="state.pagination.total > 0"
  21. :status="state.loadStatus"
  22. :content-text="{
  23. contentdown: '上拉加载更多',
  24. }"
  25. @tap="loadmore"
  26. />
  27. </s-layout>
  28. </template>
  29. <script setup>
  30. import sheep from '@/sheep';
  31. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  32. import { reactive } from 'vue';
  33. import _ from 'lodash';
  34. const state = reactive({
  35. pagination: {
  36. data: [],
  37. current_page: 1,
  38. total: 1,
  39. last_page: 1,
  40. },
  41. loadStatus: '',
  42. });
  43. async function getData(page = 1, list_rows = 5) {
  44. // TODO @puhui999:分页重写成,我们的代码风格。原先的有点复杂
  45. state.loadStatus = 'loading';
  46. let res = await sheep.$api.app.scoreShop.list({
  47. list_rows,
  48. page,
  49. });
  50. if (res.error === 0) {
  51. let couponlist = _.concat(state.pagination.data, res.data.data);
  52. state.pagination = {
  53. ...res.data,
  54. data: couponlist,
  55. };
  56. if (state.pagination.current_page < state.pagination.last_page) {
  57. state.loadStatus = 'more';
  58. } else {
  59. state.loadStatus = 'noMore';
  60. }
  61. }
  62. }
  63. // 加载更多
  64. function loadmore() {
  65. if (state.loadStatus !== 'noMore') {
  66. getData(state.pagination.current_page + 1);
  67. }
  68. }
  69. // 上拉加载更多
  70. onReachBottom(() => {
  71. loadmore();
  72. });
  73. onLoad(() => {
  74. getData();
  75. });
  76. </script>