sh-coupon.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <!-- 首页优惠券卡片 -->
  3. <view class="coupon-box u-m-b-10 u-p-20" v-if="detail.ids && couponList.length">
  4. <view class="head-box u-flex u-row-between u-m-b-20">
  5. <view class="head-title u-ellipsis-1">领券专区</view>
  6. <view class="head-more u-flex u-col-center" @tap="$Router.push('/pages/app/coupon/list')">
  7. <text class="more-text u-m-r-10">查看更多</text>
  8. <text class="iconfont icon-youjiantou-tianchong more-icon"></text>
  9. </view>
  10. </view>
  11. <scroll-view class="groupon-scroll" enable-flex scroll-anchoring scroll-x scroll-with-animation>
  12. <view class="groupon-card-wrap u-flex ">
  13. <view :class="{ 'gray-wrap': item.status_code === 'cannot_get' }" v-for="(item, index) in couponList" :key="item.id">
  14. <!-- mini -->
  15. <view class="coupon-card u-flex u-row-between u-m-r-16" v-if="couponType === 2" :style="{ background: `linear-gradient(to right, ${bgColor1}, ${bgColor2})` }">
  16. <view class="card-left u-flex-col u-row-center u-p-l-30">
  17. <view class="price u-m-b-10" :style="{ color: priceColor }">{{ item.amount }}</view>
  18. <view class="notice" :style="{ color: color }">满{{ item.enough }}元可用</view>
  19. <view class="notice u-m-b-10" :style="{ color: color }">仅剩{{ item.stock }}张</view>
  20. </view>
  21. <view class="card-right u-p-y-20 u-p-r-10 u-flex-col u-row-center u-col-center">
  22. <button class="u-reset-button get-btn u-m-b-10" :style="{ color: color }" @tap="getCoupon(item.id, index)">
  23. {{ item.status_code === 'cannot_get' ? '不可领取' : '领券购买' }}
  24. </button>
  25. </view>
  26. </view>
  27. <!-- big -->
  28. <view v-if="couponType === 1" class="u-p-r-16">
  29. <view class="coupon-wrap " :style="{ background: `linear-gradient(to right, ${bgColor1}, ${bgColor2})` }">
  30. <view class="coupon-item u-flex u-row-between">
  31. <view class="coupon-left u-flex-col ">
  32. <view class="sum-box">
  33. <text class="unit " :style="{ color: priceColor }">¥</text>
  34. <text class="sum " :style="{ color: priceColor }">{{ item.amount }}</text>
  35. <text class="sub " :style="{ color: priceColor }">{{ item.name }}</text>
  36. </view>
  37. <view class="notice " :style="{ color: color }">满{{ item.enough }}元可用</view>
  38. <view class="notice" :style="{ color: color }">
  39. 有效期:{{ $u.timeFormat(item.usetime.start, 'yyyy-mm-dd') }} 至 {{ $u.timeFormat(item.usetime.end, 'yyyy-mm-dd') }}
  40. </view>
  41. </view>
  42. <view class="coupon-right u-flex-col">
  43. <button class="get-btn" :style="{ color: bgColor1 }" @tap.stop="getCoupon(item.id, index)">
  44. {{ item.status_code === 'cannot_get' ? '不可领取' : '立即领取' }}
  45. </button>
  46. <view class="surplus-num" :style="{ color: color }">仅剩{{ item.stock }}张</view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </scroll-view>
  54. </view>
  55. </template>
  56. <script>
  57. /**
  58. * 自定义之优惠券卡片
  59. * @property {Object} detail - 优惠券信息
  60. */
  61. export default {
  62. components: {},
  63. data() {
  64. return {
  65. currentIndex: 0,
  66. couponList: [],
  67. couponType: this.detail.style,
  68. priceColor: this.detail.pricecolor,
  69. color: this.detail.color,
  70. bgColor1: this.detail.bgcolor1,
  71. bgColor2: this.detail.bgcolor2
  72. };
  73. },
  74. props: {
  75. detail: {}
  76. },
  77. computed: {},
  78. created() {
  79. this.detail.ids && this.getCouponsList();
  80. },
  81. methods: {
  82. jump(path, parmas) {
  83. this.$Router.push({
  84. path: path,
  85. query: parmas
  86. });
  87. },
  88. // 优惠券列表
  89. getCouponsList() {
  90. let that = this;
  91. that.$http('coupons.templateList', {
  92. ids: that.detail.ids
  93. }).then(res => {
  94. if (res.code === 1) {
  95. that.couponList = res.data;
  96. }
  97. });
  98. },
  99. // 领取
  100. getCoupon(id, index) {
  101. let that = this;
  102. uni.showLoading({
  103. title: '领取中'
  104. });
  105. that.$http('coupons.get', {
  106. id: id
  107. }).then(res => {
  108. uni.hideLoading();
  109. if (res.code === 1) {
  110. that.couponList[index].stock -= 1;
  111. this.$u.toast('领取成功');
  112. }
  113. });
  114. }
  115. }
  116. };
  117. </script>
  118. <style lang="scss" scoped>
  119. // 失效
  120. .gray-wrap {
  121. filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1) !important;
  122. -webkit-filter: grayscale(100%) !important;
  123. -moz-filter: grayscale(100%) !important;
  124. -ms-filter: grayscale(100%) !important;
  125. -o-filter: grayscale(100%) !important;
  126. filter: grayscale(100%) !important;
  127. filter: gray !important;
  128. }
  129. .groupon-scroll {
  130. height: 170rpx;
  131. width: 730rpx;
  132. .groupon-card-wrap {
  133. height: 170rpx;
  134. width: 730rpx;
  135. }
  136. }
  137. .coupon-box {
  138. background-color: #fff;
  139. .head-box {
  140. .head-title {
  141. width: 300rpx;
  142. font-size: 32rpx;
  143. font-weight: bold;
  144. color: #333333;
  145. }
  146. .head-more {
  147. .more-text {
  148. font-size: 22rpx;
  149. font-weight: 500;
  150. color: #333333;
  151. }
  152. .more-icon {
  153. color: #333333;
  154. font-size: 24rpx;
  155. }
  156. }
  157. }
  158. .coupon-card {
  159. width: 343rpx;
  160. height: 170rpx;
  161. background: linear-gradient(90deg, #f8dca5, #efc480);
  162. border-radius: 10rpx;
  163. mask: url($IMG_URL+'/imgs/coupon_mini_bg.png');
  164. -webkit-mask-box-image: url($IMG_URL+'/imgs/coupon_mini_bg.png');
  165. mask-size: 100% 100%;
  166. .card-left {
  167. height: 100%;
  168. width: 260rpx;
  169. .price {
  170. color: #4f3a1e;
  171. font-size: 30rpx;
  172. font-weight: bold;
  173. &::before {
  174. content: '¥';
  175. font-size: 20rpx;
  176. }
  177. }
  178. .notice {
  179. font-size: 22rpx;
  180. font-weight: 500;
  181. color: #a8700d;
  182. }
  183. }
  184. .card-right {
  185. height: 100%;
  186. width: 60rpx;
  187. .get-btn {
  188. font-size: 24rpx;
  189. font-weight: 500;
  190. text-align: right;
  191. color: #a8700d;
  192. writing-mode: vertical-lr; /*从左向右 从右向左是 writing-mode: vertical-rl;*/
  193. writing-mode: tb-lr; /*IE浏览器的从左向右 从右向左是 writing-mode: tb-rl;*/
  194. }
  195. }
  196. }
  197. }
  198. // 未领取,已领取
  199. .coupon-wrap {
  200. mask: url($IMG_URL+'/imgs/coupon_bg1.png');
  201. -webkit-mask-box-image: url($IMG_URL+'/imgs/coupon_bg1.png');
  202. mask-size: 100% 100%;
  203. position: relative;
  204. border-radius: 10rpx;
  205. width: 710rpx;
  206. height: 170rpx;
  207. background: linear-gradient(to right, $u-type-warning-disabled, $u-type-warning);
  208. .coupon-item {
  209. width: 100%;
  210. height: 168rpx;
  211. border-radius: 10rpx;
  212. .coupon-left {
  213. height: 100%;
  214. justify-content: center;
  215. padding-left: 40rpx;
  216. .unit {
  217. font-size: 24rpx;
  218. color: #fff;
  219. }
  220. .sum {
  221. font-size: 55rpx;
  222. font-weight: bold;
  223. color: #fff;
  224. line-height: 55rpx;
  225. padding-right: 10rpx;
  226. }
  227. .sub {
  228. font-size: 26rpx;
  229. color: #fff;
  230. }
  231. .notice {
  232. font-size: 22rpx;
  233. color: rgba(#fff, 0.7);
  234. margin-top: 6rpx;
  235. }
  236. }
  237. .coupon-right {
  238. height: 100%;
  239. width: 220rpx;
  240. justify-content: center;
  241. align-items: center;
  242. .get-btn {
  243. width: 142rpx;
  244. height: 54rpx;
  245. background: #ffffff;
  246. border-radius: 27rpx;
  247. padding: 0;
  248. font-size: 24rpx;
  249. font-weight: 500;
  250. color: $u-type-warning;
  251. }
  252. .surplus-num {
  253. font-size: 22rpx;
  254. font-weight: 500;
  255. color: #fff;
  256. margin-top: 14rpx;
  257. }
  258. }
  259. }
  260. }
  261. </style>