index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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-if="item.applicable_type === 3">品牌券</view>
  27. <view class="line-title acea-row row-center-wrapper" :class="item._type === 0 ? 'bg-color-huic' : 'bg-color-check'"
  28. v-else>商品券</view>
  29. <image src="../../../static/images/fvip.png" class="pic" v-if="item.receive_type===4">
  30. </image>
  31. <text class="title">{{item.coupon_title}}</text>
  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">{{item._msg}}</view>
  37. <view class='bnt bg-color' v-else>{{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. <home v-if="navigation"></home>
  48. <!-- #ifdef MP -->
  49. <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
  50. <!-- #endif -->
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. getUserCoupons
  56. } from '@/api/api.js';
  57. import {
  58. toLogin
  59. } from '@/libs/login.js';
  60. import {
  61. mapGetters
  62. } from "vuex";
  63. import home from '@/components/home';
  64. import colors from '@/mixins/color.js';
  65. import {HTTP_REQUEST_URL} from '@/config/app';
  66. export default {
  67. components: {
  68. home
  69. },
  70. mixins:[colors],
  71. data() {
  72. return {
  73. couponsList: [],
  74. loading: false,
  75. isAuto: false, //没有授权的不会自动授权
  76. isShowAuth: false, //是否隐藏授权
  77. navOn: 1,
  78. page: 1,
  79. limit: 15,
  80. finished: false,
  81. imgHost:HTTP_REQUEST_URL
  82. };
  83. },
  84. computed: mapGetters(['isLogin']),
  85. watch: {
  86. isLogin: {
  87. handler: function(newV, oldV) {
  88. if (newV) {
  89. // #ifdef H5 || APP-PLUS
  90. this.getUseCoupons();
  91. // #endif
  92. }
  93. },
  94. deep: true
  95. }
  96. },
  97. onLoad() {
  98. if (this.isLogin) {
  99. this.getUseCoupons();
  100. } else {
  101. // #ifdef H5 || APP-PLUS
  102. toLogin()
  103. // #endif
  104. // #ifdef MP
  105. this.isShowAuth = true;
  106. // #endif
  107. }
  108. },
  109. onShow() {
  110. uni.removeStorageSync('form_type_cart');
  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. // 通用券
  126. if (item.category_id == 0 && item.product_id == '' && item.brand_id == 0) {
  127. url = '/pages/goods/goods_list/index?title=默认'
  128. }
  129. // 品类券
  130. if (item.category_id != 0) {
  131. if (item.category_type == 1) {
  132. url = '/pages/goods/goods_list/index?cid='+item.category_id+'&title='+item.category_name
  133. }else{
  134. url = '/pages/goods/goods_list/index?sid='+item.category_id+'&title='+item.category_name
  135. }
  136. }
  137. //商品券
  138. if (item.product_id != '') {
  139. let arr = item.product_id.split(',');
  140. let num = arr.length;
  141. if (num == 1) {
  142. url = '/pages/goods_details/index?id='+item.product_id
  143. } else {
  144. url = '/pages/goods/goods_list/index?productId='+item.product_id+'&title=默认'
  145. }
  146. }
  147. //品牌券
  148. if(item.brand_id != 0){
  149. url = '/pages/goods/goods_list/index?brandId='+item.brand_id+'&title=默认'
  150. }
  151. uni.navigateTo({
  152. url: url
  153. });
  154. },
  155. /**
  156. * 授权回调
  157. */
  158. onLoadFun: function() {
  159. this.getUseCoupons();
  160. this.isShowAuth = false;
  161. },
  162. // 授权关闭
  163. authColse: function(e) {
  164. this.isShowAuth = e
  165. },
  166. /**
  167. * 获取领取优惠券列表
  168. */
  169. getUseCoupons: function() {
  170. let that = this;
  171. if (that.loading || that.finished) {
  172. return;
  173. }
  174. that.loading = true;
  175. uni.showLoading({
  176. title: '正在加载…'
  177. });
  178. getUserCoupons(this.navOn, {
  179. page: this.page,
  180. limit: this.limit
  181. }).then(res => {
  182. that.loading = false;
  183. uni.hideLoading();
  184. that.couponsList = that.couponsList.concat(res.data);
  185. that.finished = res.data.length < that.limit;
  186. that.page += 1;
  187. }).catch(err => {
  188. that.loading = false;
  189. uni.showToast({
  190. title: err,
  191. icon: 'none'
  192. });
  193. });
  194. }
  195. }
  196. }
  197. </script>
  198. <style>
  199. .money {
  200. display: flex;
  201. flex-direction: column;
  202. justify-content: center;
  203. }
  204. .pic-num {
  205. color: #ffffff;
  206. font-size: 24rpx;
  207. }
  208. .coupon-list .item .text .condition {
  209. display: flex;
  210. align-items: center;
  211. }
  212. .coupon-list .item .text .condition .name {
  213. font-size: 26rpx;
  214. font-weight: 500;
  215. }
  216. .coupon-list .item .text .condition .pic {
  217. width: 30rpx;
  218. height: 30rpx;
  219. display: block;
  220. margin-right: 10rpx;
  221. display: inline-block;
  222. vertical-align: sub;
  223. }
  224. .condition .line-title {
  225. width: 70rpx;
  226. height: 32rpx !important;
  227. /* #ifndef APP */
  228. line-height: 28rpx;
  229. /* #endif */
  230. /* #ifdef APP */
  231. line-height: 30rpx;
  232. /* #endif */
  233. text-align: center;
  234. box-sizing: border-box;
  235. background: var(--view-minorColorT);
  236. border: 1px solid var(--view-theme);
  237. opacity: 1;
  238. border-radius: 20rpx;
  239. font-size: 18rpx !important;
  240. color: var(--view-theme);
  241. margin-right: 12rpx;
  242. text-align: center;
  243. display: inline-block;
  244. vertical-align: middle;
  245. }
  246. .condition .title{
  247. vertical-align: middle;
  248. }
  249. .condition .line-title.bg-color-huic {
  250. border-color: #BBB !important;
  251. color: #bbb !important;
  252. background-color: #F5F5F5 !important;
  253. }
  254. </style>
  255. <style lang="scss" scoped>
  256. .navbar {
  257. position: fixed;
  258. top: 0;
  259. left: 0;
  260. width: 100%;
  261. height: 106rpx;
  262. background-color: #FFFFFF;
  263. z-index: 9;
  264. .item {
  265. border-top: 5rpx solid transparent;
  266. border-bottom: 5rpx solid transparent;
  267. font-size: 30rpx;
  268. color: #999999;
  269. &.on {
  270. border-bottom-color: var(--view-theme);
  271. color: #282828;
  272. }
  273. }
  274. }
  275. .coupon-list {
  276. margin-top: 122rpx;
  277. }
  278. .noCommodity {
  279. margin-top: 300rpx;
  280. }
  281. </style>