coupon.vue 4.4 KB

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