coupon.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="coupon-list">
  3. <uv-empty mode="coupon" textSize="28" iconSize="180" v-if="coupon.length === 0"></uv-empty>
  4. <view v-else>
  5. <view :class="returnCouponClass(item) ?'coupon-card' : 'coupon-card disabled'"
  6. v-for="(item,index) in coupon" :key="index" @tap="checkCoupon(item)">
  7. <view
  8. :class="couponChecked.findIndex(node=>node.id === item.id) > -1 ? 'coupon-card-box active' :'coupon-card-box'">
  9. <view class="price">
  10. <view v-if="item.type === 1">
  11. <text class="symbol">¥</text>
  12. <text>{{item.couponAmount}}</text>
  13. </view>
  14. <view v-else>
  15. <text>{{item.discount*100}}</text>
  16. <text class="symbol">折</text>
  17. </view>
  18. </view>
  19. <view class="center-describe">
  20. <uv-text :text="item.title" :lines="1" size="30"></uv-text>
  21. <uv-text
  22. :text="item.type === 1?`满${item.threshold}减${item.couponAmount}`:`满${item.threshold}可用,最高抵扣${item.mostConstraint}`"
  23. type="content" :lines="1" size="26">
  24. </uv-text>
  25. </view>
  26. <view class="icon-check">
  27. <uv-icon name="checkmark" color="#fff" size="28"></uv-icon>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="hui-button-box">
  32. <uv-button type="primary" :text="`使用优惠券${couponChecked.length}张`" @tap="changeCoupon"></uv-button>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. getCouponListByQuery
  40. } from '@/request/api/workark.js'
  41. export default {
  42. data() {
  43. return {
  44. productLevelId: '',
  45. coupon: [],
  46. couponChecked: [],
  47. isStacking: false,
  48. price: 0
  49. }
  50. },
  51. onLoad(body) {
  52. this.productLevelId = body.productLevelId;
  53. this.price = body.price || 0;
  54. if (this.productLevelId) this.init()
  55. },
  56. methods: {
  57. async init() {
  58. let couponData = await getCouponListByQuery({
  59. userId: this.$store.getters.user.userId,
  60. productLevelId: this.productLevelId,
  61. state: 1
  62. })
  63. if (!couponData.state) return;
  64. this.coupon = couponData.data;
  65. },
  66. returnCouponClass(item) {
  67. if (item.threshold > this.price) return false; //大于满减。
  68. if (this.couponChecked.findIndex(node => node.id === item.id) > -1) return true; //已选择的返回true
  69. if (this.couponChecked.length === 0) return true; //未选择优惠券时都能选择。
  70. if (this.isStacking && item.overlayUse === 0) return false; //叠加时不能选择不能叠加优惠券。
  71. if (this.isStacking && item.overlayUse === 1) return true; //叠加时能选择叠加优惠券。
  72. },
  73. checkCoupon(item) {
  74. if (!this.returnCouponClass(item)) return;
  75. let index = this.couponChecked.findIndex(node => node.id === item.id);
  76. if (index === -1) {
  77. this.couponChecked.push(item);
  78. } else {
  79. this.couponChecked.splice(index, 1);
  80. }
  81. this.isStacking = this.couponChecked.length > 0 ? this.couponChecked[0].overlayUse === 1 : false; //是否可叠加
  82. },
  83. changeCoupon() {
  84. uni.$emit('changeCoupon', this.couponChecked);
  85. uni.navigateBack();
  86. }
  87. },
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .coupon-list {
  92. padding: 30rpx;
  93. }
  94. .coupon-card {
  95. margin-bottom: 20rpx;
  96. &.disabled {
  97. .coupon-card-box {
  98. opacity: 0.6;
  99. cursor: unset;
  100. &.active {
  101. border-color: $uv-border-color;
  102. }
  103. }
  104. }
  105. .coupon-card-box {
  106. background: #fff;
  107. padding: 30rpx 0;
  108. align-items: center;
  109. display: flex;
  110. position: relative;
  111. border: 2rpx solid $uv-border-color;
  112. overflow: hidden;
  113. &.active {
  114. border-color: $uv-primary;
  115. .icon-check {
  116. background: $uv-primary;
  117. border-color: $uv-primary;
  118. }
  119. }
  120. }
  121. .price {
  122. color: $uv-error;
  123. font-size: 48rpx;
  124. font-weight: 500;
  125. line-height: 48rpx;
  126. text-align: center;
  127. width: 200rpx;
  128. .symbol {
  129. margin: 0 6rpx;
  130. font-size: 26rpx;
  131. }
  132. }
  133. .center-describe {
  134. display: inline-block;
  135. margin-right: auto;
  136. text-align: left;
  137. }
  138. .icon-check {
  139. border: 1px solid $uv-border-color;
  140. width: 40rpx;
  141. height: 40rpx;
  142. border-radius: 50%;
  143. display: flex;
  144. justify-content: center;
  145. align-items: center;
  146. margin-right: 30rpx;
  147. }
  148. }
  149. </style>