index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. <!-- #ifdef MP -->
  47. <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
  48. <!-- #endif -->
  49. </view>
  50. </template>
  51. <script>
  52. import {
  53. getUserCoupons
  54. } from '@/api/api.js';
  55. import {
  56. toLogin
  57. } from '@/libs/login.js';
  58. import {
  59. mapGetters
  60. } from "vuex";
  61. import home from '@/components/home';
  62. import colors from '@/mixins/color.js';
  63. import {HTTP_REQUEST_URL} from '@/config/app';
  64. export default {
  65. components: {
  66. home
  67. },
  68. mixins:[colors],
  69. data() {
  70. return {
  71. couponsList: [],
  72. loading: false,
  73. isAuto: false, //没有授权的不会自动授权
  74. isShowAuth: false, //是否隐藏授权
  75. navOn: 1,
  76. page: 1,
  77. limit: 15,
  78. finished: false,
  79. imgHost:HTTP_REQUEST_URL
  80. };
  81. },
  82. computed: mapGetters(['isLogin']),
  83. watch: {
  84. isLogin: {
  85. handler: function(newV, oldV) {
  86. if (newV) {
  87. // #ifdef H5 || APP-PLUS
  88. this.getUseCoupons();
  89. // #endif
  90. }
  91. },
  92. deep: true
  93. }
  94. },
  95. onLoad() {
  96. if (this.isLogin) {
  97. this.getUseCoupons();
  98. } else {
  99. // #ifdef H5 || APP-PLUS
  100. toLogin()
  101. // #endif
  102. // #ifdef MP
  103. this.isShowAuth = true;
  104. // #endif
  105. }
  106. },
  107. onShow() {
  108. uni.removeStorageSync('form_type_cart');
  109. },
  110. onReachBottom() {
  111. this.getUseCoupons();
  112. },
  113. methods: {
  114. onNav: function(type) {
  115. this.navOn = type;
  116. this.couponsList = [];
  117. this.page = 1;
  118. this.finished = false;
  119. this.getUseCoupons();
  120. },
  121. useCoupon(item){
  122. let url = '';
  123. if (item.category_id == 0 && item.product_id == '') {
  124. url = '/pages/goods/goods_list/index?title=默认'
  125. }
  126. if (item.category_id != 0) {
  127. if (item.category_type == 1) {
  128. url = '/pages/goods/goods_list/index?cid='+item.category_id+'&title='+item.category_name
  129. }else{
  130. url = '/pages/goods/goods_list/index?sid='+item.category_id+'&title='+item.category_name
  131. }
  132. }
  133. if (item.product_id != '') {
  134. let arr = item.product_id.split(',');
  135. let num = arr.length;
  136. if (num == 1) {
  137. url = '/pages/goods_details/index?id='+item.product_id
  138. } else {
  139. url = '/pages/goods/goods_list/index?productId='+item.product_id+'&title=默认'
  140. }
  141. }
  142. uni.navigateTo({
  143. url: url
  144. });
  145. },
  146. /**
  147. * 授权回调
  148. */
  149. onLoadFun: function() {
  150. this.getUseCoupons();
  151. this.isShowAuth = false;
  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: '正在加载…'
  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 .condition {
  200. display: flex;
  201. align-items: center;
  202. }
  203. .coupon-list .item .text .condition .name {
  204. font-size: 26rpx;
  205. font-weight: 500;
  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: sub;
  214. }
  215. .condition .line-title {
  216. width: 70rpx;
  217. height: 32rpx !important;
  218. text-align: center;
  219. box-sizing: border-box;
  220. background: var(--view-minorColorT);
  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 .title{
  232. vertical-align: middle;
  233. }
  234. .condition .line-title.bg-color-huic {
  235. border-color: #BBB !important;
  236. color: #bbb !important;
  237. background-color: #F5F5F5 !important;
  238. }
  239. </style>
  240. <style lang="scss" scoped>
  241. .navbar {
  242. position: fixed;
  243. top: 0;
  244. left: 0;
  245. width: 100%;
  246. height: 106rpx;
  247. background-color: #FFFFFF;
  248. z-index: 9;
  249. .item {
  250. border-top: 5rpx solid transparent;
  251. border-bottom: 5rpx solid transparent;
  252. font-size: 30rpx;
  253. color: #999999;
  254. &.on {
  255. border-bottom-color: var(--view-theme);
  256. color: #282828;
  257. }
  258. }
  259. }
  260. .coupon-list {
  261. margin-top: 122rpx;
  262. }
  263. .noCommodity {
  264. margin-top: 300rpx;
  265. }
  266. </style>