index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. if (item.category_type == 1) {
  125. url = '/pages/goods/goods_list/index?cid='+item.category_id+'&title='+item.category_name
  126. }else{
  127. url = '/pages/goods/goods_list/index?sid='+item.category_id+'&title='+item.category_name
  128. }
  129. }
  130. if (item.product_id != '') {
  131. let arr = item.product_id.split(',');
  132. let num = arr.length;
  133. if (num == 1) {
  134. url = '/pages/goods_details/index?id='+item.product_id
  135. } else {
  136. url = '/pages/goods/goods_list/index?productId='+item.product_id+'&title=默认'
  137. }
  138. }
  139. uni.navigateTo({
  140. url: url
  141. });
  142. },
  143. /**
  144. * 授权回调
  145. */
  146. onLoadFun: function() {
  147. this.getUseCoupons();
  148. },
  149. // 授权关闭
  150. authColse: function(e) {
  151. this.isShowAuth = e
  152. },
  153. /**
  154. * 获取领取优惠券列表
  155. */
  156. getUseCoupons: function() {
  157. let that = this;
  158. if (that.loading || that.finished) {
  159. return;
  160. }
  161. that.loading = true;
  162. uni.showLoading({
  163. title: that.$t(`正在加载…`)
  164. });
  165. getUserCoupons(this.navOn, {
  166. page: this.page,
  167. limit: this.limit
  168. }).then(res => {
  169. that.loading = false;
  170. uni.hideLoading();
  171. that.couponsList = that.couponsList.concat(res.data);
  172. that.finished = res.data.length < that.limit;
  173. that.page += 1;
  174. }).catch(err => {
  175. that.loading = false;
  176. uni.showToast({
  177. title: err,
  178. icon: 'none'
  179. });
  180. });
  181. }
  182. }
  183. }
  184. </script>
  185. <style>
  186. .money {
  187. display: flex;
  188. flex-direction: column;
  189. justify-content: center;
  190. }
  191. .pic-num {
  192. color: #ffffff;
  193. font-size: 24rpx;
  194. }
  195. .coupon-list .item .text .condition {
  196. display: flex;
  197. align-items: center;
  198. }
  199. .coupon-list .item .text .condition .name {
  200. font-size: 26rpx;
  201. font-weight: 500;
  202. display: flex;
  203. align-items: center;
  204. }
  205. .coupon-list .item .text .condition .pic {
  206. width: 30rpx;
  207. height: 30rpx;
  208. display: block;
  209. margin-right: 10rpx;
  210. display: inline-block;
  211. vertical-align: middle;
  212. }
  213. .condition .line-title {
  214. /* width: 70rpx; */
  215. height: 32rpx !important;
  216. padding: 0 5px;
  217. line-height: 30rpx;
  218. text-align: center;
  219. box-sizing: border-box;
  220. background: rgba(255, 247, 247, 1);
  221. border: 1px solid var(--view-theme);
  222. opacity: 1;
  223. border-radius: 20rpx;
  224. font-size: 18rpx !important;
  225. color: var(--view-theme);
  226. margin-right: 12rpx;
  227. text-align: center;
  228. display: inline-block;
  229. vertical-align: middle;
  230. }
  231. .condition .line-title.bg-color-huic {
  232. border-color: #BBB !important;
  233. color: #bbb !important;
  234. background-color: #F5F5F5 !important;
  235. }
  236. </style>
  237. <style lang="scss" scoped>
  238. .navbar {
  239. position: fixed;
  240. top: 0;
  241. left: 0;
  242. width: 100%;
  243. height: 90rpx;
  244. background-color: #FFFFFF;
  245. z-index: 9;
  246. .item {
  247. border-top: 5rpx solid transparent;
  248. border-bottom: 5rpx solid transparent;
  249. font-size: 30rpx;
  250. color: #999999;
  251. &.on {
  252. border-bottom-color: var(--view-theme);
  253. color: #282828;
  254. }
  255. }
  256. }
  257. .coupon-list {
  258. margin-top: 122rpx;
  259. }
  260. .noCommodity {
  261. margin-top: 300rpx;
  262. }
  263. </style>