index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <view class="container">
  3. <view v-if="list.length" class="coupon-list">
  4. <view class="coupon-item" v-for="(item, index) in list" :key="index">
  5. <view class="item-wrapper" :class="['color-' + color[index % color.length]]">
  6. <view class="coupon-type">{{ CouponTypeEnum[item.coupon_type].name }}</view>
  7. <view class="tip dis-flex flex-dir-column flex-x-center">
  8. <view v-if="item.coupon_type == CouponTypeEnum.FULL_DISCOUNT.value">
  9. <text class="f-30">¥</text>
  10. <text class="money">{{ item.reduce_price }}</text>
  11. </view>
  12. <text class="money" v-if="item.coupon_type == CouponTypeEnum.DISCOUNT.value">{{ item.discount }}折</text>
  13. <text class="pay-line">满{{ item.min_price }}元可用</text>
  14. </view>
  15. <view class="split-line"></view>
  16. <view class="content dis-flex flex-dir-column flex-x-between">
  17. <view class="title">{{ item.name }}</view>
  18. <view class="bottom dis-flex flex-y-center">
  19. <view class="time flex-box">
  20. <text v-if="item.expire_type == 10">领取{{ item.expire_day }}天内有效</text>
  21. <text v-if="item.expire_type == 20">{{ item.start_time }}~{{ item.end_time }}</text>
  22. </view>
  23. <view class="receive" v-if="item.state.value" @click="receive(item.coupon_id)">
  24. <text>立即领取</text>
  25. </view>
  26. <view v-else class="receive state">
  27. <text>{{ item.state.text }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. <empty v-if="!list.length" :isLoading="isLoading" />
  35. </view>
  36. </template>
  37. <script>
  38. import * as CouponApi from '@/api/coupon'
  39. import * as MyCouponApi from '@/api/myCoupon'
  40. import { CouponTypeEnum } from '@/common/enum/coupon'
  41. import Empty from '@/components/empty'
  42. const color = ['red', 'blue', 'violet', 'yellow']
  43. export default {
  44. components: {
  45. Empty
  46. },
  47. data() {
  48. return {
  49. // 枚举类
  50. CouponTypeEnum,
  51. // 颜色组
  52. color,
  53. // 优惠券列表
  54. list: [],
  55. // 正在加载中
  56. isLoading: true
  57. }
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad(options) {
  63. // 获取优惠券列表
  64. this.getCouponList()
  65. },
  66. methods: {
  67. /**
  68. * 获取优惠券列表
  69. * @param {bool} load 是否显示loading弹窗
  70. */
  71. getCouponList(load = true) {
  72. const app = this
  73. app.isLoading = true
  74. CouponApi.list({}, { load })
  75. .then(result => {
  76. app.list = result.data.list
  77. })
  78. .finally(() => app.isLoading = false)
  79. },
  80. // 立即领取
  81. receive(couponId) {
  82. const app = this
  83. MyCouponApi.receive(couponId)
  84. .then(result => {
  85. // 显示领取成功提示
  86. app.$success(result.message)
  87. // 刷新优惠券列表
  88. app.getCouponList(false)
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .coupon-list {
  96. padding: 20rpx;
  97. }
  98. .coupon-item {
  99. position: relative;
  100. overflow: hidden;
  101. margin-bottom: 22rpx;
  102. }
  103. .item-wrapper {
  104. width: 100%;
  105. display: flex;
  106. background: #fff;
  107. border-radius: 8rpx;
  108. color: #fff;
  109. height: 180rpx;
  110. .coupon-type {
  111. position: absolute;
  112. top: 0;
  113. right: 0;
  114. z-index: 10;
  115. width: 128rpx;
  116. padding: 3px 0;
  117. background: #a771ff;
  118. font-size: 20rpx;
  119. text-align: center;
  120. color: #ffffff;
  121. transform: rotate(45deg);
  122. transform-origin: 64rpx 64rpx;
  123. }
  124. &.color-blue {
  125. background: linear-gradient(-125deg, #57bdbf, #2f9de2);
  126. }
  127. &.color-red {
  128. background: linear-gradient(-128deg, #ff6d6d, #ff3636);
  129. }
  130. &.color-violet {
  131. background: linear-gradient(-113deg, #ef86ff, #b66ff5);
  132. .coupon-type {
  133. background: #55b5ff;
  134. }
  135. }
  136. &.color-yellow {
  137. background: linear-gradient(-141deg, #f7d059, #fdb054);
  138. }
  139. &.color-gray {
  140. background: linear-gradient(-113deg, #bdbdbd, #a2a1a2);
  141. .coupon-type {
  142. background: #9e9e9e;
  143. }
  144. }
  145. .content {
  146. flex: 1;
  147. padding: 30rpx 20rpx;
  148. border-radius: 8px 0 0 8px;
  149. .title {
  150. font-size: 32rpx;
  151. }
  152. .bottom {
  153. .time {
  154. font-size: 24rpx;
  155. }
  156. .receive {
  157. height: 46rpx;
  158. width: 122rpx;
  159. line-height: 46rpx;
  160. text-align: center;
  161. border: 1px solid #fff;
  162. border-radius: 30rpx;
  163. color: #fff;
  164. font-size: 24rpx;
  165. &.state {
  166. border: none;
  167. }
  168. }
  169. }
  170. }
  171. .tip {
  172. position: relative;
  173. flex: 0 0 32%;
  174. text-align: center;
  175. border-radius: 0 8px 8px 0;
  176. .money {
  177. font-weight: bold;
  178. font-size: 52rpx;
  179. }
  180. .pay-line {
  181. font-size: 22rpx;
  182. }
  183. }
  184. .split-line {
  185. position: relative;
  186. flex: 0 0 0;
  187. border-left: 4rpx solid #fff;
  188. margin: 0 5px 0 3px;
  189. background: #fff;
  190. &:before,
  191. {
  192. border-radius: 0 0 16rpx 16rpx;
  193. top: 0;
  194. }
  195. &:after {
  196. border-radius: 16rpx 16rpx 0 0;
  197. bottom: 0;
  198. }
  199. &:before,
  200. &:after {
  201. content: '';
  202. position: absolute;
  203. width: 24rpx;
  204. height: 12rpx;
  205. background: #f7f7f7;
  206. left: -14rpx;
  207. z-index: 1;
  208. }
  209. }
  210. }
  211. </style>