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. ¥
  87. </view>
  88. <view class="coupon-amount-count-number">
  89. {{ coupon?.ruleReductionAmount }}
  90. </view>
  91. </view>
  92. <view class="coupon-amount-text">
  93. 满{{ coupon?.ruleMinSpendAmount }}元可用
  94. </view>
  95. </view>
  96. <view class="coupon-info">
  97. <view class="coupon-info-category">
  98. {{ category }}
  99. </view>
  100. <view class="coupon-info-time">
  101. <template v-if="coupon.validityType === '1'">
  102. <view>{{ deadline }}</view>
  103. </template>
  104. <template v-else-if="coupon.validityType === '2'">
  105. <view>使用日期</view>
  106. <view>{{ deadline }}</view>
  107. </template>
  108. <template v-else>
  109. <view>{{ deadline }}</view>
  110. </template>
  111. </view>
  112. </view>
  113. </view>
  114. <view class="discount-btn">
  115. <button class="coupon-btn-container" @click="handleShareCoupon">
  116. <view>立即</view>
  117. <view>发券</view>
  118. </button>
  119. <template v-if="!enableCustomShare">
  120. <ShortLinkModal v-model:show-modal="showShareModal" :coupon-id="couponTemplateId"
  121. :share-link="couponShareLink" :scroll-view-id="scrollViewId" :share-hooks="shareHooks"
  122. @close="handleCloseShareModal" />
  123. </template>
  124. </view>
  125. </view>
  126. </template>
  127. <style lang="scss" scoped>
  128. .discount-coupon {
  129. // width: 670rpx;
  130. width: 100%;
  131. max-width: 800rpx;
  132. height: 200rpx;
  133. position: relative;
  134. overflow: hidden;
  135. .coupon-bg {
  136. position: absolute;
  137. top: 0;
  138. left: 0;
  139. right: 0;
  140. width: 100%;
  141. height: 100%;
  142. z-index: 0;
  143. object-fit: cover;
  144. }
  145. .coupon-content {
  146. position: absolute;
  147. height: 161.5rpx;
  148. width: calc(100% - 27.68%);
  149. padding-top: 18rpx;
  150. padding-left: 20rpx;
  151. padding-bottom: 20rpx;
  152. display: flex;
  153. flex-direction: row;
  154. gap: 3rpx;
  155. .coupon-amount {
  156. height: 100%;
  157. width: 32%;
  158. display: flex;
  159. flex-direction: column;
  160. justify-content: center;
  161. align-items: center;
  162. .coupon-amount-count {
  163. display: flex;
  164. flex-direction: row;
  165. flex-wrap: nowrap;
  166. align-items: baseline;
  167. .coupon-amount-count-icon {
  168. font-weight: 500;
  169. font-size: 27rpx;
  170. color: #f83003;
  171. }
  172. .coupon-amount-count-number {
  173. font-weight: 500;
  174. font-size: 70rpx;
  175. color: #f83003;
  176. clear: both;
  177. }
  178. }
  179. .coupon-amount-text {
  180. font-weight: 400;
  181. font-size: 24rpx;
  182. color: #f3513b;
  183. }
  184. }
  185. .coupon-info {
  186. height: 100%;
  187. width: 68%;
  188. display: flex;
  189. flex-direction: column;
  190. justify-content: space-evenly;
  191. padding-left: 18rpx;
  192. .coupon-info-category {
  193. font-weight: 400;
  194. font-size: 32rpx;
  195. color: #333333;
  196. }
  197. .coupon-info-time {
  198. padding-top: 14rpx;
  199. display: flex;
  200. flex-direction: column;
  201. gap: 5rpx;
  202. font-weight: 400;
  203. font-size: 22rpx;
  204. color: #888888;
  205. }
  206. }
  207. }
  208. .discount-btn {
  209. position: absolute;
  210. right: 0;
  211. z-index: 1;
  212. height: 100%;
  213. width: 27.68%;
  214. display: flex;
  215. justify-content: center;
  216. align-items: center;
  217. .coupon-btn-container {
  218. width: 115rpx;
  219. height: 115rpx;
  220. transform: translateX(7rpx);
  221. padding: 17rpx 20rpx 18rpx 20rpx;
  222. background-color: transparent;
  223. border: none;
  224. font-weight: 500;
  225. font-size: 28rpx;
  226. color: #ffffff;
  227. line-height: 41rpx;
  228. &::after {
  229. border: none;
  230. position: unset;
  231. height: inherit;
  232. }
  233. }
  234. }
  235. }
  236. </style>