coupon.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="app-container">
  3. <view class="list-container">
  4. <block v-for="(item, index) in couponList" :key='index'>
  5. <view class="item">
  6. <view class="bg">
  7. <image src="@/static/mine/coupon/bg_1.png"></image>
  8. </view>
  9. <view class="content">
  10. <view class="left">
  11. <view class="price">{{item.couponValue}}<text>元</text></view>
  12. <view class="text" v-if="item.couponType == 'SATISFY'">满{{item.orderAmount}}可用</view>
  13. </view>
  14. <view class="right">
  15. <view class="main">
  16. <view class="row1 ellipsis-2">{{item.couponName}}</view>
  17. <view class="row2">
  18. <!-- <view class="date">
  19. <view>领取时间:</view>
  20. <view>
  21. {{item.obtainStartTime | dateToYYmmdd2}}-{{item.obtainEndTime | dateToYYmmdd2}}
  22. </view>
  23. </view> -->
  24. <view class="date">
  25. <view>使用时间:</view>
  26. <view>
  27. {{item.activeStartTime | dateToYYmmdd2}}-{{item.activeEndTime | dateToYYmmdd2}}
  28. </view>
  29. </view>
  30. <view class="button red" @tap="handleCoupon(item)">立即领取</view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </block>
  37. </view>
  38. <view v-if="couponList.length" style="position: fixed;bottom: 0;left: 0;right: 0;box-sizing: border-box;padding: 30rpx;background: #ffffff;">
  39. <button type="primary" @tap="handleCouponAll">
  40. 一键领取
  41. </button>
  42. </view>
  43. <no-data v-if="!couponList.length" :showText="'暂无可领取优惠券'"></no-data>
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. mapState
  49. } from 'vuex';
  50. export default {
  51. data() {
  52. return {
  53. couponList: [],
  54. }
  55. },
  56. computed: {
  57. ...mapState(['userInfo', 'isLogin', 'userId'])
  58. },
  59. onLoad() {
  60. this.getCouponList();
  61. },
  62. methods: {
  63. getCouponList() {
  64. this.$axios({
  65. url: '/couponNew/list/all',
  66. method: 'get',
  67. params: {
  68. userId: this.userId
  69. },
  70. isLoading: 1
  71. }).then(res => {
  72. this.couponList = res.data;
  73. })
  74. },
  75. // 处理优惠券
  76. handleCoupon(item) {
  77. this.$axios({
  78. url: '/couponNew/obtain',
  79. method: 'get',
  80. params: {
  81. userId: this.userId,
  82. couponIds: item.couponId
  83. }
  84. }).then(res => {
  85. this.$successToast('领取成功');
  86. this.getCouponList();
  87. })
  88. },
  89. handleCouponAll() {
  90. this.$axios({
  91. url: '/couponNew/obtain',
  92. method: 'get',
  93. params: {
  94. userId: this.userId,
  95. couponIds: this.couponList.map(item => item.couponId).join(",")
  96. }
  97. }).then(res => {
  98. this.$successToast('领取成功');
  99. this.getCouponList();
  100. })
  101. },
  102. }
  103. }
  104. </script>
  105. <style lang="scss">
  106. .app-container {
  107. background: #F4F2F2;
  108. padding: 20rpx;
  109. box-sizing: border-box;
  110. }
  111. .list-container {
  112. box-sizing: border-box;
  113. padding-bottom: 160rpx;
  114. .item {
  115. position: relative;
  116. margin-bottom: 20rpx;
  117. .bg {
  118. image {
  119. width: 710rpx;
  120. height: 160rpx;
  121. display: block;
  122. }
  123. }
  124. .content {
  125. position: absolute;
  126. left: 0;
  127. top: 0;
  128. width: 710rpx;
  129. height: 160rpx;
  130. display: flex;
  131. align-items: center;
  132. .left {
  133. width: 240rpx;
  134. display: flex;
  135. align-items: center;
  136. justify-content: center;
  137. flex-direction: column;
  138. .price {
  139. font-size: 60rpx;
  140. color: #FFFFFF;
  141. text {
  142. font-size: 28rpx;
  143. margin-top: 20rpx;
  144. }
  145. }
  146. .text {
  147. color: #FFFFFF;
  148. font-size: 28rpx;
  149. }
  150. }
  151. .right {
  152. display: flex;
  153. align-items: center;
  154. justify-content: space-between;
  155. padding: 0 20rpx;
  156. width: 470rpx;
  157. height: 160rpx;
  158. box-sizing: border-box;
  159. .main {
  160. width: 430rpx;
  161. height: 160rpx;
  162. padding: 16rpx 0;
  163. box-sizing: border-box;
  164. display: flex;
  165. flex-direction: column;
  166. justify-content: space-between;
  167. .row1 {
  168. font-size: 28rpx;
  169. line-height: 32rpx;
  170. }
  171. .row2 {
  172. display: flex;
  173. justify-content: space-between;
  174. align-items: center;
  175. .date {
  176. font-size: 24rpx;
  177. color: #999999;
  178. line-height: 28rpx;
  179. }
  180. .button {
  181. width: 120rpx;
  182. height: 40rpx;
  183. border-radius: 40rpx;
  184. font-size: 24rpx;
  185. flex-shrink: 0;
  186. box-sizing: border-box;
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. &.gary {
  191. background: #AAAAAA;
  192. color: #FFFFFF;
  193. border: 1px solid #AAAAAA;
  194. }
  195. &.red {
  196. background: #C434FF;
  197. color: #FFFFFF;
  198. border: 1px solid #C434FF;
  199. }
  200. &.white {
  201. color: #FF3F42;
  202. border: 1px solid #FF3F42;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. </style>