index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view>
  3. <view class="navbar acea-row row-around">
  4. <view class="item acea-row row-center-wrapper" :class="{ on: navOn === 'usable' }" @click="onNav('usable')">未使用</view>
  5. <view class="item acea-row row-center-wrapper" :class="{ on: navOn === 'unusable' }" @click="onNav('unusable')">已使用/过期</view>
  6. </view>
  7. <view class='coupon-list' v-if="couponsList.length">
  8. <view class='item acea-row row-center-wrapper' v-for='(item,index) in couponsList' :key="index">
  9. <view class='money' :class="item.validStr==='unusable'||item.validStr==='overdue'||item.validStr==='notStart' ? 'moneyGray' : ''">
  10. <view>¥<text class='num'>{{item.money?Number(item.money):''}}</text></view>
  11. <view class="pic-num">满{{ item.minPrice?Number(item.minPrice):'' }}元可用</view>
  12. </view>
  13. <view class='text'>
  14. <view class='condition line2'>
  15. <span class="line-title" :class="item.validStr==='unusable'||item.validStr==='overdue'||item.validStr==='notStart' ? 'bg-color-huic' : 'bg-color-check'" v-if="item.useType === 1">通用</span>
  16. <span class="line-title" :class="item.validStr==='unusable'||item.validStr==='overdue'||item.validStr==='notStart' ? 'bg-color-huic' : 'bg-color-check'" v-else-if="item.useType === 2">商品</span>
  17. <span class="line-title" :class="item.validStr==='unusable'||item.validStr==='overdue'||item.validStr==='notStart' ? 'bg-color-huic' : 'bg-color-check'" v-else-if="item.useType === 3">品类</span>
  18. <span>{{item.name}}</span>
  19. </view>
  20. <view class='data acea-row row-between-wrapper'>
  21. <view>{{item.useStartTimeStr}}~{{item.useEndTimeStr}}</view>
  22. <view class='bnt' :class="item.validStr==='unusable'||item.validStr==='overdue'||item.validStr==='notStart'?'gray':'bg-color'">{{item.validStr | validStrFilter}}</view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class='loadingicon acea-row row-center-wrapper' v-if="couponsList.length">
  28. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  29. </view>
  30. <view class='noCommodity' v-if="!couponsList.length">
  31. <view class='pictrue'>
  32. <image src='../../../static/images/noCoupon.png'></image>
  33. </view>
  34. </view>
  35. <!-- #ifdef MP -->
  36. <!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
  37. <!-- #endif -->
  38. <home></home>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. getUserCoupons
  44. } from '@/api/api.js';
  45. import {
  46. toLogin
  47. } from '@/libs/login.js';
  48. import {
  49. mapGetters
  50. } from "vuex";
  51. // #ifdef MP
  52. import authorize from '@/components/Authorize';
  53. // #endif
  54. import home from '@/components/home';
  55. export default {
  56. components: {
  57. // #ifdef MP
  58. authorize,
  59. // #endif
  60. home
  61. },
  62. filters: {
  63. validStrFilter(status) {
  64. const statusMap = {
  65. 'usable': '可用',
  66. 'unusable': '已用',
  67. 'overdue': '过期',
  68. 'notStart': '未开始'
  69. }
  70. return statusMap[status]
  71. }
  72. },
  73. data() {
  74. return {
  75. couponsList: [],
  76. loading: false,
  77. loadend: false,
  78. loadTitle: '加载更多',//提示语
  79. page: 1,
  80. limit: 20,
  81. navOn: 'usable',
  82. isAuto: false, //没有授权的不会自动授权
  83. isShowAuth: false //是否隐藏授权
  84. };
  85. },
  86. computed: mapGetters(['isLogin']),
  87. watch: {
  88. isLogin: {
  89. handler: function(newV, oldV) {
  90. if (newV) {
  91. this.getUseCoupons();
  92. }
  93. },
  94. deep: true
  95. }
  96. },
  97. onLoad() {
  98. if (this.isLogin) {
  99. this.getUseCoupons();
  100. } else {
  101. toLogin();
  102. }
  103. },
  104. methods: {
  105. /**
  106. * 授权回调
  107. */
  108. onLoadFun: function() {
  109. this.getUseCoupons();
  110. },
  111. // 授权关闭
  112. authColse: function(e) {
  113. this.isShowAuth = e
  114. },
  115. onNav: function(type) {
  116. this.navOn = type;
  117. this.couponsList = [];
  118. this.page = 1;
  119. this.loadend = false;
  120. this.getUseCoupons();
  121. },
  122. /**
  123. * 获取领取优惠券列表
  124. */
  125. getUseCoupons: function() {
  126. let that = this;
  127. if(this.loadend) return false;
  128. if(this.loading) return false;
  129. getUserCoupons({ page: that.page, limit: that.limit, type: that.navOn}).then(res => {
  130. let list= res.data ? res.data.list : [],loadend=list.length < that.limit;
  131. let couponsList = that.$util.SplitArray(list, that.couponsList);
  132. that.$set(that,'couponsList',couponsList);
  133. that.loadend = loadend;
  134. that.loadTitle = loadend ? '我也是有底线的' : '加载更多';
  135. that.page = that.page + 1;
  136. that.loading = false;
  137. }).catch(err=>{
  138. that.loading = false;
  139. that.loadTitle = '加载更多';
  140. });
  141. }
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function () {
  147. this.getUseCoupons();
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. .navbar {
  153. position: fixed;
  154. top: 0;
  155. left: 0;
  156. width: 100%;
  157. height: 106rpx;
  158. background-color: #FFFFFF;
  159. z-index: 9;
  160. .item {
  161. border-top: 5rpx solid transparent;
  162. border-bottom: 5rpx solid transparent;
  163. font-size: 30rpx;
  164. color: #999999;
  165. &.on {
  166. border-bottom-color: #E93323;
  167. color: #282828;
  168. }
  169. }
  170. }
  171. .money {
  172. display: flex;
  173. flex-direction: column;
  174. justify-content: center;
  175. }
  176. .pic-num {
  177. color: #ffffff;
  178. font-size: 24rpx;
  179. }
  180. .coupon-list {
  181. margin-top: 122rpx;
  182. }
  183. .coupon-list .item .text{
  184. height: 100%;
  185. }
  186. .coupon-list .item .text .condition{
  187. /* display: flex;
  188. align-items: center; */
  189. }
  190. .condition .line-title {
  191. width: 90rpx;
  192. height: 40rpx !important;
  193. line-height: 40rpx !important;
  194. padding: 2rpx 10rpx;
  195. -webkit-box-sizing: border-box;
  196. box-sizing: border-box;
  197. background: rgba(255, 247, 247, 1);
  198. border: 1px solid rgba(232, 51, 35, 1);
  199. opacity: 1;
  200. border-radius: 20rpx;
  201. font-size: 18rpx !important;
  202. color: #e83323;
  203. margin-right: 12rpx;
  204. }
  205. .noCommodity {
  206. margin-top: 300rpx;
  207. }
  208. </style>