index.vue 6.6 KB

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