index.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <script setup lang="ts">
  2. import CouponItem from '../components/coupon/index.vue'
  3. definePage({ name: 'xsb-coupon', islogin: true, style: { navigationBarTitleText: '优惠券列表' } })
  4. const tabList = [
  5. { label: '待使用', useStatus: 2 },
  6. { label: '已使用', useStatus: 1 },
  7. { label: '已过期', useStatus: 5 },
  8. { label: '冻结', useStatus: 7 },
  9. ]
  10. const activeTab = ref(0)
  11. const { data: couponList, isLastPage, page, reload } = usePagination(
  12. (pageNum, pageSize) => Apis.xsb.memberCouponPage({
  13. data: {
  14. pageNum,
  15. pageSize,
  16. useStatus: tabList[activeTab.value].useStatus,
  17. },
  18. }),
  19. {
  20. immediate: true,
  21. pageNum: 1,
  22. pageSize: 10,
  23. initialData: [],
  24. data: res => res.data?.list ?? [],
  25. append: true,
  26. },
  27. )
  28. function switchTab(index: number) {
  29. if (activeTab.value === index)
  30. return
  31. activeTab.value = index
  32. couponList.value = []
  33. reload()
  34. }
  35. onReachBottom(() => {
  36. if (!isLastPage.value) {
  37. page.value++
  38. }
  39. })
  40. </script>
  41. <template>
  42. <view class="min-h-screen bg-white">
  43. <!-- Tab 导航 -->
  44. <view class="sticky top-0 z-10 bg-white">
  45. <wd-tabs v-model="activeTab" @change="switchTab($event.index)">
  46. <wd-tab v-for="tab in tabList" :key="tab.useStatus" :title="tab.label" />
  47. </wd-tabs>
  48. </view>
  49. <!-- 列表 -->
  50. <view class="p-24rpx">
  51. <view v-for="item in couponList" :key="item.id" class="mb-20rpx">
  52. <CouponItem
  53. :itemcoupon="item"
  54. :show-use-btn="item.useStatus === 2"
  55. />
  56. </view>
  57. <!-- 空状态 -->
  58. <StatusTip v-if="couponList.length === 0" tip="暂无内容" />
  59. <!-- 底部占位 -->
  60. <view class="h-40rpx" />
  61. </view>
  62. </view>
  63. </template>
  64. <style lang="scss" scoped></style>