index.vue 5.8 KB

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