index.vue 6.7 KB

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