templateCoupon.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. import { getPlatformSource } from '@/utils/platformSource'
  8. const props = defineProps({
  9. coupon: {
  10. type: Object,
  11. default: () => ({
  12. ruleDiscountRate: '0',
  13. ruleMinSpendAmount: '0',
  14. relatedName: '',
  15. ruleDiscountCapAmount: '0',
  16. validityType: '1',
  17. }),
  18. },
  19. scrollViewId: {
  20. type: String,
  21. default: '',
  22. },
  23. enableCustomShare: {
  24. type: Boolean,
  25. default: false,
  26. }
  27. })
  28. const emit = defineEmits(['shareClick'])
  29. const coupon = computed(() => props.coupon)
  30. const couponTemplateId = computed(() => coupon.value.templateId || '')
  31. const deadline = computed(() => {
  32. const type = props.coupon.validityType
  33. if (type === '2') {
  34. return `领取后${props.coupon.validDays}天过期`
  35. // return `自领取之日起${props.coupon.validDays}日内使用`
  36. }
  37. else if (type === '1') {
  38. return `${props.coupon.validEndTime}`
  39. // return `限${props.coupon.validStartTime}到${props.coupon.validEndTime}日内使用`
  40. }
  41. return '长期有效'
  42. })
  43. const category = computed(() => {
  44. const relatedType = coupon.value.relatedType
  45. if (coupon.value?.relatedName && coupon.value?.relatedName !== 'null') {
  46. let relatedName = coupon.value.relatedName
  47. if (relatedType === '2') {
  48. relatedName = getLastPartAfterSlash(coupon.value.relatedName)
  49. return `仅限${relatedName}分类商品使用`
  50. } else if (relatedType === '3') {
  51. return `仅限部分商品使用`
  52. }
  53. else {
  54. return `仅限${relatedName}商品使用`
  55. }
  56. }
  57. return '不限商品分类'
  58. })
  59. // 分享弹窗相关 - 使用v-model控制弹窗显示
  60. const showShareModal = ref(false)
  61. const couponShareLink = ref('')
  62. const isExpand = ref(false);
  63. const { shareCoupon, ...shareHooks } = useCouponShare()
  64. // 调用分享弹窗
  65. async function handleShareCoupon() {
  66. // 确保有优惠券数据
  67. if (coupon.value.templateId) {
  68. // uni.showLoading({
  69. // title: '获取分享链接中...',
  70. // mask: true,
  71. // })
  72. try {
  73. const shareLink = await shareCoupon(couponTemplateId.value)
  74. console.log(couponTemplateId.value, '分享链接========');
  75. if (shareLink) {
  76. couponShareLink.value = shareLink
  77. showShareModal.value = true
  78. if (props.enableCustomShare) {
  79. emit('shareClick', couponShareLink.value, shareHooks)
  80. }
  81. }
  82. }
  83. finally {
  84. // uni.hideLoading()
  85. }
  86. }
  87. }
  88. // 关闭分享弹窗
  89. function handleCloseShareModal() {
  90. console.log('分享弹窗已关闭')
  91. }
  92. </script>
  93. <template>
  94. <view class="discount-coupon">
  95. <image class="coupon-bg" :src="getImageUrl('@img/index/new-coupon-bg.png')" mode="aspectFill" />
  96. <view class="discount-coupon-content">
  97. <view class="discount-coupon-info-container">
  98. <view class="discount-coupon-info-content">
  99. <view :class="coupon.ruleReductionAmount && String(coupon.ruleReductionAmount).length > 2 ? 'discount-coupon-info-price scale' : 'discount-coupon-info-price'">
  100. <text class="discount-coupon-info-number">
  101. {{ coupon.type === '2' ? coupon?.ruleDiscountRate : coupon?.ruleReductionAmount }}
  102. </text>
  103. <view class="discount-coupon-info-unit">
  104. {{ coupon.type === '2' ? '折' : '元' }}
  105. </view>
  106. </view>
  107. <view class="discount-coupon-info-desc">
  108. <view class="desc-text">
  109. {{ coupon.name }}
  110. </view>
  111. <view class="desc-type" @tap="isExpand = !isExpand">
  112. <text v-if="coupon.type === '2'">最高优惠{{ coupon.ruleDiscountCapAmount }}元,满{{ coupon.ruleMinSpendAmount }}元可用</text>
  113. <text v-else>满{{ coupon.ruleMinSpendAmount }}元可用</text>
  114. </view>
  115. <view class="desc-type" @tap="isExpand = !isExpand">
  116. 有效期限:{{ deadline }}
  117. </view>
  118. <view class="desc-more" @tap="isExpand = !isExpand">
  119. {{isExpand ? '收起详情' : '展开详情 '}}
  120. <up-icon v-if="isExpand" size="10" color="#FF4129" name="arrow-up" />
  121. <up-icon size="10" color="#FF4129" v-else name="arrow-down" />
  122. </view>
  123. </view>
  124. </view>
  125. </view>
  126. <view class="discount-btn-container">
  127. <view class="share-text">分享赚 ¥{{ coupon.pushCouponAverageAmount }}</view>
  128. <view class="btn-bg">
  129. <button class="discount-btn" @click="handleShareCoupon">去分享</button>
  130. </view>
  131. </view>
  132. </view>
  133. <!-- <up-transition :show="isExpand" mode="fade-down" duration="300"> -->
  134. <view :class="['coupon-info', isExpand ? 'expanded' : 'collapsed']">
  135. <view class="info-content">
  136. <view class="info-item">
  137. <view class="item-title">券类型:</view>
  138. <view class="item-content">{{ coupon.type === '2' ? '折扣券' : '满减券' }}</view>
  139. </view>
  140. <view class="info-item">
  141. <view class="item-title">限定地区:</view>
  142. <view class="item-content">
  143. <view v-if="coupon.relatedType == '3'">仅可在部分地区使用</view>
  144. <view v-else>{{ coupon?.locality && coupon?.locality !== 'null' ? `仅可在${coupon?.locality}地区的商户使用` : '不限地区' }}</view>
  145. </view>
  146. </view>
  147. <view class="info-item">
  148. <view class="item-title">限定商户:</view>
  149. <view class="item-content">
  150. <view v-if="coupon.relatedType == '3'">仅限部分商户使用</view>
  151. <view v-else>{{ coupon?.storeName && coupon?.storeName !== 'null' ? `仅限${coupon?.storeName}商户使用` : '不限商户' }}</view>
  152. </view>
  153. </view>
  154. <view class="info-item">
  155. <view class="item-title">限定商品:</view>
  156. <view class="item-content">{{ category }}</view>
  157. </view>
  158. <view class="info-item">
  159. <view class="item-title">限定平台:</view>
  160. <view class="item-content">仅限{{ getPlatformSource(coupon?.platformSource) }}平台使用</view>
  161. </view>
  162. </view>
  163. </view>
  164. <!-- </up-transition> -->
  165. <template v-if="!enableCustomShare">
  166. <ShortLinkModal v-model:show-modal="showShareModal" :coupon-id="couponTemplateId" :share-hooks="shareHooks"
  167. :share-link="couponShareLink" :scroll-view-id="scrollViewId" @close="handleCloseShareModal" />
  168. </template>
  169. </view>
  170. </template>
  171. <style lang="scss" scoped>
  172. .discount-coupon {
  173. width: 100%;
  174. // max-height: 800rpx;
  175. position: relative;
  176. font-weight: 400;
  177. .coupon-bg {
  178. position: absolute;
  179. top: 0;
  180. left: 0;
  181. width: 100%;
  182. height: 170rpx;
  183. object-fit: cover;
  184. z-index: 1;
  185. border-radius: 10rpx;
  186. }
  187. .discount-coupon-content {
  188. width: 100%;
  189. display: flex;
  190. flex-direction: row;
  191. flex-wrap: nowrap;
  192. height: 170rpx;
  193. .discount-coupon-info-container {
  194. width: 73.47%;
  195. display: flex;
  196. flex-direction: column;
  197. z-index: 1;
  198. .discount-coupon-info-content {
  199. width: 100%;
  200. height: 100%;
  201. display: flex;
  202. flex-direction: row;
  203. flex-wrap: nowrap;
  204. .discount-coupon-info-price {
  205. width: 125rpx;
  206. height: 100%;
  207. display: flex;
  208. flex-direction: row;
  209. flex-wrap: nowrap;
  210. align-items: center;
  211. justify-content: center;
  212. gap: 5rpx;
  213. font-family: D-DIN Exp-DINExp, D-DIN Exp-DINExp;
  214. .discount-coupon-info-number {
  215. font-weight: bold;
  216. font-size: 60rpx;
  217. color: #FF5365;
  218. letter-spacing: -4rpx;
  219. }
  220. .discount-coupon-info-unit {
  221. font-weight: 500;
  222. font-size: 26rpx;
  223. color: #FF5365;
  224. padding-top: 18rpx;
  225. }
  226. }
  227. .scale {
  228. scale: 0.8;
  229. }
  230. .discount-coupon-info-desc {
  231. display: flex;
  232. flex-direction: column;
  233. justify-content: center;
  234. gap: 4rpx;
  235. padding-left: 4rpx;
  236. .desc-text {
  237. max-width: 290rpx;
  238. overflow: hidden;
  239. text-overflow: ellipsis;
  240. white-space: nowrap;
  241. flex-wrap: nowrap;
  242. font-weight: 600;
  243. font-size: 24rpx;
  244. color: #000000;
  245. line-height: 34rpx;
  246. }
  247. .desc-type {
  248. font-size: 20rpx;
  249. color: #808080;
  250. line-height: 28rpx;
  251. display: flex;
  252. flex-wrap: nowrap;
  253. }
  254. .desc-more {
  255. font-size: 20rpx;
  256. color: #FF4129;
  257. display: flex;
  258. flex-wrap: nowrap;
  259. gap: 4rpx;
  260. }
  261. }
  262. }
  263. }
  264. .discount-btn-container {
  265. height: 100%;
  266. width: 26.53%;
  267. display: flex;
  268. flex-direction: column;
  269. justify-content: center;
  270. align-items: center;
  271. .share-text {
  272. font-weight: 500;
  273. font-size: 22rpx;
  274. color: #FFFFFF;
  275. z-index: 2;
  276. margin-bottom: 7rpx;
  277. }
  278. .btn-bg {
  279. z-index: 2;
  280. .discount-btn {
  281. display: flex;
  282. height: 48rpx;
  283. padding: 7rpx 24rpx;
  284. line-height: 34rpx;
  285. background: #FFFFFF;
  286. border-radius: 999rpx 999rpx 999rpx 999rpx;
  287. font-weight: 600;
  288. font-size: 24rpx;
  289. color: #FF5365;
  290. letter-spacing: 1rpx;
  291. }
  292. }
  293. }
  294. }
  295. .coupon-info {
  296. margin-top: -4rpx;
  297. padding: 16rpx 26rpx 12rpx;
  298. background: rgba(255,140,58,0.15);
  299. border-radius: 0 0 32rpx 32rpx;
  300. overflow: hidden;
  301. transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  302. box-shadow: 1rpx 1rpx 10rpx #fff9f4;
  303. .info-content {
  304. display: flex;
  305. flex-direction: column;
  306. align-items: flex-start;
  307. gap: 5rpx;
  308. .info-item {
  309. display: flex;
  310. flex-direction: row;
  311. flex-wrap: nowrap;
  312. align-items: top;
  313. justify-content: flex-start;
  314. gap: 10rpx;
  315. font-size: 18rpx;
  316. color: #808080;
  317. .item-title {
  318. width:80rpx;
  319. }
  320. .item-content {
  321. flex: 1;
  322. }
  323. }
  324. }
  325. }
  326. /* 收起状态 */
  327. .coupon-info.collapsed {
  328. opacity: 0;
  329. max-height: 0;
  330. padding-top: 0;
  331. padding-bottom: 0;
  332. border-top-width: 0;
  333. border-bottom-width: 0;
  334. }
  335. /* 展开状态 */
  336. .coupon-info.expanded {
  337. opacity: 1;
  338. max-height: 500rpx;
  339. /* 设置一个足够大的值以容纳所有内容 */
  340. padding-top: 20rpx;
  341. padding-bottom: 20rpx;
  342. border-top-width: 11rpx;
  343. border-bottom-width: 11rpx;
  344. }
  345. }
  346. </style>