index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view :style="colorStyle">
  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>
  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. :class="{svip: item.receive_type === 4}" @click="useCoupon(item)">
  10. <view class="moneyCon acea-row row-center-wrapper">
  11. <view class='money' :class='item._type == 0 ? "moneyGray" : ""'>
  12. <view>¥<text class='num'>{{item.coupon_price}}</text></view>
  13. <view class="pic-num" v-if="item.use_min_price > 0">满{{item.use_min_price}}元可用</view>
  14. <view class="pic-num" v-else>无门槛券</view>
  15. </view>
  16. </view>
  17. <view class='text'>
  18. <view class='condition'>
  19. <view class="name line2">
  20. <view class="line-title" :class="item._type === 0 ? 'bg-color-huic' : 'bg-color-check'"
  21. v-if="item.applicable_type === 0">通用劵</view>
  22. <view class="line-title" :class="item._type === 0 ? 'bg-color-huic' : 'bg-color-check'"
  23. v-else-if="item.applicable_type === 1">品类券</view>
  24. <view class="line-title" :class="item._type === 0 ? 'bg-color-huic' : 'bg-color-check'"
  25. v-else>商品券</view>
  26. <image src="../../../static/images/fvip.png" class="pic" v-if="item.receive_type===4">
  27. </image>
  28. <text>{{item.coupon_title}}</text>
  29. </view>
  30. </view>
  31. <view class='data acea-row row-between-wrapper'>
  32. <view>{{item.add_time}}-{{item.end_time}}</view>
  33. <view class='bnt gray' v-if="item._type==0">{{item._msg}}</view>
  34. <view class='bnt bg-color' v-else>{{item._msg}}</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class='noCommodity' v-if="!couponsList.length && page === 2">
  40. <view class='pictrue'>
  41. <image src='../../../static/images/noCoupon.png'></image>
  42. </view>
  43. </view>
  44. <!-- #ifdef MP -->
  45. <!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
  46. <!-- #endif -->
  47. <!-- #ifndef MP -->
  48. <home></home>
  49. <!-- #endif -->
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. getUserCoupons
  55. } from '@/api/api.js';
  56. import {
  57. toLogin
  58. } from '@/libs/login.js';
  59. import {
  60. mapGetters
  61. } from "vuex";
  62. // #ifdef MP
  63. import authorize from '@/components/Authorize';
  64. // #endif
  65. import home from '@/components/home';
  66. import colors from '@/mixins/color.js';
  67. export default {
  68. components: {
  69. // #ifdef MP
  70. authorize,
  71. // #endif
  72. home
  73. },
  74. mixins:[colors],
  75. data() {
  76. return {
  77. couponsList: [],
  78. loading: false,
  79. isAuto: false, //没有授权的不会自动授权
  80. isShowAuth: false, //是否隐藏授权
  81. navOn: 1,
  82. page: 1,
  83. limit: 15,
  84. finished: false
  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. onReachBottom() {
  106. this.getUseCoupons();
  107. },
  108. methods: {
  109. onNav: function(type) {
  110. this.navOn = type;
  111. this.couponsList = [];
  112. this.page = 1;
  113. this.finished = false;
  114. this.getUseCoupons();
  115. },
  116. useCoupon(item){
  117. let url = '';
  118. if (item.category_id == 0 && item.product_id == '') {
  119. url = '/pages/goods_list/index?title=默认'
  120. }
  121. if (item.category_id != 0) {
  122. if (item.category_type == 1) {
  123. url = '/pages/goods_list/index?cid='+item.category_id+'&title='+item.category_name
  124. }else{
  125. url = '/pages/goods_list/index?sid='+item.category_id+'&title='+item.category_name
  126. }
  127. }
  128. if (item.product_id != '') {
  129. let arr = item.product_id.split(',');
  130. let num = arr.length;
  131. if (num == 1) {
  132. url = '/pages/goods_details/index?id='+item.product_id
  133. } else {
  134. url = '/pages/goods_list/index?productId='+item.product_id+'&title=默认'
  135. }
  136. }
  137. uni.navigateTo({
  138. url: url
  139. });
  140. },
  141. /**
  142. * 授权回调
  143. */
  144. onLoadFun: function() {
  145. this.getUseCoupons();
  146. },
  147. // 授权关闭
  148. authColse: function(e) {
  149. this.isShowAuth = e
  150. },
  151. /**
  152. * 获取领取优惠券列表
  153. */
  154. getUseCoupons: function() {
  155. let that = this;
  156. if (that.loading || that.finished) {
  157. return;
  158. }
  159. that.loading = true;
  160. uni.showLoading({
  161. title: '正在加载…'
  162. });
  163. getUserCoupons(this.navOn, {
  164. page: this.page,
  165. limit: this.limit
  166. }).then(res => {
  167. that.loading = false;
  168. uni.hideLoading();
  169. that.couponsList = that.couponsList.concat(res.data);
  170. that.finished = res.data.length < that.limit;
  171. that.page += 1;
  172. }).catch(err => {
  173. that.loading = false;
  174. uni.showToast({
  175. title: err,
  176. icon: 'none'
  177. });
  178. });
  179. }
  180. }
  181. }
  182. </script>
  183. <style>
  184. .money {
  185. display: flex;
  186. flex-direction: column;
  187. justify-content: center;
  188. }
  189. .pic-num {
  190. color: #ffffff;
  191. font-size: 24rpx;
  192. }
  193. .coupon-list .item .text .condition {
  194. display: flex;
  195. align-items: center;
  196. }
  197. .coupon-list .item .text .condition .name {
  198. font-size: 26rpx;
  199. font-weight: 500;
  200. display: flex;
  201. align-items: center;
  202. }
  203. .coupon-list .item .text .condition .pic {
  204. width: 30rpx;
  205. height: 30rpx;
  206. display: block;
  207. margin-right: 10rpx;
  208. display: inline-block;
  209. vertical-align: middle;
  210. }
  211. .condition .line-title {
  212. width: 70rpx;
  213. height: 32rpx !important;
  214. line-height: 30rpx;
  215. text-align: center;
  216. box-sizing: border-box;
  217. background: rgba(255, 247, 247, 1);
  218. border: 1px solid var(--view-theme);
  219. opacity: 1;
  220. border-radius: 20rpx;
  221. font-size: 18rpx !important;
  222. color: var(--view-theme);
  223. margin-right: 12rpx;
  224. text-align: center;
  225. display: inline-block;
  226. vertical-align: middle;
  227. }
  228. .condition .line-title.bg-color-huic {
  229. border-color: #BBB !important;
  230. color: #bbb !important;
  231. background-color: #F5F5F5 !important;
  232. }
  233. </style>
  234. <style lang="scss" scoped>
  235. .navbar {
  236. position: fixed;
  237. top: 0;
  238. left: 0;
  239. width: 100%;
  240. height: 90rpx;
  241. background-color: #FFFFFF;
  242. z-index: 9;
  243. .item {
  244. border-top: 5rpx solid transparent;
  245. border-bottom: 5rpx solid transparent;
  246. font-size: 30rpx;
  247. color: #999999;
  248. &.on {
  249. border-bottom-color: var(--view-theme);
  250. color: #282828;
  251. }
  252. }
  253. }
  254. .coupon-list {
  255. margin-top: 122rpx;
  256. }
  257. .noCommodity {
  258. margin-top: 300rpx;
  259. }
  260. </style>