detail.vue 7.9 KB

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