index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view>
  3. <view class='coupon-list-window' :class='coupon.coupon === true?"on":""'>
  4. <view v-if="!orderShow" class="nav acea-row row-around">
  5. <view :class="['acea-row', 'row-middle', type === 1 ? 'on' : '']" @click="setType(1)">通用券</view>
  6. <view :class="['acea-row', 'row-middle', type === 2 ? 'on' : '']" @click="setType(2)">商品券</view>
  7. <view :class="['acea-row', 'row-middle', type === 3 ? 'on' : '']" @click="setType(3)">品类券</view>
  8. </view>
  9. <view class='coupon-list' :style="{'margin-top':!orderShow?'0':'50rpx'}">
  10. <block v-if="coupon.list.length">
  11. <view class='item acea-row row-center-wrapper' v-for="(item,index) in coupon.list"
  12. @click="getCouponUser(index, item.id)" :key='index'>
  13. <!-- 金额 -->
  14. <view class='money acea-row row-column row-center-wrapper' :class='item.canTake ? "" : "moneyGray"'>
  15. <view>¥
  16. <text v-if="item.discountType === 1" class='num'>{{ fen2yuan(item.discountPrice) }}</text>
  17. <text v-else class='num'>{{ (item.discountPercent / 10.0).toFixed(1) }} 折</text>
  18. </view>
  19. <view class="pic-num">满 {{ fen2yuan(item.usePrice) }} 元可用</view>
  20. </view>
  21. <view class='text'>
  22. <!-- 类型 -->
  23. <view class='condition line2'>
  24. <span class='line-title' :class='item.isUse?"gray":""' v-if='type === 1'>通用</span>
  25. <span class='line-title' :class='item.isUse?"gray":""'
  26. v-else-if='type === 3'>品类</span>
  27. <span class='line-title' :class='item.isUse?"gray":""' v-else>商品</span>
  28. <span>{{item.name}}</span>
  29. </view>
  30. <!-- 领取类型 -->
  31. <view class='data acea-row row-between-wrapper'>
  32. <view v-if="item.validityType > 1">领取后 {{ item.fixedEndTerm }} 天内可用</view>
  33. <view v-else>
  34. {{ formatDate(item.validStartTime) + " - " + formatDate(item.validEndTime) }}
  35. </view>
  36. <view class='bnt bg-color' v-if="item.canTake">{{coupon.statusTile || '立即领取'}}</view>
  37. <view class='bnt gray' v-else>{{item.use_title || '已领取'}}</view>
  38. </view>
  39. </view>
  40. </view>
  41. </block>
  42. <!-- 无优惠券 -->
  43. <view class='pictrue' v-else>
  44. <image src='../../static/images/noCoupon.png'></image>
  45. </view>
  46. </view>
  47. </view>
  48. <view class='mask' catchtouchmove="true" :hidden='!coupon.coupon' @click='close'></view>
  49. </view>
  50. </template>
  51. <script>
  52. import * as Util from '@/utils/util.js';
  53. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  54. import * as CouponApi from '@/api/promotion/coupon.js';
  55. export default {
  56. props: {
  57. openType: {
  58. type: Number, // 打开状态 0=领取优惠券, 1=使用优惠券
  59. default: 0,
  60. },
  61. coupon: {
  62. type: Object,
  63. default: function() {
  64. return {};
  65. }
  66. },
  67. orderShow: {
  68. type: String, // 下单页面使用优惠券组件不展示 tab 切换页
  69. default: function() {
  70. return '';
  71. }
  72. }
  73. },
  74. data() {
  75. return {
  76. type: 1 // 使用类型
  77. };
  78. },
  79. methods: {
  80. close: function() {
  81. this.type = 1
  82. this.$emit('ChangCouponsClose');
  83. },
  84. /**
  85. * 选择优惠劵
  86. */
  87. getCouponUser: function(index, id) {
  88. // 领取优惠劵时,如果已经领取,则直接跳过
  89. let list = this.coupon.list;
  90. switch (this.openType) {
  91. case 0: // 领取优惠券
  92. if (!list[index].canTake) {
  93. return;
  94. }
  95. CouponApi.takeCoupon(id).then(res => {
  96. this.$util.Tips({
  97. title: "领取成功"
  98. });
  99. this.$emit('ChangCoupons', list[index]);
  100. })
  101. break;
  102. case 1: // 使用优惠劵
  103. // TODO 芋艿:需要额外把不可用优惠劵的样式做了;
  104. if (list[index].match === false) {
  105. alert('该优惠劵无法使用,原因:' + list[index].description);
  106. return;
  107. }
  108. this.$emit('ChangCoupons', index);
  109. break;
  110. }
  111. },
  112. setType: function(type) {
  113. this.type = type;
  114. this.$emit('tabCouponType', type);
  115. },
  116. fen2yuan(price) {
  117. return Util.fen2yuan(price)
  118. },
  119. formatDate: function(date) {
  120. return dayjs(date).format("YYYY-MM-DD");
  121. }
  122. }
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. .coupon-list-window {
  127. position: fixed;
  128. bottom: 0;
  129. left: 0;
  130. width: 100%;
  131. background-color: #f5f5f5;
  132. border-radius: 16rpx 16rpx 0 0;
  133. z-index: 555;
  134. transform: translate3d(0, 100%, 0);
  135. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  136. }
  137. .coupon-list-window.on {
  138. transform: translate3d(0, 0, 0);
  139. }
  140. .coupon-list-window .title {
  141. height: 124rpx;
  142. width: 100%;
  143. text-align: center;
  144. line-height: 124rpx;
  145. font-size: 32rpx;
  146. font-weight: bold;
  147. position: relative;
  148. }
  149. .coupon-list-window .title .iconfont {
  150. position: absolute;
  151. right: 30rpx;
  152. top: 50%;
  153. transform: translateY(-50%);
  154. font-size: 35rpx;
  155. color: #8a8a8a;
  156. font-weight: normal;
  157. }
  158. .coupon-list-window .coupon-list {
  159. margin: 0 0 30rpx 0;
  160. height: 823rpx;
  161. overflow: auto;
  162. padding-top: 30rpx;
  163. }
  164. .coupon-list-window .pictrue {
  165. width: 414rpx;
  166. height: 336rpx;
  167. margin: 208rpx auto;
  168. }
  169. .coupon-list-window .pictrue image {
  170. width: 100%;
  171. height: 100%;
  172. }
  173. .pic-num {
  174. color: #fff;
  175. font-size: 24rpx;
  176. }
  177. .line-title {
  178. width: 90rpx;
  179. padding: 0 10rpx;
  180. box-sizing: border-box;
  181. background: rgba(255, 247, 247, 1);
  182. border: 1px solid rgba(232, 51, 35, 1);
  183. opacity: 1;
  184. border-radius: 20rpx;
  185. font-size: 20rpx;
  186. color: #E83323;
  187. margin-right: 12rpx;
  188. }
  189. .line-title.gray {
  190. border-color: #BBB;
  191. color: #bbb;
  192. background-color: #F5F5F5;
  193. }
  194. .nav {
  195. // position: absolute;
  196. // top: 0;
  197. // left: 0;
  198. width: 100%;
  199. height: 96rpx;
  200. border-bottom: 2rpx solid #F5F5F5;
  201. border-top-left-radius: 16rpx;
  202. border-top-right-radius: 16rpx;
  203. background-color: #FFFFFF;
  204. font-size: 30rpx;
  205. color: #999999;
  206. }
  207. .nav .acea-row {
  208. border-top: 5rpx solid transparent;
  209. border-bottom: 5rpx solid transparent;
  210. }
  211. .nav .acea-row.on {
  212. border-bottom-color: #E93323;
  213. color: #282828;
  214. }
  215. .nav .acea-row:only-child {
  216. border-bottom-color: transparent;
  217. }
  218. .occupy {
  219. height: 106rpx;
  220. }
  221. .coupon-list .item {
  222. margin-bottom: 20rpx;
  223. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.06);
  224. }
  225. .coupon-list .item .money {
  226. font-weight: normal;
  227. }
  228. </style>