detail.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view :style="themeColor()">
  3. <view v-if="Object.keys(detail).length&&!loading" class="overflow-hidden min-h-screen bg-style relative"
  4. :style="{ 'background': 'url(' + img('addon/mall/coupon/coupon_bg.png') + ') no-repeat' }">
  5. <!-- #ifdef MP -->
  6. <top-tabbar :data="topTabbarData" :scrollBool="topTabarObj.getScrollBool()" />
  7. <!-- #endif -->
  8. <view class="relative mt-[236rpx] w-[100%] h-[932rpx]" :style="{ 'background': 'url(' + img('addon/mall/coupon/coupon_bg_02.png') + ') center / contain no-repeat' }">
  9. <view v-if="detail.limit_count" :style="{ 'background': 'url(' + img('addon/mall/coupon/top_tab.png') + ') center / cover no-repeat', 'transform': 'translateX(-50%)'}" class="text-[32rpx] leading-[56rpx] top-[2rpx] left-[50%] px-[30rpx] box-border justify-center absolute min-w-[196rpx] h-[56rpx] flex items-center text-[#FFF9DD]">限领{{ detail.limit_count }}张</view>
  10. <view class="flex justify-center pt-[90rpx]">
  11. <text class="max-w-[380rpx] text-[var(--price-text-color)] text-[140rpx] truncate price-font">{{ detail.coupon_price || 0.00 }}</text>
  12. <text class="flex items-center justify-center text-[44rpx] mt-[54rpx] ml-[8rpx] text-[#F7D894] bg-[var(--price-text-color)] rounded-full w-[70rpx] h-[70rpx]">元</text>
  13. </view>
  14. <view class="h-[64rpx] leading-[64rpx] text-[42rpx] text-[#E22D17] mt-[10rpx] text-center">
  15. <text v-if="detail.min_condition_money === '0.00'">无门槛</text>
  16. <text v-else>满{{ detail.coupon_min_price }}元可用</text>
  17. </view>
  18. <view class="text-[26rpx] h-[36rpx] text-[#E22D17] mt-[44rpx] text-center flex justify-center items-center">
  19. <block v-if="detail.valid_type == 1">
  20. <text>领取之日起</text>
  21. <text>{{ detail.length }}</text>
  22. <text>天内有效</text>
  23. </block>
  24. <block v-else>
  25. <text>有效期至</text>
  26. <text>{{ detail.valid_end_time ? detail.valid_end_time.slice(0, 10) : '' }}</text>
  27. </block>
  28. </view>
  29. <view class="flex justify-center items-center mt-[20rpx]">
  30. <text v-if="detail.btnType === 'collected'" class="!leading-[100rpx] text-center text-[rgba(255,255,255,1)] text-[46rpx] min-w-[240rpx] h-[106rpx]" :style="{ 'background': 'url(' + img('addon/mall/coupon/coupon_btn_02.png') + ') center / contain no-repeat' }">已领完</text>
  31. <text v-if="detail.btnType === 'collecting'" class="!leading-[100rpx] text-center text-[#E22D17] text-[46rpx] min-w-[240rpx] h-[106rpx]" :style="{ 'background': 'url(' + img('addon/mall/coupon/coupon_btn.png') + ') center / contain no-repeat' }" @click="collecting(detail.id)">领取</text>
  32. <text v-if="detail.btnType === 'using'" class="!leading-[100rpx] text-center text-[#E22D17] text-[46rpx] min-w-[240rpx] h-[106rpx]" :style="{ 'background': 'url(' + img('addon/mall/coupon/coupon_btn.png') + ') center / contain no-repeat' }" @click="toLink(detail.id)">去使用</text>
  33. <text v-if="detail.btnType === 'used'" class="!leading-[100rpx] text-center text-[rgba(255,255,255,1)] text-[46rpx] min-w-[240rpx] h-[106rpx]" :style="{ 'background': 'url(' + img('addon/mall/coupon/coupon_btn_02.png') + ') center / contain no-repeat' }">已使用</text>
  34. </view>
  35. <view class="w-[230rpx] h-[230rpx] box-border p-[14rpx] bg-[#fff] mx-[auto] mt-[50rpx]">
  36. <image class="w-[200rpx] h-[200rpx]" :src="codeUrl" mode="aspectFill" />
  37. </view>
  38. <view class="text-[24rpx] text-[rgba(255,255,255,0.7)] mt-[30rpx] text-center">注:扫描二维码或点击右上角进行分享</view>
  39. </view>
  40. </view>
  41. <loading-page :loading="loading"></loading-page>
  42. </view>
  43. </template>
  44. <script lang="ts" setup>
  45. import { ref, computed } from 'vue'
  46. import { onLoad } from '@dcloudio/uni-app'
  47. import { img, redirect, handleOnloadParams, goback } from '@/utils/common'
  48. import QRCode from "qrcode";
  49. import { topTabar } from '@/utils/topTabbar'
  50. import { getMallCouponInfo, getCoupon, getMallCouponQrocde } from '@/addon/mall/api/coupon'
  51. import useMemberStore from '@/stores/member'
  52. import { useLogin } from '@/hooks/useLogin'
  53. const loading = ref(false)
  54. const codeUrl = ref('')
  55. const detail: any = ref({})
  56. const memberStore = useMemberStore()
  57. const userInfo = computed(() => memberStore.info)
  58. /********* 自定义头部 - start ***********/
  59. const topTabarObj = topTabar()
  60. let topTabbarData = topTabarObj.setTopTabbarParam({ title: '优惠券详情' })
  61. /********* 自定义头部 - end ***********/
  62. onLoad((option: any) => {
  63. // #ifdef MP-WEIXIN
  64. // 处理小程序场景值参数
  65. option = handleOnloadParams(option);
  66. // #endif
  67. if (!option.coupon_id) {
  68. let parameter = {
  69. url: '/addon/mall/pages/coupon/list',
  70. title: '优惠券不存在'
  71. };
  72. goback(parameter)
  73. } else {
  74. getMallCouponInfoFn(option.coupon_id)
  75. getMallCouponQrocdeFn(option.coupon_id)
  76. }
  77. })
  78. const getMallCouponInfoFn = (id: number) => {
  79. loading.value = true
  80. getMallCouponInfo(id).then((res:any) => {
  81. detail.value = res.data
  82. if (!userInfo.value) {
  83. if (detail.value.sum_count != -1 && detail.value.receive_count === detail.value.sum_count) {
  84. detail.value.btnType = 'collected'//已领完
  85. } else {
  86. detail.value.btnType = 'collecting'//领用
  87. }
  88. } else {
  89. if (detail.value.is_receive) {
  90. if (detail.value.member_receive_count < detail.value.limit_count) {
  91. if (detail.value.need_receive) {
  92. detail.value.btnType = 'collecting'//领用
  93. } else {
  94. detail.value.btnType = 'using'//去使用
  95. }
  96. } else {
  97. if (detail.value.need_receive) {
  98. detail.value.btnType = 'used'//已使用
  99. } else {
  100. detail.value.btnType = 'using'//去使用
  101. }
  102. }
  103. } else {
  104. if (detail.value.sum_count != -1 && detail.value.receive_count === detail.value.sum_count) {
  105. detail.value.btnType = 'collected'//已领完
  106. } else {
  107. detail.value.btnType = 'collecting'//领用
  108. }
  109. }
  110. }
  111. loading.value = false
  112. }).catch(() => {
  113. loading.value = false
  114. detail.value = {}
  115. setTimeout(() => {
  116. redirect({ url: '/app/pages/index/index', mode: 'reLaunch' })
  117. }, 600)
  118. })
  119. }
  120. const getMallCouponQrocdeFn = (id: any) => {
  121. // #ifdef H5
  122. QRCode.toDataURL(window.location.href, { errorCorrectionLevel: 'L', margin: 0, width: 100 }).then(url => {
  123. codeUrl.value = url
  124. });
  125. // #endif
  126. // #ifdef MP-WEIXIN
  127. getMallCouponQrocde(id).then((res: any) => {
  128. if (res.data) {
  129. codeUrl.value = img(res.data);
  130. }
  131. })
  132. // #endif
  133. }
  134. const collecting = (coupon_id: any) => {
  135. if (!userInfo.value) {
  136. useLogin().setLoginBack({ url: '/addon/shop/pages/coupon/detail', param: { coupon_id: detail.value.id } })
  137. return false
  138. }
  139. getCoupon({ coupon_id, number: 1 }).then(res => {
  140. detail.value.btnType = 'using'
  141. })
  142. }
  143. const toLink = (id: any) => {
  144. redirect({ url: '/addon/mall/pages/goods/list', param: { coupon_id: id } })
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .border-color {
  149. border-color: var(--primary-color) !important;
  150. }
  151. .text-color {
  152. color: var(--primary-color) !important;
  153. }
  154. .bg-color {
  155. background-color: var(--primary-color) !important;
  156. }
  157. .bg-style {
  158. background-size: 100% 100% !important;
  159. }
  160. .code {
  161. box-shadow: 0 0 20px -1px;
  162. }
  163. </style>