spendAndSaveCoupon.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <script lang="ts" setup>
  2. import { computed, ref } from 'vue'
  3. import ShortLinkModal from '@/components/ShortLinkModal.vue'
  4. import { getImageUrl } from '@/utils/imageUtil'
  5. import { useCouponShare } from '../hooks/useCouponShare'
  6. const props = defineProps({
  7. coupon: {
  8. type: Object,
  9. default: () => ({
  10. ruleReductionAmount: '0',
  11. ruleMinSpendAmount: '0',
  12. }),
  13. }
  14. })
  15. const coupon = computed(() => props.coupon)
  16. const couponTemplateId = computed(() => coupon.value.templateId || '')
  17. // 分享弹窗相关 - 使用v-model控制弹窗显示
  18. const showShareModal = ref(false)
  19. const couponShareLink = ref('')
  20. const { shareCoupon, ...shareHooks } = useCouponShare()
  21. // 调用分享弹窗
  22. async function handleShareCoupon() {
  23. // 确保有优惠券数据
  24. if (coupon.value.templateId) {
  25. // uni.showLoading({
  26. // title: '获取分享链接中...',
  27. // mask: true,
  28. // })
  29. try {
  30. const shareLink = await shareCoupon(couponTemplateId.value)
  31. if (shareLink) {
  32. couponShareLink.value = shareLink
  33. showShareModal.value = true
  34. }
  35. }
  36. finally {
  37. // uni.hideLoading()
  38. }
  39. }
  40. }
  41. // 关闭分享弹窗
  42. function handleCloseShareModal() {
  43. console.log('分享弹窗已关闭')
  44. }
  45. </script>
  46. <template>
  47. <view class="spend-and-save-coupon" :style="{ backgroundImage: `url(${getImageUrl('@img/index/coupon1.png')})` }">
  48. <view class="coupon-content">
  49. <view class="coupon-amount">
  50. <view class="coupon-amount-text">
  51. {{ coupon.ruleReductionAmount }}
  52. </view>
  53. <view class="coupon-amount-icon">
  54. </view>
  55. </view>
  56. <view class="coupon-desc">
  57. 满{{ coupon.ruleMinSpendAmount }}元可用
  58. </view>
  59. </view>
  60. <button class="coupon-btn" @click="handleShareCoupon">
  61. 去发券
  62. </button>
  63. <ShortLinkModal v-model:show-modal="showShareModal" :share-link="couponShareLink" :share-hooks="shareHooks" />
  64. </view>
  65. </template>
  66. <style lang="scss" scoped>
  67. .spend-and-save-coupon {
  68. width: 210rpx;
  69. height: 205rpx;
  70. background-position: right top;
  71. background-repeat: no-repeat;
  72. background-size: cover;
  73. position: relative;
  74. .coupon-content {
  75. position: absolute;
  76. top: 35%;
  77. left: 51%;
  78. transform: translate(-50%, -50%);
  79. width: 162rpx;
  80. height: 158rpx;
  81. display: flex;
  82. flex-direction: column;
  83. justify-content: center;
  84. align-items: center;
  85. gap: 27rpx;
  86. .coupon-amount {
  87. position: relative;
  88. .coupon-amount-text {
  89. font-weight: 500;
  90. font-size: 66rpx;
  91. color: #ff4f3b;
  92. }
  93. .coupon-amount-icon {
  94. position: absolute;
  95. width: 24rpx;
  96. height: 24rpx;
  97. background-color: #ffffff;
  98. border-radius: 50%;
  99. bottom: 0;
  100. right: 0;
  101. transform: translate(55%, -20%);
  102. font-weight: 500;
  103. font-size: 20rpx;
  104. color: #ff1a00;
  105. display: flex;
  106. justify-content: center;
  107. align-items: center;
  108. }
  109. }
  110. .coupon-desc {
  111. font-weight: 400;
  112. font-size: 22rpx;
  113. color: #ff1a00;
  114. }
  115. }
  116. .coupon-btn {
  117. position: absolute;
  118. font-weight: 500;
  119. font-size: 22rpx;
  120. color: #f26e5f;
  121. bottom: 2rpx;
  122. left: 50%;
  123. transform: translate(-54%, 5%);
  124. padding: 0;
  125. background-color: transparent;
  126. border: none;
  127. &::after {
  128. border: none;
  129. position: unset;
  130. height: inherit;
  131. }
  132. }
  133. }
  134. </style>