shopro-coupon.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view class="">
  3. <!-- 未领取,已领取 -->
  4. <view class="coupon-wrap" :style="gradientColor" :class="{ 'gray-wrap': state === 3 || state === 2 || couponData.status_code == 'cannot_get' }">
  5. <view class="coupon-item u-flex u-row-between">
  6. <view class="coupon-left u-flex-col ">
  7. <view class="sum-box">
  8. <text class="unit " :style="{ color: priceColor }">¥</text>
  9. <text class="sum " :style="{ color: priceColor }">{{ couponData.amount }}</text>
  10. <text class="sub " :style="{ color: priceColor }">{{ couponData.name }}</text>
  11. </view>
  12. <view class="notice " :style="{ color: color }">满{{ couponData.enough }}元可用</view>
  13. <view class="notice" :style="{ color: color }">
  14. 有效期:{{ $u.timeFormat(couponData.usetime.start, 'yyyy-mm-dd') }} 至 {{ $u.timeFormat(couponData.usetime.end, 'yyyy-mm-dd') }}
  15. </view>
  16. </view>
  17. <view class="coupon-right u-flex-col">
  18. <button class="get-btn" :style="{ color: btnTextColor }" v-if="state === 0" @tap.stop="getCoupon">{{ stateMap[couponData.status_code] || '立即领取' }}</button>
  19. <button class="get-btn" :style="{ color: btnTextColor }" v-if="state === 1">去使用</button>
  20. <button class="get-btn" :style="{ color: btnTextColor }" v-if="state === 2">暂不可用</button>
  21. <button class="get-btn" v-if="state === 3">{{ stateMap[couponData.status_code] }}</button>
  22. <view class="surplus-num" :style="{ color: color }" v-if="state === 0">仅剩{{ stock }}张</view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. /**
  30. * shoproCoupon-优惠券
  31. * @property {Number} state - 0:立即领取,1:去使用,2:查看详情,3:已失效。
  32. * @property {Object} couponData - 优惠劵数据。
  33. * @property {String} gradientColor - 渐变色。
  34. */
  35. export default {
  36. components: {},
  37. data() {
  38. return {
  39. stock: 0,
  40. stateMap: {
  41. can_use: '立即使用',
  42. used: '已使用',
  43. expired: '已失效',
  44. cannot_use: '暂不可用',
  45. can_get: '立即领取',
  46. cannot_get: '已领取'
  47. }
  48. };
  49. },
  50. props: {
  51. state: 0, //0:立即领取,1:去使用,2:查看详情,3:已失效。
  52. couponData: {},
  53. gradientColor: {
  54. type: String,
  55. default: ''
  56. },
  57. color: {
  58. type: String,
  59. default: ''
  60. },
  61. btnTextColor: {
  62. type: String,
  63. default: ''
  64. },
  65. priceColor: {
  66. type: String,
  67. default: ''
  68. }
  69. },
  70. computed: {},
  71. created() {
  72. this.$nextTick(() => {
  73. this.stock = this.couponData.stock;
  74. });
  75. },
  76. methods: {
  77. getCoupon() {
  78. let that = this;
  79. that.$http(
  80. 'coupons.get',
  81. {
  82. id: that.couponData.id
  83. },
  84. '领取中...'
  85. ).then(res => {
  86. if (res.code === 1) {
  87. that.stock -= 1;
  88. that.$u.toast('领取成功');
  89. }
  90. });
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss" scoped>
  96. // 失效
  97. .gray-wrap {
  98. -webkit-filter: grayscale(1); /* Webkit */
  99. filter: gray; /* IE6-9 */
  100. filter: grayscale(1); /* W3C */
  101. }
  102. // 未领取,已领取
  103. .coupon-wrap {
  104. mask: url($IMG_URL+'/imgs/coupon_bg1.png');
  105. -webkit-mask-box-image: url($IMG_URL+'/imgs/coupon_bg1.png');
  106. mask-size: 100% 100%;
  107. position: relative;
  108. border-radius: 10rpx;
  109. width: 710rpx;
  110. height: 170rpx;
  111. background: linear-gradient(to right, $u-type-warning-disabled, $u-type-warning);
  112. .coupon-item {
  113. width: 100%;
  114. height: 168rpx;
  115. border-radius: 10rpx;
  116. .coupon-left {
  117. height: 100%;
  118. justify-content: center;
  119. padding-left: 40rpx;
  120. .unit {
  121. font-size: 24rpx;
  122. color: #fff;
  123. }
  124. .sum {
  125. font-size: 55rpx;
  126. font-weight: bold;
  127. color: #fff;
  128. line-height: 55rpx;
  129. padding-right: 10rpx;
  130. }
  131. .sub {
  132. font-size: 26rpx;
  133. color: #fff;
  134. }
  135. .notice {
  136. font-size: 22rpx;
  137. color: rgba(#fff, 0.7);
  138. margin-top: 6rpx;
  139. }
  140. }
  141. .coupon-right {
  142. height: 100%;
  143. width: 220rpx;
  144. justify-content: center;
  145. align-items: center;
  146. .get-btn {
  147. width: 142rpx;
  148. height: 54rpx;
  149. background: #ffffff;
  150. border-radius: 27rpx;
  151. padding: 0;
  152. font-size: 24rpx;
  153. font-weight: 500;
  154. color: $u-type-warning;
  155. }
  156. .surplus-num {
  157. font-size: 22rpx;
  158. font-weight: 500;
  159. color: #fff;
  160. margin-top: 14rpx;
  161. }
  162. }
  163. }
  164. }
  165. </style>