index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <page title="领取卡券" ref="pageRef" light nav-color="transparent">
  3. <view v-if="list && list.length > 0">
  4. <view class="cell" v-for="item in list" :key="item.id">
  5. <view class="flex-align relative" style="height: 188rpx" :style="{opacity: item.status === 1 ? '1' : '0.6'}">
  6. <image class="bg" :src="item.status === 1 ? resource.center_bg_coupon : resource.center_bg_coupon_invalid"
  7. mode="scaleToFill" />
  8. <view class="left self-stretch flex-column-align-center">
  9. <view class="color-white">
  10. <text class="font8">¥</text>
  11. <text class="bold marginL2" style="font-size: 72rpx">{{item.amount}}</text>
  12. </view>
  13. <view class="marginT10 font4">
  14. <text v-if="item.fullAmount > 0">满{{item.fullAmount}}可用</text>
  15. <text v-else>无门槛</text>
  16. </view>
  17. </view>
  18. <view class="flex1 self-stretch flex-column-around marginL10 paddingY5">
  19. <view class="font4">{{item.name}}</view>
  20. <view class="font3">领取截止:{{item.endTime}}</view>
  21. <view class="font2" style="opacity: 0.8" @click="spread(item)">
  22. 使用规则
  23. <text class="lg color-white" :class="[item.spread ? 'cuIcon-fold' : 'cuIcon-unfold']"></text>
  24. </view>
  25. </view>
  26. <button v-if="item.status === 1" class="btn color-theme" @click="take(item)">领取</button>
  27. </view>
  28. <view class="rule" v-if="item.spread">
  29. {{item.description}}
  30. </view>
  31. </view>
  32. </view>
  33. <empty v-else :top="200" />
  34. </page>
  35. </template>
  36. <script>
  37. import empty from '@/components/empty'
  38. import store from '@/store'
  39. import resource from '@/utils/resource'
  40. export default {
  41. components: { empty },
  42. data() {
  43. return {
  44. resource,
  45. list: [],
  46. id: null,
  47. requestCouponTime: null
  48. }
  49. },
  50. onLoad(options) {
  51. if (options.q) {
  52. let qrUrl = decodeURIComponent(options.q)
  53. let qrObj = this.$common.getQueryObj(qrUrl)
  54. this.scene = qrObj.scene
  55. this.sceneId = qrObj.id
  56. this.couponId = qrObj.couponId
  57. } else {
  58. this.scene = options.scene
  59. this.sceneId = options.id
  60. this.couponId = options.couponId
  61. }
  62. this.$event.on(this.$event.key.LANUCH_COUPON, this.initCoupon)
  63. },
  64. onUnload() {
  65. this.$event.on(this.$event.key.LANUCH_COUPON)
  66. },
  67. mounted() {
  68. setTimeout(() => {
  69. this.initCoupon()
  70. }, 100)
  71. },
  72. onPullDownRefresh() {
  73. this.getData(false)
  74. },
  75. methods: {
  76. async initCoupon() {
  77. let token = store.state.token
  78. if (!token) {
  79. token = this.$cache.get(this.$cache.key.TEMP_TOKEN)
  80. }
  81. if (!token) return
  82. let now = new Date().getTime()
  83. if (this.requestCouponTime && now - this.requestCouponTime < 2 * 60 * 1000) {
  84. return
  85. }
  86. this.requestCouponTime = now
  87. this.getData(true)
  88. },
  89. async getData(loading = false) {
  90. const res = await this.$service.wallet.couponByQr(this.couponId, loading)
  91. uni.stopPullDownRefresh()
  92. this.list = res ? [res] : null
  93. },
  94. async take(item) {
  95. if (!this.$common.isLogin()) {
  96. this.$router.push('login')
  97. return
  98. }
  99. const res = await this.$service.wallet.receiveCoupon(item.id)
  100. if (res) {
  101. this.$message.success('领取成功')
  102. this.getData()
  103. setTimeout(() => {
  104. let curPages = getCurrentPages()
  105. if (curPages.length > 1) {
  106. this.$router.back()
  107. } else {
  108. this.$router.replace('coupon')
  109. }
  110. }, 1000)
  111. }
  112. },
  113. spread(item) {
  114. this.$set(item, 'spread', !item.spread)
  115. }
  116. }
  117. }
  118. </script>
  119. <style>
  120. </style>
  121. <style lang="scss" scoped>
  122. .cell {
  123. color: #fff;
  124. margin: 20rpx 28rpx 0;
  125. position: relative;
  126. .bg {
  127. position: absolute;
  128. top: 0;
  129. left: 0;
  130. height: 100%;
  131. width: 100%;
  132. z-index: -1;
  133. }
  134. .left {
  135. width: 244rpx;
  136. margin: 10rpx 0;
  137. border-right: 2rpx dashed #fff;
  138. }
  139. .btn {
  140. position: absolute;
  141. right: 30rpx;
  142. bottom: 18rpx;
  143. height: 48rpx;
  144. line-height: 48rpx;
  145. border-radius: 24rpx;
  146. text-align: center;
  147. padding: 0 16rpx;
  148. font-size: 28rpx;
  149. background: #fff;
  150. }
  151. .rule {
  152. background: #333333;
  153. border-bottom-right-radius: 8rpx;
  154. border-bottom-left-radius: 8rpx;
  155. padding: 16rpx 30rpx;
  156. color: #888888;
  157. font-size: 24rpx;
  158. }
  159. }
  160. </style>