index.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 activeCoupon = ref(null)
  12. const routeType = ref('')
  13. const { data: couponList, isLastPage, page, reload } = usePagination(
  14. (pageNum, pageSize) => Apis.xsb.memberCouponPage({
  15. data: {
  16. pageNum,
  17. pageSize,
  18. useStatus: tabList[activeTab.value].useStatus,
  19. },
  20. }),
  21. {
  22. immediate: true,
  23. pageNum: 1,
  24. pageSize: 10,
  25. initialData: [],
  26. data: res => res.data?.list ?? [],
  27. append: true,
  28. },
  29. )
  30. onLoad((options: any) => {
  31. console.log(options)
  32. if (options.type) {
  33. routeType.value = options.type
  34. }
  35. if (options.couponId) {
  36. activeCoupon.value = options.couponId
  37. switchTab(Number(options.activeTab))
  38. }
  39. })
  40. function switchTab(index: number) {
  41. if (activeTab.value === index)
  42. return
  43. activeTab.value = index
  44. couponList.value = []
  45. reload()
  46. }
  47. onReachBottom(() => {
  48. if (!isLastPage.value) {
  49. page.value++
  50. }
  51. })
  52. </script>
  53. <template>
  54. <view class="min-h-screen bg-white">
  55. <!-- Tab 导航 -->
  56. <view class="sticky top-0 z-10 bg-white">
  57. <wd-tabs v-model="activeTab" @change="switchTab($event.index)">
  58. <wd-tab v-for="tab in tabList" :key="tab.useStatus" :title="tab.label" />
  59. </wd-tabs>
  60. </view>
  61. <!-- 列表 -->
  62. <view class="p-24rpx">
  63. <view v-for="item in couponList" :key="item.id" class="mb-20rpx">
  64. <view :class="[item.allowanceId == activeCoupon ? 'border-2rpx border-red-4 rounded-16rpx border-solid' : '']">
  65. <CouponItem
  66. :itemcoupon="item"
  67. :show-use-btn="item.useStatus === 2"
  68. :route-type="routeType"
  69. />
  70. </view>
  71. </view>
  72. <!-- 空状态 -->
  73. <StatusTip v-if="couponList.length === 0" tip="暂无内容" />
  74. <!-- 底部占位 -->
  75. <view class="h-40rpx" />
  76. </view>
  77. </view>
  78. </template>
  79. <style lang="scss" scoped></style>