spendAndSaveCoupon_large.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <script lang="ts" setup>
  2. import { computed, ref } from 'vue'
  3. import ShortLinkModal from '@/components/ShortLinkModal.vue'
  4. import { getLastPartAfterSlash } from '@/utils/couponClassFormat'
  5. import { getImageUrl } from '@/utils/imageUtil'
  6. import { useCouponShare } from '../hooks/useCouponShare'
  7. const props = defineProps({
  8. coupon: {
  9. type: Object,
  10. default: () => ({
  11. ruleReductionAmount: '0',
  12. ruleMinSpendAmount: '0',
  13. }),
  14. },
  15. scrollViewId: {
  16. type: String,
  17. default: '',
  18. },
  19. enableCustomShare: {
  20. type: Boolean,
  21. default: false,
  22. }
  23. })
  24. const emit = defineEmits(['shareClick'])
  25. const coupon = computed(() => props.coupon)
  26. const couponTemplateId = computed(() => coupon.value.templateId || '')
  27. const deadline = computed(() => {
  28. const type = props.coupon.validityType
  29. if (type === '1') {
  30. return `自领取之日起${props.coupon.validDays}日内使用`
  31. }
  32. else if (type === '2') {
  33. return `${props.coupon.validStartTime}至${props.coupon.validEndTime}`
  34. }
  35. return '长期有效'
  36. })
  37. const category = computed(() => {
  38. const relatedType = props.coupon.relatedType
  39. const relatedName = getLastPartAfterSlash(props.coupon.relatedName)
  40. if (relatedType === '1') {
  41. return `限${relatedName}分类商品使用`
  42. }
  43. else {
  44. return `限${relatedName}商品使用`
  45. }
  46. })
  47. // 分享弹窗相关 - 使用v-model控制弹窗显示
  48. const showShareModal = ref(false)
  49. const couponShareLink = ref('')
  50. const { shareCoupon, ...shareHooks } = useCouponShare()
  51. // 调用分享弹窗
  52. async function handleShareCoupon() {
  53. // 确保有优惠券数据
  54. if (coupon.value.templateId) {
  55. uni.showLoading({
  56. title: '获取分享链接中...',
  57. mask: true,
  58. })
  59. try {
  60. const shareLink = await shareCoupon(couponTemplateId.value)
  61. if (shareLink) {
  62. couponShareLink.value = shareLink
  63. showShareModal.value = true
  64. if (props.enableCustomShare) {
  65. emit('shareClick', couponShareLink.value, shareHooks)
  66. }
  67. }
  68. }
  69. finally {
  70. uni.hideLoading()
  71. }
  72. }
  73. }
  74. // 关闭分享弹窗
  75. function handleCloseShareModal() {
  76. console.log('分享弹窗已关闭')
  77. }
  78. </script>
  79. <template>
  80. <view class="discount-coupon">
  81. <image class="coupon-bg" :src="getImageUrl('@img/index/coupon3.png')" mode="aspectFit" />
  82. <view class="coupon-content">
  83. <view class="coupon-amount">
  84. <view class="coupon-amount-count">
  85. <view class="coupon-amount-count-icon">
  86. </view>
  87. <view class="coupon-amount-count-number">
  88. {{ coupon?.ruleReductionAmount }}
  89. </view>
  90. </view>
  91. <view class="coupon-amount-text">
  92. 满{{ coupon?.ruleMinSpendAmount }}元可用
  93. </view>
  94. </view>
  95. <view class="coupon-info">
  96. <view class="coupon-info-category">
  97. {{ category }}
  98. </view>
  99. <view class="coupon-info-time">
  100. <template v-if="coupon.validityType === '1'">
  101. <view>{{ deadline }}</view>
  102. </template>
  103. <template v-else-if="coupon.validityType === '2'">
  104. <view>使用日期</view>
  105. <view>{{ deadline }}</view>
  106. </template>
  107. <template v-else>
  108. <view>{{ deadline }}</view>
  109. </template>
  110. </view>
  111. </view>
  112. </view>
  113. <view class="discount-btn">
  114. <button class="coupon-btn-container" @click="handleShareCoupon">
  115. <view>立即</view>
  116. <view>发券</view>
  117. </button>
  118. <template v-if="!enableCustomShare">
  119. <ShortLinkModal v-model:show-modal="showShareModal" :coupon-id="couponTemplateId"
  120. :share-link="couponShareLink" :scroll-view-id="scrollViewId" :share-hooks="shareHooks"
  121. @close="handleCloseShareModal" />
  122. </template>
  123. </view>
  124. </view>
  125. </template>
  126. <style lang="scss" scoped>
  127. .discount-coupon {
  128. // width: 670rpx;
  129. width: 100%;
  130. max-width: 800rpx;
  131. height: 200rpx;
  132. position: relative;
  133. overflow: hidden;
  134. .coupon-bg {
  135. position: absolute;
  136. top: 0;
  137. left: 0;
  138. right: 0;
  139. width: 100%;
  140. height: 100%;
  141. z-index: 0;
  142. object-fit: cover;
  143. }
  144. .coupon-content {
  145. position: absolute;
  146. height: 161.5rpx;
  147. width: calc(100% - 27.68%);
  148. padding-top: 18rpx;
  149. padding-left: 20rpx;
  150. padding-bottom: 20rpx;
  151. display: flex;
  152. flex-direction: row;
  153. gap: 3rpx;
  154. .coupon-amount {
  155. height: 100%;
  156. width: 32%;
  157. display: flex;
  158. flex-direction: column;
  159. justify-content: center;
  160. align-items: center;
  161. .coupon-amount-count {
  162. display: flex;
  163. flex-direction: row;
  164. flex-wrap: nowrap;
  165. align-items: baseline;
  166. .coupon-amount-count-icon {
  167. font-weight: 500;
  168. font-size: 27rpx;
  169. color: #f83003;
  170. }
  171. .coupon-amount-count-number {
  172. font-weight: 500;
  173. font-size: 70rpx;
  174. color: #f83003;
  175. clear: both;
  176. }
  177. }
  178. .coupon-amount-text {
  179. font-weight: 400;
  180. font-size: 24rpx;
  181. color: #f3513b;
  182. }
  183. }
  184. .coupon-info {
  185. height: 100%;
  186. width: 68%;
  187. display: flex;
  188. flex-direction: column;
  189. justify-content: space-evenly;
  190. padding-left: 18rpx;
  191. .coupon-info-category {
  192. font-weight: 400;
  193. font-size: 32rpx;
  194. color: #333333;
  195. }
  196. .coupon-info-time {
  197. padding-top: 14rpx;
  198. display: flex;
  199. flex-direction: column;
  200. gap: 5rpx;
  201. font-weight: 400;
  202. font-size: 22rpx;
  203. color: #888888;
  204. }
  205. }
  206. }
  207. .discount-btn {
  208. position: absolute;
  209. right: 0;
  210. z-index: 1;
  211. height: 100%;
  212. width: 27.68%;
  213. display: flex;
  214. justify-content: center;
  215. align-items: center;
  216. .coupon-btn-container {
  217. width: 115rpx;
  218. height: 115rpx;
  219. transform: translateX(7rpx);
  220. padding: 17rpx 20rpx 18rpx 20rpx;
  221. background-color: transparent;
  222. border: none;
  223. font-weight: 500;
  224. font-size: 28rpx;
  225. color: #ffffff;
  226. line-height: 41rpx;
  227. &::after {
  228. border: none;
  229. position: unset;
  230. height: inherit;
  231. }
  232. }
  233. }
  234. }
  235. </style>