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. ¥
  55. </view>
  56. </view>
  57. <view class="coupon-desc">
  58. 满{{ coupon.ruleMinSpendAmount }}元可用
  59. </view>
  60. </view>
  61. <button class="coupon-btn" @click="handleShareCoupon">
  62. 去发券
  63. </button>
  64. <ShortLinkModal v-model:show-modal="showShareModal" :share-link="couponShareLink" :share-hooks="shareHooks" />
  65. </view>
  66. </template>
  67. <style lang="scss" scoped>
  68. .spend-and-save-coupon {
  69. width: 210rpx;
  70. height: 205rpx;
  71. background-position: right top;
  72. background-repeat: no-repeat;
  73. background-size: cover;
  74. position: relative;
  75. .coupon-content {
  76. position: absolute;
  77. top: 35%;
  78. left: 51%;
  79. transform: translate(-50%, -50%);
  80. width: 162rpx;
  81. height: 158rpx;
  82. display: flex;
  83. flex-direction: column;
  84. justify-content: center;
  85. align-items: center;
  86. gap: 27rpx;
  87. .coupon-amount {
  88. position: relative;
  89. .coupon-amount-text {
  90. font-weight: 500;
  91. font-size: 66rpx;
  92. color: #ff4f3b;
  93. }
  94. .coupon-amount-icon {
  95. position: absolute;
  96. width: 24rpx;
  97. height: 24rpx;
  98. background-color: #ffffff;
  99. border-radius: 50%;
  100. bottom: 0;
  101. right: 0;
  102. transform: translate(55%, -20%);
  103. font-weight: 500;
  104. font-size: 20rpx;
  105. color: #ff1a00;
  106. display: flex;
  107. justify-content: center;
  108. align-items: center;
  109. }
  110. }
  111. .coupon-desc {
  112. font-weight: 400;
  113. font-size: 22rpx;
  114. color: #ff1a00;
  115. }
  116. }
  117. .coupon-btn {
  118. position: absolute;
  119. font-weight: 500;
  120. font-size: 22rpx;
  121. color: #f26e5f;
  122. bottom: 2rpx;
  123. left: 50%;
  124. transform: translate(-54%, 5%);
  125. padding: 0;
  126. background-color: transparent;
  127. border: none;
  128. &::after {
  129. border: none;
  130. position: unset;
  131. height: inherit;
  132. }
  133. }
  134. }
  135. </style>