index.vue 5.7 KB

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