couponArrivalPopup.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <script setup lang="ts">
  2. import { dayjs } from 'wot-design-uni'
  3. import { StaticUrl } from '@/config'
  4. const emit = defineEmits<{
  5. use: [coupon: Api.AppMemberCouponVO]
  6. }>()
  7. const show = ref(false)
  8. const couponList = ref<Api.AppMemberCouponVO[]>([])
  9. function getCouponTitle(coupon: Api.AppMemberCouponVO) {
  10. return coupon.activityName || coupon.couponName || '星闪豹优惠券'
  11. }
  12. function getCouponThreshold(coupon: Api.AppMemberCouponVO) {
  13. return Number(coupon.amountMoney || 0) > 0 ? `满${coupon.amountMoney}可用` : '无门槛'
  14. }
  15. function getCouponExpireTime(coupon: Api.AppMemberCouponVO) {
  16. if (!coupon.expirationTime) {
  17. return '长期有效'
  18. }
  19. return dayjs(coupon.expirationTime).format('YYYY-MM-DD HH:mm:ss')
  20. }
  21. function handleUse(coupon: Api.AppMemberCouponVO) {
  22. show.value = false
  23. emit('use', coupon)
  24. }
  25. async function tryShowCouponArrivalPopup() {
  26. try {
  27. const res = await Apis.xsb.newCouponPopup({})
  28. couponList.value = res.data ?? []
  29. show.value = couponList.value.length > 0
  30. }
  31. catch (error) {
  32. console.error('get coupon arrival popup failed', error)
  33. }
  34. }
  35. tryShowCouponArrivalPopup()
  36. </script>
  37. <template>
  38. <wd-overlay :show="show" :z-index="100001">
  39. <view class="h-full w-full flex items-center justify-center">
  40. <view :style="{ backgroundImage: `url(${StaticUrl}/xsb-coupon-idx-popup-bg.png)` }" class="relative h1078rpx w702rpx bg-contain bg-no-repeat" @click.stop>
  41. <view class="absolute left-0 top-180rpx box-border h-full w-full flex justify-center px-66rpx pb-60rpx pt-184rpx">
  42. <scroll-view scroll-y class="mt-110rpx box-border h-362rpx w500rpx flex justify-center px-20rpx pb-20rpx">
  43. <view v-for="coupon in couponList" :key="coupon.id || coupon.allowanceId" :style="{ backgroundImage: `url(${StaticUrl}/xsb-coupon-idx-bg-popup.png)` }" class="relative mb-20rpx h-164rpx w450rpx bg-contain bg-no-repeat">
  44. <view class="absolute left-0 top-0 box-border h-full w-full flex items-center px12rpx py24rpx">
  45. <view class="h-full w-full flex items-center">
  46. <view class="box-border w115rpx flex-shrink-0 text-center">
  47. <view class="absolute left-0 top-0 inline-flex rounded-br-10rpx rounded-tl-10rpx bg-[#FF5A36] px-16rpx py-6rpx text-20rpx text-white">
  48. {{ Number(coupon.amountMoney) > 0 ? '满减券' : '无门槛' }}
  49. </view>
  50. <view class="mt-18rpx text-[#FF5331] font-bold">
  51. <text class="text-20rpx">
  52. </text>
  53. <text class="text-40rpx leading-none">
  54. {{ coupon.discountMoney ?? 0 }}
  55. </text>
  56. </view>
  57. <view class="mt-10rpx text-24rpx text-[#666666]">
  58. {{ getCouponThreshold(coupon) }}
  59. </view>
  60. </view>
  61. <view class="box-border min-w-0 flex-1 pl30rpx">
  62. <view class="text-28rpx text-[#333333] font-semibold">
  63. {{ getCouponTitle(coupon) }}
  64. </view>
  65. <view class="mt-20rpx text-24rpx text-[#9A9A9A]">
  66. 有效期:
  67. </view>
  68. <view class="mt-6rpx text-24rpx text-[#A8A8A8]">
  69. {{ getCouponExpireTime(coupon) }}
  70. </view>
  71. <view class="coupon-arrival-card__action absolute right-22rpx top-50% rounded-full bg-[#FF5736] px-24rpx py-12rpx text-24rpx text-white -translate-y-50%" @click.stop="handleUse(coupon)">
  72. 去使用
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </scroll-view>
  79. </view>
  80. <image :src="`${StaticUrl}/xsb-coupon-idx-kaixing-btn.png`" class="absolute bottom-90rpx left-50% h112rpx w384rpx transform -translate-x-50%" @click.stop="show = false" />
  81. </view>
  82. </view>
  83. </wd-overlay>
  84. </template>
  85. <style scoped lang="scss">
  86. </style>