cm-coupon.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="coupon on">
  3. <view class="content" :class="[statusIcon, { 'cover-bg': showStatus }]">
  4. <view class="header">
  5. <view class="tag">优惠券标签</view> <view class="price"><text>¥</text>100</view>
  6. <view class="tip">满600可用</view>
  7. </view>
  8. <view class="center desc">
  9. <view class="row bold">618全场满600减100</view> <view class="row">全商城商品通用</view>
  10. <view class="end-time">截止日期:2021-10-28</view>
  11. </view>
  12. <view class="footer">
  13. <!-- <view class="btn" @click="handleBtnClick">领取</view> -->
  14. <view class="btn plain" @click="handleBtnClick">去使用</view>
  15. </view>
  16. <!-- <text class="radio-flag iconfont icon-weixuanze"></text> -->
  17. <text class="radio-flag iconfont icon-xuanze" v-if="chooseAble" @click="choose"></text>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. props: {
  24. // 优惠券数据
  25. couponData: {
  26. type: Object,
  27. default: () => {}
  28. },
  29. // 设置优惠券是否可选
  30. chooseAble: {
  31. type: Boolean,
  32. default: false
  33. },
  34. // 是否显示优惠券状态
  35. showStatus: {
  36. type: Boolean,
  37. default: false
  38. }
  39. },
  40. filters: {
  41. // 优惠券标签格式化
  42. formatTag(val) {
  43. const tags = {
  44. 1: '活动券',
  45. 2: '用户专享券',
  46. 3: '新用户券',
  47. 4: '好友分享券',
  48. 5: '好友消费券'
  49. }
  50. return tags[val] || '未知券'
  51. }
  52. },
  53. computed: {
  54. // 优惠券状态图标
  55. statusIcon() {
  56. if (!this.couponData) return
  57. let name = ''
  58. switch (this.couponData.flag) {
  59. case 1:
  60. name = 'received'
  61. break
  62. case 2:
  63. name = 'expired'
  64. break
  65. case 3:
  66. name = 'used'
  67. break
  68. default:
  69. name = ''
  70. break
  71. }
  72. return name
  73. }
  74. },
  75. methods: {
  76. // 点击勾选按钮
  77. choose() {
  78. this.$emit('choose', this.couponData)
  79. },
  80. // 按钮点击
  81. handleBtnClick() {
  82. console.log('领取 or 使用')
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. $grid: 24rpx;
  89. $color: #ff457b;
  90. $coupon-width: 702rpx;
  91. $coupon-height: 200rpx;
  92. $coupon-bg-on: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon-bg-on.png);
  93. $coupon-bg-off: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon-bg-off.png);
  94. $coupon-bg-received: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon-received.png); // 已领取
  95. $coupon-bg-expired: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon-expired.png); // 已失效
  96. $coupon-bg-used: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon-used.png); // 已使用
  97. .coupon {
  98. width: $coupon-width;
  99. height: $coupon-height;
  100. padding: 6rpx;
  101. margin: $grid;
  102. box-sizing: border-box;
  103. background: #ffffff no-repeat center;
  104. background-size: $coupon-width $coupon-height;
  105. .content {
  106. position: relative;
  107. display: flex;
  108. justify-content: space-between;
  109. align-items: center;
  110. }
  111. .cover-bg {
  112. background-position: 580rpx 16rpx;
  113. background-size: 100rpx 100rpx;
  114. background-repeat: no-repeat;
  115. &.received {
  116. background-image: $coupon-bg-received;
  117. }
  118. &.expired {
  119. background-image: $coupon-bg-expired;
  120. }
  121. &.used {
  122. background-image: $coupon-bg-used;
  123. }
  124. }
  125. &.on {
  126. background-image: $coupon-bg-on;
  127. }
  128. &.off {
  129. filter: grayscale(1);
  130. opacity: 0.7;
  131. background-image: $coupon-bg-off;
  132. }
  133. .header,
  134. .center,
  135. .footer {
  136. display: flex;
  137. flex-direction: column;
  138. justify-content: center;
  139. }
  140. .header {
  141. align-items: center;
  142. position: relative;
  143. width: 206rpx;
  144. height: 188rpx;
  145. .tag {
  146. position: absolute;
  147. top: 0;
  148. left: 0;
  149. height: 32rpx;
  150. padding: 0 6rpx;
  151. background: linear-gradient(90deg, #fc32b4 0%, #f83c6c 100%);
  152. border-radius: 10rpx 0px 10rpx 0px;
  153. font-size: 22rpx;
  154. color: #ffffff;
  155. text-align: center;
  156. line-height: 32rpx;
  157. }
  158. .price {
  159. font-size: 56rpx;
  160. font-weight: 600;
  161. color: $color;
  162. text {
  163. font-size: 24rpx;
  164. }
  165. }
  166. .tip {
  167. margin-top: 6rpx;
  168. font-size: 24rpx;
  169. color: #404040;
  170. }
  171. }
  172. .center {
  173. margin-left: 36rpx;
  174. .row {
  175. width: 250rpx;
  176. white-space: nowrap;
  177. overflow: hidden;
  178. text-overflow: ellipsis;
  179. font-size: 26rpx;
  180. color: #333333;
  181. margin-bottom: 16rpx;
  182. &.bold {
  183. font-weight: 600;
  184. }
  185. }
  186. .end-time {
  187. font-size: 20rpx;
  188. color: #999999;
  189. }
  190. }
  191. .footer {
  192. align-items: center;
  193. width: 128rpx;
  194. margin-right: $grid;
  195. .btn {
  196. width: 128rpx;
  197. height: 48rpx;
  198. background: linear-gradient(270deg, #f83c6c 0%, #fc32b4 100%);
  199. border-radius: 28rpx;
  200. box-sizing: border-box;
  201. border: 1rpx solid transparent;
  202. text-align: center;
  203. line-height: 46rpx;
  204. font-size: 26rpx;
  205. color: #ffffff;
  206. &.plain {
  207. border: 1rpx solid $color;
  208. background: transparent;
  209. color: $color;
  210. }
  211. }
  212. }
  213. .radio-flag {
  214. position: absolute;
  215. top: $grid;
  216. right: $grid;
  217. color: $color;
  218. font-size: 32rpx;
  219. }
  220. }
  221. </style>