coupon.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="diy-coupon"
  3. :style="{ background: itemData.style.background, padding: itemData.style.paddingTop + 'px 20rpx' }">
  4. <scroll-view scroll-x="true">
  5. <view class="swiper swiper-list">
  6. <view class="coupon-item" :class="'bg-' + item.color.text" v-for="(item, index) in listData"
  7. :key="index">
  8. <view class="side-line left-side-line" ><text class="round" :style="{ background: itemData.style.background}"></text></view>
  9. <view class="side-line right-side-line"><text class="round" :style="{ background: itemData.style.background}"></text></view>
  10. <view class="left-type d-c-c">{{ item.coupon_type.text }}</view>
  11. <view class="center-content pr">
  12. <view class="content-top">
  13. <template v-if="item.coupon_type.value == 10">
  14. <text class="f22">¥</text>
  15. <text class="f28 fb">{{ item.reduce_price }}</text>
  16. </template>
  17. <template v-if="item.coupon_type.value == 20">
  18. <text class="f28 fb">{{ item.discount }}</text>
  19. <text>折</text>
  20. </template>
  21. </view>
  22. <view class="content-bottom">
  23. <text class="f20">{{ item.name }}</text>
  24. </view>
  25. </view>
  26. <!--领取-->
  27. <view v-if="item.state.value == 1" class="right-receive d-c-c" @click="receiveCoupon(index)">
  28. 立即领取
  29. </view>
  30. <view v-else class="right-receive no-receive d-c-c">
  31. {{ item.state.text }}
  32. </view>
  33. </view>
  34. </view>
  35. </scroll-view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. /*是否显示点*/
  43. indicatorDots: false,
  44. /*是否自动*/
  45. autoplay: true,
  46. /*切换时间*/
  47. interval: 5000,
  48. /*动画过渡时间*/
  49. duration: 1000,
  50. /*数据列表*/
  51. listData: []
  52. };
  53. },
  54. props: ['itemData'],
  55. created() {
  56. this.listData = this.itemData.data;
  57. },
  58. methods: {
  59. scroll(e) {},
  60. /**
  61. * 领取优惠券
  62. */
  63. receiveCoupon: function(index) {
  64. let self = this;
  65. let item = self.listData[index];
  66. if (item.state.value == 0) {
  67. return false;
  68. }
  69. self._post(
  70. 'user.coupon/receive', {
  71. coupon_id: item.coupon_id
  72. },
  73. function(result) {
  74. uni.showToast({
  75. title: '领取成功',
  76. icon: 'success',
  77. mask: true,
  78. duration: 2000
  79. });
  80. item.state.value = 0;
  81. item.state.text = '已领取';
  82. }
  83. );
  84. }
  85. }
  86. };
  87. </script>
  88. <style>
  89. .diy-coupon {
  90. margin:0 20rpx;
  91. border-radius: 20rpx;
  92. }
  93. .f-s-0 {
  94. flex-shrink: 0;
  95. }
  96. .diy-coupon .swiper {
  97. height: 174rpx;
  98. display: flex;
  99. justify-content: flex-start;
  100. align-items: center;
  101. overflow-x: auto;
  102. }
  103. .diy-coupon .coupon-item {
  104. width: 196rpx;
  105. height: 158rpx;
  106. color: #ffffff;
  107. flex-shrink: 0;
  108. margin: 8rpx;
  109. position: relative;
  110. border-radius: 8rpx;
  111. overflow: hidden;
  112. background: #feefef;
  113. color: #ef3325;
  114. display: block;
  115. }
  116. .diy-coupon .coupon-item.bg-red .right-receive {
  117. background: #fe3d30;
  118. }
  119. .diy-coupon .coupon-item.bg-blue .right-receive{
  120. background: #178ed9;
  121. }
  122. .diy-coupon .coupon-item.bg-yellow .right-receive{
  123. background: #fe961a;
  124. }
  125. .diy-coupon .coupon-item.bg-violet .right-receive{
  126. background: #ab0bf6;
  127. }
  128. .diy-coupon .coupon-item .left-type {
  129. padding: 4rpx 8rpx;
  130. font-size: 18rpx;
  131. line-height: 18rpx;
  132. text-align: center;
  133. position: absolute;
  134. right: 0;
  135. top: 0;
  136. color: #ffffff;
  137. background: linear-gradient(to right, #ff5b00, #fe8802);
  138. border-bottom-left-radius: 8rpx;
  139. }
  140. .diy-coupon .left-side-line {
  141. position: absolute;
  142. width: 12rpx;
  143. bottom: 36rpx;
  144. left: -6rpx;
  145. overflow: hidden;
  146. }
  147. .diy-coupon .right-side-line {
  148. position: absolute;
  149. width: 12rpx;
  150. bottom: 36rpx;
  151. right: -6rpx;
  152. overflow: hidden;
  153. }
  154. .diy-coupon .side-line .round {
  155. display: block;
  156. width: 12rpx;
  157. height: 12rpx;
  158. border-radius: 50%;
  159. margin: 4rpx 0;
  160. background: #ffffff;
  161. }
  162. .diy-coupon .center-content::before {
  163. top: 0;
  164. right: -16rpx;
  165. border-radius: 0 0 15rpx 15rpx;
  166. }
  167. .diy-coupon .coupon-item .center-content {
  168. padding: 26rpx 23rpx;
  169. display: flex;
  170. justify-content: space-between;
  171. flex-direction: column;
  172. align-items: flex-start;
  173. flex: 1;
  174. height: 112rpx;
  175. box-sizing: border-box;
  176. }
  177. .diy-coupon .coupon-item .center-content .content-top {
  178. height: 28rpx;
  179. line-height: 28rpx;
  180. }
  181. .diy-coupon .coupon-item .center-content .content-datatime {
  182. padding: 4rpx 10rpx;
  183. border-radius: 30rpx;
  184. font-size: 20rpx;
  185. background: rgba(0, 0, 0, .2);
  186. }
  187. .diy-coupon .coupon-item .right-receive {
  188. height: 46rpx;
  189. width: 100%;
  190. text-align: center;
  191. font-size: 20rpx;
  192. line-height: 20rpx;
  193. text-align: center;
  194. color: #FFFFFF;
  195. }
  196. .diy-coupon .coupon-item .no-receive {
  197. background: #acacac !important;
  198. color: #ffffff;
  199. }
  200. </style>