index.vue 5.7 KB

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