index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view>
  3. <view class='coupon-list' v-if="couponsList.length">
  4. <view class='item acea-row row-center-wrapper' v-for="(item,index) in couponsList" :key="index">
  5. <view class='money' :class='item.is_use ? "moneyGray" : "" '>
  6. <view>¥<text class='num'>{{item.coupon_price}}</text></view>
  7. <view class="pic-num">满{{item.use_min_price}}元可用</view>
  8. </view>
  9. <view class='text'>
  10. <view class='condition line1'>
  11. <span class='line-title' :class='(item.is_use==true || item.is_use==2)?"gray":""' v-if='item.type===0'>通用劵</span>
  12. <span class='line-title' :class='(item.is_use==true || item.is_use==2)?"gray":""' v-else-if='item.type===1'>品类券</span>
  13. <span class='line-title' :class='(item.is_use==true || item.is_use==2)?"gray":""' v-else>商品券</span>
  14. <span>{{item.title}}</span>
  15. </view>
  16. <view class='data acea-row row-between-wrapper'>
  17. <view>{{ item.start_time ? item.start_time + "-" : ""}}{{ item.end_time }}</view>
  18. <view class='bnt gray' v-if="item.is_use==true">已领取</view>
  19. <view class='bnt gray' v-else-if="item.is_use==2">已领完</view>
  20. <view class='bnt bg-color' v-else @click='getCoupon(item.id,index)'>立即领取</view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class='loadingicon acea-row row-center-wrapper' v-if="couponsList.length">
  26. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  27. </view>
  28. <view class='noCommodity' v-else-if="!couponsList.length && loading==true">
  29. <view class='pictrue'>
  30. <image :src="`${domain}/static/images/noCoupon.png`"></image>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. // +----------------------------------------------------------------------
  37. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  38. // +----------------------------------------------------------------------
  39. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  40. // +----------------------------------------------------------------------
  41. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  42. // +----------------------------------------------------------------------
  43. // | Author: CRMEB Team <admin@crmeb.com>
  44. // +----------------------------------------------------------------------
  45. import { getCoupons, setCouponReceive } from '@/api/api.js';
  46. import { mapGetters } from "vuex";
  47. import { HTTP_REQUEST_URL } from '@/config/app';
  48. import { toLogin } from '@/libs/login.js';
  49. export default {
  50. components: {},
  51. data() {
  52. return {
  53. domain: HTTP_REQUEST_URL,
  54. couponsList: [],
  55. loading: false,
  56. loadend: false,
  57. loadTitle: '加载更多',//提示语
  58. page: 1,
  59. limit: 20,
  60. };
  61. },
  62. computed: mapGetters(['isLogin']),
  63. onLoad(){
  64. if(this.isLogin){
  65. // #ifdef H5
  66. this.getUseCoupons();
  67. // #endif
  68. }else{
  69. toLogin()
  70. }
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom: function () {
  76. this.getUseCoupons();
  77. },
  78. methods: {
  79. getCoupon:function(id,index){
  80. let that = this;
  81. let list = that.couponsList;
  82. //领取优惠券
  83. setCouponReceive(id).then(function (res) {
  84. list[index].is_use = true;
  85. that.$set(that,'couponsList',list);
  86. that.$util.Tips({ title: '领取成功' });
  87. },function(res){
  88. return that.$util.Tips({title:res.message});
  89. });
  90. },
  91. /**
  92. * 获取领取优惠券列表
  93. */
  94. getUseCoupons:function(){
  95. let that=this
  96. if(this.loadend) return false;
  97. if(this.loading) return false;
  98. getCoupons({ page: that.page, limit: that.limit }).then(res=>{
  99. let list=res.data,loadend=list.length < that.limit;
  100. let couponsList = that.$util.SplitArray(list, that.couponsList);
  101. that.$set(that,'couponsList',couponsList);
  102. that.loadend = loadend;
  103. that.loadTitle = loadend ? '我也是有底线的' : '加载更多';
  104. that.page = that.page + 1;
  105. that.loading = false;
  106. }).catch(err=>{
  107. that.loading = false;
  108. that.loadTitle = '加载更多';
  109. });
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .condition .line-title{
  116. width:90rpx;
  117. padding: 0 10rpx;
  118. box-sizing: border-box;
  119. background:rgba(255,247,247,1);
  120. border:1px solid rgba(232,51,35,1);
  121. opacity:1;
  122. border-radius:20rpx;
  123. font-size:20rpx;
  124. color: #E83323;
  125. margin-right: 12rpx;
  126. }
  127. .condition .line-title.gray{
  128. border-color:#BBB;
  129. color:#bbb;
  130. background-color:#F5F5F5;
  131. }
  132. .coupon-list .pic-num{
  133. color: #FFFFFF;
  134. font-size: 24rpx;
  135. }
  136. </style>