coupon.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="content">
  3. <scroll-view class="coupon-box clamp" :style="{ height: height }">
  4. <view v-for="(item, index) in couponArray" :key="item.id" class="coupon-list">
  5. <view class="row flex">
  6. <view class="list-money flex">
  7. <image :src="item.is_use ? '/static/img/img02.png' : '/static/img/img03.png'" mode="scaleToFill"></image>
  8. <view class="list-money-text">
  9. <view class="tit" :class="{ noAction: item.is_use }">
  10. <text>{{ item.coupon_price }}</text>
  11. </view>
  12. </view>
  13. </view>
  14. <view class="list-interval position-relative">
  15. <view class="bottom"></view>
  16. <view class="top"></view>
  17. </view>
  18. <view class="row_list_right">
  19. <view class="right_top"><text class="right_title" :class="{ noAction: item.is_use }">满减券</text></view>
  20. <view class="right_time">
  21. <text>满{{ item.use_min_price }}使用</text>
  22. </view>
  23. </view>
  24. <view class="right_use noAction" v-if="item.is_use" @click="setCoupons(item)">
  25. <text>{{ item.is_use ? '已领取' : '立即领取' }}</text>
  26. </view>
  27. <view class="right_use action" v-else @click="setCoupons(item)">
  28. <text>{{ item.is_use ? '已领取' : '立即领取' }}</text>
  29. </view>
  30. </view>
  31. </view>
  32. </scroll-view>
  33. </view>
  34. </template>
  35. <script>
  36. import { getCouponsList } from '@/api/index.js';
  37. import { setCoupons, getwCouponsList } from '@/api/functionalUnit.js';
  38. export default {
  39. data() {
  40. return {
  41. height: '',
  42. couponArray: [] //可领取优惠券
  43. };
  44. },
  45. onLoad() {
  46. this.loadData();
  47. },
  48. onShow() {},
  49. onReachBottom() {},
  50. onReady() {
  51. var _this = this;
  52. uni.getSystemInfo({
  53. success: resu => {
  54. const query = uni.createSelectorQuery();
  55. query.select('.coupon-box').boundingClientRect();
  56. query.exec(function(res) {
  57. console.log(res, 'ddddddddddddd');
  58. _this.height = resu.windowHeight - res[0].top + 'px';
  59. console.log('打印页面的剩余高度', _this.height);
  60. });
  61. },
  62. fail: res => {}
  63. });
  64. },
  65. methods: {
  66. loadData() {
  67. getwCouponsList({}).then(({ data }) => {
  68. this.couponArray = data;
  69. });
  70. },
  71. setCoupons(item) {
  72. // 判断是否已经领取了优惠券
  73. let obj = this;
  74. uni.showModal({
  75. title: '领取提示',
  76. content: '是否领取优惠券',
  77. success(e) {
  78. if (e.confirm) {
  79. setCoupons({ couponId: item.id }).then(e => {
  80. item.is_use = true;
  81. uni.showToast({
  82. title: '领取成功',
  83. type: 'top',
  84. duration: 2000
  85. });
  86. });
  87. }
  88. }
  89. });
  90. }
  91. }
  92. };
  93. </script>
  94. <style lang="scss">
  95. page,
  96. .content {
  97. min-height: 100%;
  98. height: auto;
  99. }
  100. $card-color-action: #fc4141;
  101. .row {
  102. padding-right: 10rpx;
  103. border-radius: 15rpx;
  104. margin: 0 25rpx;
  105. margin-bottom: 25rpx;
  106. height: 200rpx;
  107. overflow: hidden;
  108. background-color: #ffffff;
  109. .list-interval {
  110. border: 1px dashed $border-color-light;
  111. height: 100%;
  112. .top,
  113. .bottom {
  114. border-radius: 100rpx;
  115. width: 30rpx;
  116. height: 30rpx;
  117. position: absolute;
  118. background-color: $page-color-base;
  119. right: -15rpx;
  120. }
  121. .top {
  122. top: -18rpx;
  123. }
  124. .bottom {
  125. bottom: -18rpx;
  126. }
  127. }
  128. .list-money {
  129. height: 100%;
  130. image {
  131. height: 100%;
  132. width: 20rpx;
  133. }
  134. .list-money-text {
  135. width: 220rpx;
  136. padding: 0 25rpx;
  137. text-align: center;
  138. color: $font-color-light;
  139. .tit {
  140. padding: 15rpx 0rpx;
  141. font-size: 55rpx;
  142. font-weight: bold;
  143. &.action {
  144. color: $card-color-action;
  145. }
  146. }
  147. .price {
  148. padding-bottom: 25rpx;
  149. }
  150. }
  151. }
  152. .row_list_right {
  153. flex-grow: 1;
  154. padding-left: 25rpx;
  155. line-height: 1;
  156. .right_time {
  157. color: $font-color-light;
  158. font-size: $font-sm;
  159. }
  160. .right_top {
  161. margin: 15rpx 0;
  162. font-size: $font-lg;
  163. height: 50rpx;
  164. color: $font-color-light;
  165. .right_name {
  166. font-weight: bold;
  167. }
  168. .right_title {
  169. font-weight: bold;
  170. &.action {
  171. color: $font-color-base;
  172. }
  173. }
  174. }
  175. }
  176. .right_use {
  177. margin: 15rpx 0;
  178. padding: 10rpx;
  179. width: 140rpx;
  180. display: flex;
  181. justify-content: center;
  182. align-items: center;
  183. border-radius: 50rpx;
  184. color: #fff;
  185. font-size: $font-sm - 4rpx;
  186. &.action {
  187. background-color: $card-color-action;
  188. }
  189. &.noAction {
  190. background-color: $color-gray;
  191. }
  192. }
  193. .iconlocation {
  194. font-size: 36rpx;
  195. color: $font-color-light;
  196. }
  197. }
  198. </style>