You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
5.7 KiB

3 months ago
  1. <template>
  2. <view :data-theme="theme">
  3. <view class="acea-row row-around nav">
  4. <template v-for="item in navList">
  5. <view :key="item.type" :class="['acea-row', 'row-middle', type === item.type ? 'on' : '']" >
  6. <text @click="setType(item.type)">{{ item.name }}</text>
  7. </view>
  8. </template>
  9. </view>
  10. <view style="height: 106rpx;"></view>
  11. <view class='coupon-list' v-if="couponsList.length">
  12. <view class='item acea-row row-center-wrapper' v-for="(item,index) in couponsList" :key="index">
  13. <view class='money' :class='item.isUse ? "moneyGray" : "main_bg" '>
  14. <view ><text class='num' :style="[{'font-size':item.money.length>=7?'42rpx':'60rpx'}]" >{{item.money?Number(item.money):''}}</text></view>
  15. <view class="pic-num">{{item.minPrice?Number(item.minPrice):''}}元可用</view>
  16. </view>
  17. <view class='text'>
  18. <view class='condition line2'>
  19. <span class='line-title' :class='(item.isUse==true || item.isUse==2)?"gray":"select"' v-if='item.useType===1'>通用</span>
  20. <span class='line-title' :class='(item.isUse==true || item.isUse==2)?"gray":"select"' v-else-if='item.useType===3'>品类</span>
  21. <span class='line-title' :class='(item.isUse==true || item.isUse==2)?"gray":"select"' v-else>商品</span>
  22. <span>{{item.name}}</span>
  23. </view>
  24. <view class='data acea-row row-between-wrapper'>
  25. <view v-if="item.day>0">领取后{{item.day}}天内可用</view>
  26. <view v-else>{{ item.useStartTimeStr&& item.useEndTimeStr ? item.useStartTimeStr + " - " + item.useEndTimeStr : ""}}</view>
  27. <view class='bnt gray' v-if="item.isUse==true">已领取</view>
  28. <view class='bnt main_bg' v-else @click='getCoupon(item.id,index)'>立即领取</view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class='loadingicon acea-row row-center-wrapper'>
  34. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{couponsList.length?loadTitle:''}}
  35. </view>
  36. <view class='noCommodity' v-if="!couponsList.length && isShow && !loading">
  37. <view class='pictrue'>
  38. <image :src="urlDomain+'crmebimage/perset/staticImg/noCoupon.png'"></image>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. getCoupons,
  46. setCouponReceive
  47. } from '@/api/api.js';
  48. import {
  49. toLogin
  50. } from '@/libs/login.js';
  51. import {
  52. mapGetters
  53. } from "vuex";
  54. let app = getApp();
  55. export default {
  56. data() {
  57. return {
  58. urlDomain: this.$Cache.get("imgHost"),
  59. couponsList:[],
  60. loading: false,
  61. loadend: false,
  62. loadTitle: '加载更多',//提示语
  63. page: 1,
  64. limit: 20,
  65. type: 1,
  66. isShow: false,
  67. navList: [{
  68. type: 1,
  69. name: '通用券',
  70. count: 0
  71. },
  72. {
  73. type: 2,
  74. name: '商品券',
  75. count: 0
  76. },
  77. {
  78. type: 3,
  79. name: '品类券',
  80. count: 0
  81. },
  82. ],
  83. count: 0,
  84. theme:app.globalData.theme,
  85. };
  86. },
  87. computed: mapGetters(['isLogin']),
  88. watch: {
  89. isLogin: {
  90. handler: function(newV, oldV) {
  91. if (newV) {
  92. this.getUseCoupons();
  93. }
  94. },
  95. deep: true
  96. }
  97. },
  98. onLoad(){
  99. if(this.isLogin){
  100. this.getUseCoupons();
  101. }else{
  102. toLogin();
  103. }
  104. },
  105. /**
  106. * 页面上拉触底事件的处理函数
  107. */
  108. onReachBottom: function () {
  109. this.getUseCoupons();
  110. },
  111. methods: {
  112. getCoupon:function(id,index){
  113. let that = this;
  114. let list = that.couponsList;
  115. let ids = [];
  116. ids.push(id);
  117. //领取优惠券
  118. setCouponReceive(id).then(function (res) {
  119. list[index].isUse = true;
  120. that.$set(that,'couponsList',list);
  121. that.$util.Tips({ title: '领取成功' });
  122. },function(res){
  123. return that.$util.Tips({title:res});
  124. })
  125. },
  126. /**
  127. * 获取领取优惠券列表
  128. */
  129. getUseCoupons:function(){
  130. let that=this
  131. if(that.loadend) return false;
  132. if(that.loading) return false;
  133. that.loading = true;
  134. getCoupons({ page: that.page, limit: that.limit, type: that.type }).then(res=>{
  135. let list=res.data.list,loadend=list.length < that.limit;
  136. let couponsList = that.$util.SplitArray(list, that.couponsList);
  137. that.$set(that,'couponsList',couponsList);
  138. that.loadend = loadend;
  139. that.loadTitle = loadend ? '我也是有底线的~' : '加载更多';
  140. that.page = that.page + 1;
  141. that.loading = false;
  142. that.isShow = true;
  143. }).catch(err=>{
  144. that.loading = false;
  145. that.loadTitle = '加载更多';
  146. });
  147. },
  148. setType: function(type) {
  149. if (this.type !== type) {
  150. this.type = type;
  151. this.couponsList = [];
  152. this.page = 1;
  153. this.loadend = false;
  154. this.getUseCoupons();
  155. }
  156. }
  157. }
  158. }
  159. </script>
  160. <style scoped lang="scss">
  161. .nav {
  162. position: fixed;
  163. top: 0;
  164. left: 0;
  165. width: 100%;
  166. height: 106rpx;
  167. background-color: #FFFFFF;
  168. font-size: 30rpx;
  169. color: #999999;
  170. z-index: 9;
  171. }
  172. .nav .acea-row {
  173. border-top: 5rpx solid transparent;
  174. border-bottom: 5rpx solid transparent;
  175. cursor: pointer;
  176. }
  177. .nav .acea-row.on {
  178. @include tab_border_bottom(theme);
  179. @include main_color(theme);
  180. }
  181. .condition .line-title{
  182. width:90rpx;
  183. padding: 0 10rpx;
  184. box-sizing: border-box;
  185. background:#fff;
  186. opacity:1;
  187. border-radius:20rpx;
  188. font-size:20rpx;
  189. margin-right: 12rpx;
  190. }
  191. .condition .line-title.gray{
  192. border:1px solid #BBB;
  193. color:#bbb;
  194. background-color:#F5F5F5;
  195. }
  196. .coupon-list .pic-num{
  197. color: #FFFFFF;
  198. font-size: 24rpx;
  199. }
  200. .main_bg{
  201. @include main_bg_color(theme);
  202. }
  203. .select{
  204. @include main_color(theme);
  205. @include coupons_border_color(theme);
  206. }
  207. </style>