cm-coupon.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="coupon off">
  3. <view class="content cover-bg" :class="[cover]">
  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" :class="{ plain: i === 2 }">{{ i === 2 ? '去使用' : '领取' }}</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. showReceived: {
  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. cover() {
  55. if(!this.couponData) return
  56. let name = ''
  57. switch (this.couponData.flag) {
  58. case 1:
  59. name = 'received'
  60. break
  61. case 2:
  62. name = 'expired'
  63. break
  64. case 3:
  65. name = 'used'
  66. break
  67. default:
  68. name = ''
  69. break
  70. }
  71. return name
  72. }
  73. },
  74. methods: {
  75. // 点击勾选按钮
  76. choose() {
  77. this.$emit('choose', this.couponData)
  78. },
  79. // 领取优惠券 TODO
  80. receive() {
  81. console.log('领取优惠券')
  82. },
  83. // 按钮点击
  84. handleBtnClick(){
  85. console.log('领取 or 使用')
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. $grid: 24rpx;
  92. $color: #ff457b;
  93. $coupon-width: 702rpx;
  94. $coupon-height: 200rpx;
  95. $coupon-bg-on: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon-bg-on.png);
  96. $coupon-bg-off: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon-bg-off.png);
  97. $coupon-bg-received: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon-received.png); // 已领取
  98. $coupon-bg-expired: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon-expired.png); // 已失效
  99. $coupon-bg-used: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon-used.png); // 已使用
  100. .coupon {
  101. width: $coupon-width;
  102. height: $coupon-height;
  103. padding: 6rpx;
  104. margin: $grid;
  105. box-sizing: border-box;
  106. background: #ffffff no-repeat center;
  107. background-size: $coupon-width $coupon-height;
  108. .content {
  109. position: relative;
  110. display: flex;
  111. justify-content: space-between;
  112. align-items: center;
  113. }
  114. .cover-bg {
  115. background-position: 580rpx 16rpx;
  116. background-size: 90rpx 90rpx;
  117. background-repeat: no-repeat;
  118. &.received {
  119. background-image: $coupon-bg-received;
  120. }
  121. &.expired {
  122. background-image: $coupon-bg-expired;
  123. }
  124. &.used {
  125. background-image: $coupon-bg-used;
  126. }
  127. }
  128. &.on {
  129. background-image: $coupon-bg-on;
  130. }
  131. &.off {
  132. filter: grayscale(1);
  133. opacity: 0.7;
  134. background-image: $coupon-bg-off;
  135. }
  136. .header,
  137. .center,
  138. .footer {
  139. display: flex;
  140. flex-direction: column;
  141. justify-content: center;
  142. }
  143. .header {
  144. align-items: center;
  145. position: relative;
  146. width: 206rpx;
  147. height: 188rpx;
  148. .tag {
  149. position: absolute;
  150. top: 0;
  151. left: 0;
  152. height: 32rpx;
  153. padding: 0 6rpx;
  154. background: linear-gradient(90deg, #fc32b4 0%, #f83c6c 100%);
  155. border-radius: 10rpx 0px 10rpx 0px;
  156. font-size: 22rpx;
  157. color: #ffffff;
  158. text-align: center;
  159. line-height: 32rpx;
  160. }
  161. .price {
  162. font-size: 56rpx;
  163. font-weight: 600;
  164. color: $color;
  165. text {
  166. font-size: 24rpx;
  167. }
  168. }
  169. .tip {
  170. margin-top: 6rpx;
  171. font-size: 24rpx;
  172. color: #404040;
  173. }
  174. }
  175. .center {
  176. margin-left: 36rpx;
  177. .row {
  178. width: 250rpx;
  179. white-space: nowrap;
  180. overflow: hidden;
  181. text-overflow: ellipsis;
  182. font-size: 26rpx;
  183. color: #333333;
  184. margin-bottom: 16rpx;
  185. &.bold {
  186. font-weight: 600;
  187. }
  188. }
  189. .end-time {
  190. font-size: 20rpx;
  191. color: #999999;
  192. }
  193. }
  194. .footer {
  195. align-items: center;
  196. width: 128rpx;
  197. margin-right: $grid;
  198. .btn {
  199. width: 128rpx;
  200. height: 48rpx;
  201. background: linear-gradient(270deg, #f83c6c 0%, #fc32b4 100%);
  202. border-radius: 28rpx;
  203. box-sizing: border-box;
  204. border: 1rpx solid transparent;
  205. text-align: center;
  206. line-height: 46rpx;
  207. font-size: 26rpx;
  208. color: #ffffff;
  209. &.plain {
  210. border: 1rpx solid $color;
  211. background: transparent;
  212. color: $color;
  213. }
  214. }
  215. }
  216. .radio-flag {
  217. position: absolute;
  218. top: $grid;
  219. right: $grid;
  220. color: $color;
  221. font-size: 32rpx;
  222. }
  223. }
  224. </style>