浏览代码

领取优惠券列表接口调用

喻文俊 3 年之前
父节点
当前提交
43c646f628

+ 67 - 101
App.vue

@@ -3,111 +3,75 @@
  * vuex管理登陆状态,具体可以参考官方登陆模板示例
  */
 import Vue from 'vue'
-import { mapState, mapMutations } from 'vuex'
-import authorize from '@/common/authorize.js'
-import wxLogin from '@/services/wxLogin.js'
+import { mapActions, mapMutations } from 'vuex'
 export default {
     onLaunch: function() {
-        let self = this
-        uni.getSystemInfo({
-            success: function(e) {
-                let modelmes = e.model
-                self.$store.commit('app/setWindowHeight', e.windowHeight)
-                // iphone x以上的版本都要控制下巴高度
-                if (/iphone [1|x]\s?/i.test(modelmes)) { 
-                    self.$store.dispatch('app/setVariableFun', true)
-                } else {
-                    self.$store.dispatch('app/setVariableFun', false)
-                }
-                // #ifndef MP
-                Vue.prototype.StatusBar = e.statusBarHeight
-                if (e.platform == 'android') {
-                    Vue.prototype.CustomBar = e.statusBarHeight + 50
-                    Vue.prototype.platformClass = true
-                } else {
-                    Vue.prototype.CustomBar = e.statusBarHeight + 45
-                    Vue.prototype.platformClass = false
-                }
-                // #endif
-
-                // #ifdef MP-WEIXIN || MP-QQ
-                console.log(e.platform)
-                if (e.platform == 'android') {
-                    Vue.prototype.platformClass = 'left'
-                    self.$store.dispatch('app/setVariableFun', false)
-                } else {
-                    Vue.prototype.platformClass = 'center'
-                    self.$store.dispatch('app/setIsIphoneFun', true)
-                }
-                Vue.prototype.StatusBar = e.statusBarHeight
-                Vue.prototype.fontSizeSetting = e.fontSizeSetting
-                Vue.prototype.screenWidth = e.screenWidth
-                let capsule = wx.getMenuButtonBoundingClientRect()
-                Vue.prototype.capsule = capsule
-                if (capsule) {
-                    Vue.prototype.Custom = capsule
-                    // Vue.prototype.capsuleSafe = uni.upx2px(750) - capsule.left + uni.upx2px(750) - capsule.right;
-                    Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight
-                } else {
-                    Vue.prototype.CustomBar = e.statusBarHeight + 50
-                }
-                // #endif
-                // #ifdef MP-ALIPAY
-                Vue.prototype.StatusBar = e.statusBarHeight
-                Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight
-                // #endif
-            }
-        })
-        this.refresh()
-        if (uni.getStorageSync('isActivityStatus')) {
-            const lockTime = uni.getStorageSync('lockTime')
-            const eTime = this.diffTime(lockTime)
-            this.$store.dispatch('app/setActivityFn', eTime)
-        } else {
-            this.$store.dispatch('app/setActivityFn', true)
-        }
+        this.initSystemInfo()
+        // 判断优惠券弹窗是否显示
+        this.checkShowCouponPopup()
     },
     methods: {
-        ...mapMutations('app', ['login', 'logout', 'updateStatus']),
-        async getWxAuthorize() {
-            const wechatCode = await authorize.getCode('weixin')
-            this.UserService.userInfoLogin({
-                code: wechatCode
-            })
-                .then(response => {
-                    this.login(response.data)
-                    this.updateStatus(response.data)
-                })
-                .catch(error => {
-                    uni.setStorage({
-                        //缓存游客用户openid
-                        key: 'openid',
-                        data: error.data.openid
-                    })
-                    this.logout()
-                })
-        },
-        refresh() {
-            let TIME = 20 * 60 * 1000
-            setInterval(() => {
-                authorize
-                    .getSetting()
-                    .then(res => {
-                        // console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
-                        if (res == 1) {
-                            this.getWxAuthorize()
-                        } else {
-                            console.log('授权失败============>:' + '用户取消授权或者未操作')
-                        }
-                    })
-                    .catch(error => {
-                        console.log('授权失败============>:' + '用户授权失败,提醒用户重新授权')
-                    })
-            }, TIME)
+        ...mapActions('app', ['setWindowHeight', 'setVariableFun']),
+        ...mapMutations('coupon', ['setCouponPopupStatus']),
+        ...mapMutations('app', ['setWindowHeight']),
+        // 验证是否需要显示优惠券入口弹窗
+        checkShowCouponPopup() {
+            const couponPopupType = uni.getStorageSync('couponPopupType')
+            const nowDay = new Date().getDay()
+            // 新用户 当天不弹窗
+            if (couponPopupType === nowDay) {
+                this.setCouponPopupStatus(false)
+            }
         },
-        diffTime(t) {
-            let date = Date.now()
-            return date - t < 2 * 60 * 1000 ? false : true
+        initSystemInfo() {
+            let self = this
+            uni.getSystemInfo({
+                success: function(e) {
+                    let modelmes = e.model
+                    self.setWindowHeight(e.windowHeight)
+                    // iphone x以上的版本都要控制下巴高度
+                    if (/iphone [1|x]\s?/i.test(modelmes)) {
+                        self.setVariableFun(true)
+                    } else {
+                        self.setVariableFun(false)
+                    }
+                    // #ifndef MP
+                    Vue.prototype.StatusBar = e.statusBarHeight
+                    if (e.platform == 'android') {
+                        Vue.prototype.CustomBar = e.statusBarHeight + 50
+                        Vue.prototype.platformClass = true
+                    } else {
+                        Vue.prototype.CustomBar = e.statusBarHeight + 45
+                        Vue.prototype.platformClass = false
+                    }
+                    // #endif
+
+                    // #ifdef MP-WEIXIN || MP-QQ
+                    if (e.platform == 'android') {
+                        Vue.prototype.platformClass = 'left'
+                        self.setVariableFun(false)
+                    } else {
+                        Vue.prototype.platformClass = 'center'
+                        self.setVariableFun(true)
+                    }
+                    Vue.prototype.StatusBar = e.statusBarHeight
+                    Vue.prototype.fontSizeSetting = e.fontSizeSetting
+                    Vue.prototype.screenWidth = e.screenWidth
+                    let capsule = wx.getMenuButtonBoundingClientRect()
+                    Vue.prototype.capsule = capsule
+                    if (capsule) {
+                        Vue.prototype.Custom = capsule
+                        Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight
+                    } else {
+                        Vue.prototype.CustomBar = e.statusBarHeight + 50
+                    }
+                    // #endif
+                    // #ifdef MP-ALIPAY
+                    Vue.prototype.StatusBar = e.statusBarHeight
+                    Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight
+                    // #endif
+                }
+            })
         }
     }
 }
@@ -184,5 +148,7 @@ page {
 .placeholder {
     color: #999999;
 }
-.uni-swiper__dots-box{display: none !important;}
+.uni-swiper__dots-box {
+    display: none !important;
+}
 </style>

+ 27 - 0
common/util.js

@@ -45,6 +45,33 @@ export const prePage = () => {
     return prePage.$vm
 }
 
+/** 时间格式化
+ * @param {dateTime} date 标准时间格式 -> new Date()
+ * @param {string} format 时间格式化的格式 'yyyy-MM-dd hh:mm:ss'
+ * @returns {string} 格式化后的时间  '2017-01-01 01:00:00'
+ */
+export const dateFormat = (date = new Date(), format = 'yyyy-MM-dd hh:mm:ss') => {
+    var o = {
+        'M+': date.getMonth() + 1, // month
+        'd+': date.getDate(), // day
+        'h+': date.getHours(), // hour
+        'm+': date.getMinutes(), // minute
+        's+': date.getSeconds(), // second
+        'q+': Math.floor((date.getMonth() + 3) / 3), // quarter
+        S: date.getMilliseconds(), // millisecond
+    }
+    if (/(y+)/.test(format)) {
+        format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
+    }
+    for (var k in o) {
+        if (new RegExp('(' + k + ')').test(format)) {
+            format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k])
+                .length))
+        }
+    }
+    return format
+}
+
 const install = (Vue, vm) => {
     console.log('初始化挂载($util)工具方法 util.js ')
     Vue.prototype.$util = { msg, prePage, modal }

+ 3 - 3
components/cm-module/cm-active-popup/cm-active-popup.vue

@@ -1,7 +1,7 @@
 <template>
     <view class="active-popup" v-if="visible">
         <view class="content">
-            <image :src="image" @click="$emit('click')"></image> <text class="close-btn" @click="handleClose"></text>
+            <image :src="image" @click="$emit('click')" mode="aspectFit"></image> <text class="close-btn" @click="handleClose"></text>
         </view>
     </view>
 </template>
@@ -42,12 +42,12 @@ export default {
     .content {
         position: relative;
         image {
-            width: 440rpx;
+            width: 640rpx;
         }
         .close-btn {
             display: block;
             position: absolute;
-            right: -48rpx;
+            right: 0;
             top: -48rpx;
             width: 48rpx;
             height: 48rpx;

+ 65 - 23
components/cm-module/cm-coupon/cm-coupon.vue

@@ -1,17 +1,31 @@
 <template>
-    <view class="coupon on">
+    <view class="coupon" :class="canUse ? 'on' : 'off'" v-if="couponData">
         <view class="content" :class="[statusIcon, { 'cover-bg': showStatus }]">
             <view class="header">
-                <view class="tag">优惠券标签</view> <view class="price"><text>¥</text>100</view>
-                <view class="tip">满600可用</view>
+                <!-- 优惠券类别 -->
+                <view class="tag">{{ couponData.couponType | formatTag }}</view>
+                <view class="price"><text>¥</text>{{ couponData.couponAmount }}</view>
+                <!-- 使用条件 -->
+                <view class="tip">
+                    <template v-if="couponData.noThresholdFlag === 1">
+                        无门槛
+                    </template>
+                    <template v-else>
+                        满{{ couponData.touchPrice }}可用
+                    </template>
+                </view>
             </view>
             <view class="center desc">
-                <view class="row bold">618全场满600减100</view> <view class="row">全商城商品通用</view>
-                <view class="end-time">截止日期:2021-10-28</view>
+                <!-- 优惠券名称 -->
+                <view class="row bold">{{ couponData.couponName }}</view>
+                <!-- 适用范围 -->
+                <view class="row">{{ couponData.productType | formatUseType }}</view>
+                <!-- 截止日期 -->
+                <view class="end-time">截止日期:{{ couponData.receivePeriod | formatDate }}</view>
             </view>
             <view class="footer">
-                <!-- <view class="btn" @click="handleBtnClick">领取</view> -->
-                <view class="btn plain" @click="handleBtnClick">去使用</view>
+                <view class="btn" @click="handleBtnClick" v-if="couponData.useStatus === 0">领取</view>
+                <view class="btn plain" @click="handleBtnClick" v-if="couponData.useStatus === 1">去使用</view>
             </view>
             <!-- <text class="radio-flag iconfont icon-weixuanze"></text> -->
             <text class="radio-flag iconfont icon-xuanze" v-if="chooseAble" @click="choose"></text>
@@ -20,6 +34,8 @@
 </template>
 
 <script>
+import { dateFormat } from '@/common/util.js'
+import { mapGetters, mapActions } from 'vuex'
 export default {
     props: {
         // 优惠券数据
@@ -49,38 +65,63 @@ export default {
                 5: '好友消费券'
             }
             return tags[val] || '未知券'
+        },
+        // 格式化日期
+        formatDate(val) {
+            return dateFormat(new Date(val), 'yyyy-MM-dd')
+        },
+        // 优惠券使用范围
+        formatUseType(val) {
+            const type = {
+                1: '全商城商品使用',
+                2: '部分商品使用'
+            }
+            return type[val] || '优惠券无法使用'
         }
     },
     computed: {
+        ...mapGetters(['hasLogin']),
         // 优惠券状态图标
         statusIcon() {
             if (!this.couponData) return
             let name = ''
-            switch (this.couponData.flag) {
-                case 1:
-                    name = 'received'
-                    break
-                case 2:
-                    name = 'expired'
-                    break
-                case 3:
-                    name = 'used'
-                    break
-                default:
-                    name = ''
-                    break
+            const type = {
+                0: '', // 未领取
+                1: 'received', //已领取
+                2: 'used', // 已使用
+                3: 'expired' //已失效
             }
-            return name
+            return type[this.couponData.useStatus + 1]
+        },
+        // 优惠券是能否领取和使用
+        canUse() {
+            return ![2, 3].includes(this.couponData.useStatus)
         }
     },
+
     methods: {
+        ...mapActions('coupon', ['receiveCoupon']),
         // 点击勾选按钮
         choose() {
             this.$emit('choose', this.couponData)
         },
         // 按钮点击
         handleBtnClick() {
-            console.log('领取 or 使用')
+            if (!this.hasLogin) return this.$api.navigateTo('/pages/login/login')
+            const clickFns = {
+                0: this.receiveCoupon, // 领取优惠券
+                1: this.useCoupon // 使用优惠券
+            }
+            // 将优惠券id作为参数传递进去
+            clickFns[this.couponData.useStatus](this.couponData.couponId).then(res=>{
+                // 向父组件发送领取优惠券事件
+                this.couponData.useStatus === 0 && this.$emit('btnClick', this.couponData)
+            })
+        },
+        // 使用优惠券
+        useCoupon() {
+            return Promise.resolve()
+            console.log('使用优惠券')
         }
     }
 }
@@ -142,7 +183,7 @@ $coupon-bg-used: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon
     .header {
         align-items: center;
         position: relative;
-        width: 206rpx;
+        width: 204rpx;
         height: 188rpx;
         .tag {
             position: absolute;
@@ -172,6 +213,7 @@ $coupon-bg-used: url(https://static.caimei365.com/app/mini-hehe/icon/icon-coupon
         }
     }
     .center {
+        flex: 1;
         margin-left: 36rpx;
         .row {
             width: 250rpx;

+ 0 - 1
pages/login/login.vue

@@ -49,7 +49,6 @@
 
 <script>
 import authorize from '@/common/authorize.js'
-import wxLogin from '@/services/wxLogin.js'
 import { mapGetters, mapActions  } from 'vuex'
 export default {
     data() {

+ 34 - 7
pages/tabBar/index/index.vue

@@ -41,7 +41,7 @@
             <!-- 活动弹窗 -->
             <cm-active-popup
                 :visible="activePopupVisible"
-                :image="StaticUrl + 'icon-coupons-news.png'"
+                :image="couponActivityIcon"
                 @click="activeClick"
                 @closed="activeClosed"
             ></cm-active-popup>
@@ -82,7 +82,7 @@ export default {
             hasNextPage: false,
             isScrollTop: false,
             isRequest: true,
-            activePopupVisible: false, // 活动弹窗
+            activePopupVisible: true, // 活动弹窗
             tipVisible: true //优惠券领取提示
         }
     },
@@ -90,17 +90,39 @@ export default {
         this.init()
     },
     computed: {
-        ...mapGetters(['hasLogin'])
+        ...mapGetters(['hasLogin', 'activePopupType']),
+        couponActivityIcon() {
+            let icon = 'news'
+            switch (this.activePopupType) {
+                case 1:
+                    icon = 'get'
+                    break
+                case 2:
+                    icon = 'news'
+                    break
+            }
+            return `${this.StaticUrl}icon-coupons-${icon}.png`
+        }
+    },
+    watch: {
+        activePopupType(val) {
+            if (val === 0) return
+            // 定时开启弹窗
+            setTimeout(() => {
+                this.activePopupVisible = true
+            }, 1000)
+        }
     },
     methods: {
+        ...mapMutations('coupon', ['updatePopupType']),
         ...mapActions('user', ['wechatlogin']),
         ...mapActions('cart', ['getCartNumber']),
         // 首页初始化
         async init() {
             this.wechatlogin()
             try {
-                await this.GetHomeBanner()
-                await this.GetHomeProductList()
+                await this.GetHomeBanner() // 轮播图
+                await this.GetHomeProductList() // 楼层
                 this.isRequest = false
             } catch (e) {
                 this.$util.msg(e.msg, 2000)
@@ -126,13 +148,18 @@ export default {
         navToDetailPage(floor) {
             this.$api.navigateTo(`/pages/goods/good-floorMore?floorId=${floor.floorId}&title=${floor.title}`)
         },
+        // 点击了活动弹窗
         activeClick() {
             this.activePopupVisible = false
-            console.log('点击了活动弹窗')
+            this.updatePopupType(0)
+            uni.setStorageSync('couponPopupType', new Date().getDay())
+            this.$api.navigateTo('/pages/user/activity/coupon-find-list')
         },
+        // 活动弹窗关闭
         activeClosed() {
             this.activePopupVisible = false
-            console.log('活动弹窗关闭')
+            this.updatePopupType(this.activePopupType - 1)
+            uni.setStorageSync('couponPopupType', new Date().getDay())
         }
     },
     onPageScroll(e) {

+ 92 - 14
pages/user/activity/coupon-find-list.vue

@@ -1,15 +1,33 @@
 <template>
     <!-- TODO -->
     <view class="coupon-find-list">
-        <!-- 顶部提示 -->
-        <view class="top-tip">
-            <view class="tip-text">如何领取更多优惠券?</view>
-            <view class="tip-btn" @click="popupVisible = true">去了解</view>
-        </view>
-        <!-- 优惠券列表 -->
-        <view class="coupon-list">
-            <cm-coupon :key="i" v-for="i in 3"></cm-coupon>
-        </view>
+        <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
+        <template v-else>
+            <!-- 顶部提示 -->
+            <view class="top-tip" v-if="couponList.length > 0">
+                <view class="tip-text">如何领取更多优惠券?</view>
+                <view class="tip-btn" @click="popupVisible = true">去了解</view>
+            </view>
+            <!-- 优惠券列表 -->
+            <view class="coupon-list">
+                <template v-for="(coupon, index) in couponList">
+                    <cm-coupon :key="index" :couponData="coupon" @btnClick="couponClick"></cm-coupon>
+                </template>
+            </view>
+            <template v-if="couponList.length >= 6">
+                <tui-loadmore :index="3" :visible="loadmore"></tui-loadmore>
+                <tui-nomore :text="loadingText" :visible="!loadmore" backgroundColor="#f7f7f7"></tui-nomore>
+            </template>
+            <!-- 优惠券列表为空 -->
+            <cm-empty
+                v-if="couponList.length <= 0"
+                message="暂无任何优惠券~"
+                :image="baseUrl + 'icon-coupon-empty.png'"
+                :offset="100"
+            ></cm-empty>
+            <!-- 侧边 -->
+            <scroll-top :isScrollTop="isScrollTop" :bottom="160"></scroll-top>
+        </template>
         <!-- 如何获取更多优惠券 -->
         <message-popup @close="closePopup" :visible="popupVisible" class="message-popup">
             <template v-slot:title>
@@ -38,23 +56,74 @@
 <script>
 import MessagePopup from '@/components/message-popup/message-popup.vue'
 import CmCoupon from '@/components/cm-module/cm-coupon/cm-coupon.vue'
+import CmEmpty from '@/components/cm-module/cm-empty/cm-empty.vue'
+import { mapGetters } from 'vuex'
 export default {
     components: {
         MessagePopup,
-        CmCoupon
+        CmCoupon,
+        CmEmpty
     },
     data() {
         return {
-            popupVisible: true
+            baseUrl: this.$Static,
+            popupVisible: false,
+            listQuery: {
+                pageNum: 1,
+                pageSize: 6,
+                userId: ''
+            },
+            couponList: [],
+            hasNextPage: false,
+            total: 0,
+            isScrollTop: false,
+            isRequest: true,
+            loadmore: false, // 正在加载更多
+            timer: null
+        }
+    },
+    computed: {
+        ...mapGetters(['userId']),
+        loadingText() {
+            return this.hasNextPage ? '上拉加载更多' : '没有更多了'
         }
     },
-    computed: {},
-    onLoad() {},
+    onLoad() {
+        this.listQuery.userId = this.userId
+        this.getCouponList()
+    },
     methods: {
         // 关闭信息弹窗
         closePopup() {
             this.popupVisible = false
+        },
+        // 获取待优惠券列表
+        getCouponList() {
+            this.loadmore = true
+            this.CouponService.GetCouponCenterInfo(this.listQuery).then(res => {
+                this.couponList = res.data.list
+                this.hasNextPage = res.data.hasNextPage
+                this.total = res.data.total
+                this.isRequest = false
+                this.listQuery.pageNum++
+                this.loadmore = false
+            })
+        },
+        // 操作优惠券
+        couponClick() {
+            this.getCouponList()
         }
+    },
+    onPageScroll(e) {
+        this.isScrollTop = e.scrollTop > 400
+    },
+    onReachBottom() {
+        if (!this.hasNextPage) return
+        clearTimeout(this.timer)
+        this.timer = setTimeout(() => {
+            console.log('触底了')
+            this.getCouponList()
+        }, 200)
     }
 }
 </script>
@@ -62,8 +131,17 @@ export default {
 <style lang="scss" scoped>
 $tip-height: 80rpx;
 $grid: 24rpx;
-
+.coupon-find-list {
+    min-height: 100%;
+    box-sizing: border-box;
+    padding-top: $tip-height;
+    background: #f7f7f7;
+}
 .top-tip {
+    position: fixed;
+    top: 0;
+    left: 0;
+    z-index: 99;
     display: flex;
     justify-content: space-between;
     align-items: center;

+ 2 - 2
services/config.env.js

@@ -3,8 +3,8 @@ if (process.env.NODE_ENV === 'development') {
     // 开发环境
     // URL_CONFIG = 'http://192.168.2.75:8011'	 //采美测试地址
     // URL_CONFIG = 'http://192.168.2.67:8011'	 //裴裴联调地址
-    // URL_CONFIG = 'http://192.168.2.68:8011'	 //涛涛联调地址
-    URL_CONFIG = 'http://127.0.0.1:8011'	 //涛涛联调地址
+    URL_CONFIG = 'http://192.168.2.68:8011'	 //涛涛联调地址
+    // URL_CONFIG = 'http://127.0.0.1:8011'	 //涛涛联调地址
     // URL_CONFIG = 'https://mall2c-b.caimei365.com'
     // URL_CONFIG = 'https://mall2c.caimei365.com'
 } else {

+ 58 - 0
services/coupon.service.js

@@ -0,0 +1,58 @@
+/**
+ * 这是所有模块公用业务逻辑的服务
+ */
+export default class CouponService {
+    constructor(AjaxService) {
+        Object.assign(this, { AjaxService })
+        this.name = 'CouponService'
+    }
+    // 领券中心
+    GetCouponCenterInfo(data = {}) {
+        return this.AjaxService.get({
+            url: '/coupon/center',
+            data,
+            isLoading: false,
+        })
+    }
+    // 领取优惠券
+    ReceiveCoupon(data = {}) {
+        return this.AjaxService.post({
+            url: '/coupon/collar',
+            data,
+            isLoading: false,
+        })
+
+    }
+    // 首页优惠券弹窗展示
+    CouponActivityPopup(data = {}) {
+        return this.AjaxService.get({
+            url: '/coupon/display',
+            data,
+            isLoading: false,
+        })
+    }
+    // 优惠券部分商品数据
+    ProductInfoByCoupon(data = {}) {
+        return this.AjaxService.get({
+            url: '/coupon/product/page',
+            data,
+            isLoading: false,
+        })
+    }
+    // 统计已领取优惠券数量
+    CouponReceiveCount(data = {}) {
+        return this.AjaxService.get({
+            url: '/coupon/receive/count',
+            data,
+            isLoading: false,
+        })
+    }
+    // 已领取优惠券中心
+    CouponReceiveList(data = {}) {
+        return this.AjaxService.get({
+            url: '/coupon/receive/list',
+            data,
+            isLoading: false,
+        })
+    }
+}

+ 3 - 0
services/index.js

@@ -8,6 +8,7 @@ import ProductService from './product.service'
 import PayService from './pay.service'
 import OrderService from './order.service'
 import PublicService from './public.service.js'
+import CouponService from './coupon.service.js'
 
 export const commonService = new CommonService(ajaxService)
 export const locateService = new LocateService(ajaxService)
@@ -16,6 +17,7 @@ export const productService = new ProductService(ajaxService)
 export const payService = new PayService(ajaxService)
 export const orderService = new OrderService(ajaxService)
 export const publicService = new PublicService(ajaxService)
+export const couponService = new CouponService(ajaxService)
 
 const install = (Vue) => {
     console.log('初始化挂载接口方法')
@@ -27,6 +29,7 @@ const install = (Vue) => {
     Vue.prototype.PayService = payService
     Vue.prototype.OrderService = orderService
     Vue.prototype.PublicService = publicService
+    Vue.prototype.CouponService = couponService
 }
 
 export default install

+ 0 - 3
services/locate.service.js

@@ -68,8 +68,5 @@ export default class LocateService {
         // 获取城市名
         let cityInfo = await this.getCityName(latitude, longitude)
         const { location = {}, cityName, address } = cityInfo
-        console.log(location)
-        console.log(cityName)
-        console.log(address)
     }
 }

+ 2 - 0
store/getters.js

@@ -16,6 +16,8 @@ const getters = {
     goodsList: state => state.cart.goodsList,
     isEmpty: state => state.cart.isEmpty,
     cartIds: state => state.cart.cartIds,
+    // 优惠券
+    activePopupType: state=>state.coupon.activePopupType
 }
 
 export default getters

+ 38 - 3
store/modules/coupon.js

@@ -1,11 +1,15 @@
 /**
  * 用户优惠券仓库
  */
+import { couponService } from '@/services/index.js'
+import { msg as showMsg } from '@/common/util.js'
 
 const state = {
+    showCouponPopup: true, // 是否显示优惠券入口弹窗
     activeCouponList: [], // 未使用
     expiredCouponList: [], // 已过期
-    usedCouponList: [] // 已使用
+    usedCouponList: [], // 已使用
+    activePopupType: 0 // 0 禁用 1 老用户 2 新用户
 }
 const mutations = {
     // 更新未使用优惠券
@@ -19,13 +23,44 @@ const mutations = {
     // 更新已使用优惠券
     updateUsed(state, list) {
         state.usedCouponList = list
+    },
+    // 更新弹窗类型
+    updatePopupType(state, type) {
+        state.activePopupType = type
+    },
+    // 设置优惠券弹窗是否显示
+    setCouponPopupStatus(state, status) {
+        state.showCouponPopup = status
     }
 }
 const actions = {
-    // 查询优惠券
+    // 查询已领取优惠券
     fetchCouponList() {},
     // 领取优惠券
-    receiveCoupon() {}
+    receiveCoupon({ rootGetters }, couponId) {
+        return couponService.ReceiveCoupon({ couponId, userId: rootGetters.userId }).then(res => {
+            showMsg('领取成功', 1500, false, 'success')
+        }).catch(error => {
+            showMsg(error.msg, 2000)
+        })
+    },
+    // 优惠券活动弹窗信息
+    getCouponActivity({ commit, rootGetters, state }) {
+        if (!state.showCouponPopup) return
+        couponService.CouponActivityPopup({
+            userId: rootGetters.userId
+        }).then(response => {
+            const { newUserCouponFlag, actCouponFlag } = response.data
+            // 全部用户弹窗
+            if (actCouponFlag !== 0) {
+                commit('updatePopupType', 1)
+            }
+            // 是否是新用户
+            if (newUserCouponFlag !== 0) {
+                commit('updatePopupType', 2)
+            }
+        })
+    }
 }
 export default {
     namespaced: true,

+ 9 - 3
store/modules/user.js

@@ -39,19 +39,25 @@ const actions = {
         const code = await authorize.getCode('weixin')
         userService.UserWechatAuthorLogin({ code })
             .then(response => {
+                console.log('登录成功')
                 commit('LOGIN', response.data)
-                dispatch('cart/getCartNumber', state.userId, { root: true })
+                dispatch('cart/getCartNumber', state.userId, { root: true }) // 获取购物车数量信息
+                dispatch('coupon/getCouponActivity', null, { root: true }) // 获取优惠券弹窗信息
             })
             .catch(error => {
+                console.log('游客')
+                dispatch('coupon/getCouponActivity', null, { root: true }) // 游客也要获取优惠券弹窗信息
                 commit('LOGIN_OUT', error.data)
             })
-    },
+    }, 
     // 手机号注册登录
-    async customLogin({ commit }, params) {
+    customLogin({ commit, state, dispatch }, params) {
         userService.UserMobileLogin(params)
             .then(response => {
                 // 保存用户信息
                 commit('LOGIN', response.data)
+                dispatch('cart/getCartNumber', state.userId, { root: true }) // 获取购物车数量信息
+                dispatch('coupon/getCouponActivity', null, { root: true }) // 获取优惠券弹窗信息
                 // 登录成功提示
                 showMsg('登录成功', 1500, false, 'success')
                 setTimeout(() => {