list.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!-- 页面 -->
  2. <template>
  3. <s-layout title="积分商城" navbar="normal" :leftWidth="0" :rightWidth="0">
  4. <!-- 筛选 -->
  5. <su-sticky bgColor="#fff">
  6. <view class="ss-flex">
  7. <view class="ss-flex-1">
  8. </view>
  9. <view class="list-icon" @tap="iconStatus = !iconStatus">
  10. <text v-if="iconStatus" class="sicon-goods-list" />
  11. <text v-else class="sicon-goods-card" />
  12. </view>
  13. </view>
  14. </su-sticky>
  15. <scroll-view
  16. class="scroll-box"
  17. :style="{ height: pageHeight + 'rpx' }"
  18. scroll-y="true"
  19. :scroll-with-animation="false"
  20. :enable-back-to-top="true"
  21. >
  22. <s-point-card ref="sPointCardRef" :property="sPointCardData" class="ss-p-x-20 ss-m-t-20"/>
  23. <s-empty
  24. v-if="activityTotal === 0"
  25. icon="/static/goods-empty.png"
  26. text="暂无积分商品"
  27. ></s-empty>
  28. <uni-load-more
  29. v-if="activityTotal > 0"
  30. :status="loadStatus"
  31. :content-text="{
  32. contentdown: '上拉加载更多',
  33. }"
  34. @tap="loadMore"
  35. />
  36. </scroll-view>
  37. </s-layout>
  38. </template>
  39. <script setup>
  40. import sheep from '@/sheep';
  41. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  42. import { computed, reactive, ref } from 'vue';
  43. import PointApi from '@/sheep/api/promotion/point';
  44. import SLayout from '@/sheep/components/s-layout/s-layout.vue';
  45. // 计算页面高度
  46. const { safeAreaInsets, safeArea } = sheep.$platform.device;
  47. const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
  48. const pageHeight =
  49. (safeArea.height + safeAreaInsets.bottom) * 2 + statusBarHeight - sheep.$platform.navbar - 350;
  50. const sPointCardData = ref({
  51. 'layoutType': 'twoCol',
  52. });
  53. // 布局类型
  54. const LayoutTypeEnum = {
  55. // 单列大图
  56. ONE_COL_BIG_IMG: 'oneColBigImg',
  57. // 双列
  58. TWO_COL: 'twoCol',
  59. };
  60. const sPointCardRef = ref();
  61. // true - 单列布局;false - 双列布局
  62. const iconStatus = computed({
  63. get() {
  64. return sPointCardData.value.layoutType === LayoutTypeEnum.ONE_COL_BIG_IMG;
  65. },
  66. set(newValue) {
  67. newValue ? (sPointCardData.value.layoutType = LayoutTypeEnum.ONE_COL_BIG_IMG) :
  68. (sPointCardData.value.layoutType = LayoutTypeEnum.TWO_COL);
  69. // 只有双列布局时需要
  70. if (sPointCardData.value.layoutType === LayoutTypeEnum.TWO_COL) {
  71. // 分列
  72. sPointCardRef.value.calculateGoodsColumn();
  73. }
  74. },
  75. });
  76. // 查询活动列表
  77. const activityPageParams = reactive({
  78. pageNo: 1, // 页码
  79. pageSize: 5, // 每页数量
  80. });
  81. const activityTotal = ref(0); // 活动总数
  82. const activityCount = ref(0); // 已加载活动数量
  83. const loadStatus = ref(''); // 页面加载状态
  84. async function getActivityList() {
  85. loadStatus.value = 'loading';
  86. const { data } = await PointApi.getPointActivityPage(activityPageParams);
  87. await sPointCardRef.value.concatActivity(data.list);
  88. activityCount.value = sPointCardRef.value.getActivityCount();
  89. activityTotal.value = data.total;
  90. loadStatus.value = activityCount.value < activityTotal.value ? 'more' : 'noMore';
  91. }
  92. // 加载更多
  93. function loadMore() {
  94. if (state.loadStatus !== 'noMore') {
  95. activityPageParams.pageNo += 1;
  96. getActivityList();
  97. }
  98. }
  99. // 上拉加载更多
  100. onReachBottom(() => {
  101. loadMore();
  102. });
  103. onLoad(() => {
  104. getActivityList();
  105. });
  106. </script>