index.vue 6.6 KB

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