getCoupon.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="coupon-list">
  3. <view v-if="couponInfo" class="coupon-box">
  4. <view class="coupon-head">
  5. <view class="coupon-sel"></view>
  6. <view class="coupon-title">
  7. <view class="coupon-title-1">{{couponInfo?couponInfo.title:''}}</view>
  8. </view>
  9. <view class="coupon-price">
  10. ¥<text>{{couponInfo?(couponInfo.couponType=='FULLSUB'?couponInfo.subAmount:couponInfo.price):''}}</text>
  11. </view>
  12. </view>
  13. <view class="coupon-desc">
  14. <view><u-icon class="icon" size="30" name="clock"></u-icon> 有效期:{{couponInfo?couponInfo.validDateStr:''}}</view>
  15. <view><u-icon class="icon" size="30" name="info-circle"></u-icon> {{couponInfo && couponInfo.ruleDesc?couponInfo.ruleDesc:''}}</view>
  16. </view>
  17. </view>
  18. <u-empty :text="noDataText" v-if="!couponInfo && status!='loading'" mode="coupon"></u-empty>
  19. <u-button class="handleSubmit" :disabled="isDisabled" shape="circle" @click="handleSubmit" type="error">确认领取</u-button>
  20. </view>
  21. </template>
  22. <script>
  23. import {couponData, receivesCoupon} from '@/api/coupon.js'
  24. export default{
  25. name: 'getCoupon',
  26. data () {
  27. return {
  28. couponInfo: null, // 领取优惠券信息
  29. isDisabled: true, // 是否可领取
  30. status: 'loading',
  31. noDataText: '暂无优惠券'
  32. }
  33. },
  34. onLoad(options) {
  35. console.log(options,'options')
  36. // 存储当前扫码的券码
  37. if (options.scene) {
  38. let scene = decodeURIComponent(options.scene);
  39. console.log(scene,'1111')
  40. //&是我们定义的参数链接方式
  41. let customerType = scene.split(',')[0];
  42. let storeId = scene.split(',')[1];
  43. let couponCode = scene.split(',')[2];
  44. console.log(scene.split(','),'222')
  45. //其他逻辑处理。。。。。
  46. this.$store.state.vuex_couponInfo.customerType = customerType
  47. this.$store.state.vuex_couponInfo.storeId = storeId
  48. this.$store.state.vuex_couponInfo.couponCode = couponCode
  49. // 获取要领取的优惠券
  50. this.getCoupon(couponCode)
  51. } else {
  52. // 判断是否扫码过
  53. if (this.$store.state.vuex_couponCode != '') {
  54. let couponCode = this.$store.state.vuex_couponCode
  55. this.getCoupon(couponCode)
  56. } else {
  57. // 返回首页
  58. uni.reLaunch({
  59. url: "/pages/index/index"
  60. })
  61. }
  62. }
  63. },
  64. methods: {
  65. // 获取要领取的优惠券
  66. getCoupon (code) {
  67. this.status = 'loading'
  68. couponData({couponCode:code}).then(res=>{
  69. this.status = 'onmore'
  70. if (res.status == 200) {
  71. this.couponInfo = res.data
  72. this.isDisabled = false
  73. } else {
  74. this.couponInfo = null
  75. this.isDisabled = true
  76. this.noDataText = res.message
  77. }
  78. })
  79. },
  80. // 确认领取优惠券
  81. handleSubmit () {
  82. let params= {
  83. wechatCustomerType: this.$store.state.vuex_couponInfo.customerType,
  84. storeId: this.$store.state.vuex_couponInfo.storeId,
  85. code: this.$store.state.vuex_couponInfo.couponCode
  86. }
  87. receivesCoupon(params).then(res =>{
  88. if (res.status == 200) {
  89. this.toashMsg('领取成功')
  90. setTimeout(()=>{
  91. uni.reLaunch({
  92. url: '/pages/index/index'
  93. })
  94. },500)
  95. }
  96. })
  97. }
  98. },
  99. }
  100. </script>
  101. <style lang="scss">
  102. .coupon-list{
  103. width: 100%;
  104. height: 100%;
  105. padding: 25rpx;
  106. .u-size-default.data-v-3bf2dba7 {
  107. margin-top: 100px;
  108. width: 60%;
  109. }
  110. }
  111. .coupon-box.diabled{
  112. background: #999;
  113. }
  114. .coupon-box{
  115. margin-bottom: 30rpx;
  116. border-radius: 15rpx;
  117. box-shadow: 2rpx 2rpx 10rpx #ddd;
  118. background: #ff0000;
  119. color: #FFFFFF;
  120. .coupon-head{
  121. display: flex;
  122. align-items: center;
  123. padding: 20rpx 30rpx;
  124. position: relative;
  125. border-bottom: 15rpx dotted #FFFFFF;
  126. margin-bottom: -8rpx;
  127. .coupon-sel{
  128. position: absolute;
  129. width: 56rpx;
  130. height: 46rpx;
  131. right: 0;
  132. top: 0;
  133. }
  134. .coupon-checked{
  135. background: url(/static/img/select.png) no-repeat center;
  136. background-size: 100% 100%;
  137. }
  138. .coupon-title{
  139. flex-grow: 1;
  140. font-size: 32rpx;
  141. }
  142. .coupon-price{
  143. padding: 0 15rpx;
  144. color: #FFFFFF;
  145. text{
  146. font-size: 60rpx;
  147. }
  148. }
  149. }
  150. .coupon-desc{
  151. padding: 10rpx 30rpx;
  152. color: #666;
  153. background: #FFFFFF;
  154. border-bottom-left-radius:10rpx;
  155. border-bottom-right-radius: 10rpx;
  156. >view{
  157. padding: 5rpx 0;
  158. }
  159. .icon{
  160. margin-right: 10rpx;
  161. }
  162. }
  163. }
  164. </style>