score-shop.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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-score-card
  7. size="sl"
  8. :data="item"
  9. priceColor="#FF3000"
  10. @tap="sheep.$router.go('/pages/goods/score', { id: item.id })"
  11. ></s-score-card>
  12. </view>
  13. </view>
  14. <s-empty
  15. v-if="state.pagination.total === 0"
  16. icon="/static/goods-empty.png"
  17. text="暂无积分商品"
  18. ></s-empty>
  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. state.loadStatus = 'loading';
  45. let res = await sheep.$api.app.scoreShop.list({
  46. list_rows,
  47. page,
  48. });
  49. if (res.error === 0) {
  50. let couponlist = _.concat(state.pagination.data, res.data.data);
  51. state.pagination = {
  52. ...res.data,
  53. data: couponlist,
  54. };
  55. if (state.pagination.current_page < state.pagination.last_page) {
  56. state.loadStatus = 'more';
  57. } else {
  58. state.loadStatus = 'noMore';
  59. }
  60. }
  61. }
  62. // 加载更多
  63. function loadmore() {
  64. if (state.loadStatus !== 'noMore') {
  65. getData(state.pagination.current_page + 1);
  66. }
  67. }
  68. // 上拉加载更多
  69. onReachBottom(() => {
  70. loadmore();
  71. });
  72. onLoad(() => {
  73. getData();
  74. });
  75. </script>