index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="container">
  3. <!-- 优惠券信息 -->
  4. <view class="info">
  5. <view class="info_name">{{ info.couponName }}</view>
  6. <view class="info_term" v-if="info.minMoney">满{{ info.minMoney || 0 }}可用</view>
  7. <view class="info_box">
  8. <text class="text">¥</text>
  9. {{ info.money || 0 }}
  10. </view>
  11. <view class="info_btn" @click="handleFetch">立即领取</view>
  12. <view class="info_time" v-if="info.expirationTime">{{ info.expirationTime }}到期</view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. shopId: '',
  21. couponId: '',
  22. info: {}
  23. }
  24. },
  25. onLoad(option) {
  26. if (option.scene) {
  27. const scene = decodeURIComponent(option.scene)
  28. let params = {}
  29. // 分割成键值对数组
  30. let pairs = scene.split('&')
  31. // 遍历并解析每个键值对
  32. pairs.forEach((pair) => {
  33. const [key, value] = pair.split('=')
  34. params[key] = value
  35. })
  36. this.shopId = params.shopId
  37. this.couponId = params.couponId
  38. this.getInfo()
  39. }
  40. },
  41. methods: {
  42. getInfo() {
  43. let data = {
  44. couponId: this.couponId
  45. }
  46. this.$Request.get('/app/coupon/selectCoupon', data).then((res) => {
  47. // console.log(res, 963)
  48. if (res.code == 0) {
  49. this.info = res.data
  50. }
  51. })
  52. },
  53. handleFetch() {
  54. let userId = uni.getStorageSync('userId')
  55. if (userId) {
  56. let data = {
  57. couponId: this.couponId,
  58. shopId: this.shopId,
  59. userId
  60. }
  61. this.$Request.get('/app/coupon/receiveCoupon', data).then((res) => {
  62. // console.log(res, 888)
  63. if (res.code == 0) {
  64. uni.showToast({
  65. title: '领取成功',
  66. icon: 'success'
  67. })
  68. setTimeout(() => {
  69. uni.reLaunch({
  70. url: '/my/coupon/index'
  71. })
  72. }, 1500)
  73. } else {
  74. uni.showToast({
  75. title: res.msg,
  76. icon: 'none'
  77. })
  78. }
  79. })
  80. } else {
  81. uni.showToast({
  82. title: '请先登录',
  83. icon: 'none'
  84. })
  85. setTimeout(() => {
  86. uni.navigateTo({
  87. url: '/pages/public/login'
  88. })
  89. }, 1500)
  90. }
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .container {
  97. display: flex;
  98. align-items: center;
  99. justify-content: center;
  100. width: 100vw;
  101. height: 100vh;
  102. background-image: url('https://mxys.chuanghai-tech.com/wmfile/20250926/a27624ab752f4623ab069c555e497531.png');
  103. background-size: 100% 100%;
  104. .info {
  105. margin-top: 4vh;
  106. width: 42vw;
  107. height: 30vh;
  108. color: #fd322e;
  109. .info_name {
  110. font-size: 36rpx;
  111. }
  112. .info_term {
  113. margin-top: 10rpx;
  114. font-size: 32rpx;
  115. }
  116. .info_box {
  117. margin-left: 90rpx;
  118. font-size: 150rpx;
  119. .text {
  120. margin-right: 35rpx;
  121. font-size: 60rpx;
  122. }
  123. }
  124. .info_btn {
  125. display: flex;
  126. align-items: center;
  127. justify-content: center;
  128. margin: 10rpx 0 20rpx 35rpx;
  129. width: 262rpx;
  130. height: 74rpx;
  131. font-size: 40rpx;
  132. color: #fff;
  133. border-radius: 32rpx;
  134. background-color: #fd322e;
  135. }
  136. .info_time {
  137. width: 100%;
  138. text-align: center;
  139. color: #000;
  140. font-size: 24rpx;
  141. }
  142. }
  143. }
  144. </style>