index.vue 6.6 KB

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