// 首页数据 import Vue from 'vue' import { mapState,mapMutations} from 'vuex' import authorize from '@/common/config/authorize.js' const homeMiXins = { data() { return { userID: 0, clubId: 0, clubStatus: '', current: 0, mode: 'round', isLogin: false, skeletonShow: true, userIdentity: 0, isRequest: false, isNavRequest: false, isLiveRequest: false, isActivityBean: false, beansType: 1, beanNumber: 50, couponEntry: 2, autoplay: true, isScroll: false, suid: 0, // 协销id options: {}, // 分享数据 bankInfo:{}, flootData: [], // 楼层 bannerImageList: [], // 轮播 centerImage: [], // 优惠弹窗 navBarsList: [], // 导航分类 shortcutList: [], // 快捷运营 newsList: [], // 公告 templateData: {}, hotListPageFloor: [], // 新品橱窗 pageList: [], // 楼层 supplierObj: [], // 供应商列表 recommendProducts:[],//推荐商品列表 centerImageShow:false, } }, computed: { ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity', 'isWxAuthorize']) }, methods: { ...mapMutations(['login', 'logout','updateNoticeNum','updateRossShow']), async GetWxAuthorize() { const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过 const getUserInfo = await authorize.getUserInfo('weixin') this.UserService.UserLoginAuthApplets({ code: wechatCode, encryptedData: getUserInfo.encryptedData, iv: getUserInfo.iv }) .then(response => { this.isLogin = true this.userID = response.data.userId this.clubId = response.data.clubId this.userIdentity = response.data.userIdentity this.clubStatus = response.data.clubStatus this.$store.commit('updateStatus', response.data) this.login(response.data) uni.setStorageSync('token', response.data.token) uni.setStorageSync('unionId', response.data.unionId) if (response.data.userIdentity == 1) { this.$api.redirectTo('/pages/seller/index/index') } else if (response.data.userIdentity === 3) { this.$api.redirectTo('/pages/supplier/index/index') } this.updateRossShow() this.GetInitBeansInfo() this.getHomeInformation() }) .catch(error => { this.isLogin = false this.logout() uni.setStorageSync('unionId', error.data.unionId) this.$store.commit('updateStatus', error.data) this.updateRossShow() this.getHomeInformation() }) }, GetHomeTopDataInfo() { //直播、活动、文章模块 this.CommonService.GetHomeTopDataInfo({ source: 2 }) .then(response => { this.templateData = response.data this.isLiveRequest = true }) .catch(error => { this.$util.msg(error.msg, 2000) }) }, GetHomeFloorInfo() { //初始化首页楼层数据 this.CommonService.GetHomeDataInfo({ userId: this.userID, source: 2 }) .then(response => { let data = response.data this.pageList = data.zones this.hotListPageFloor = data.pageFloorList this.supplierObj = data.supplierImage this.recommendProducts = data.recommendProducts setTimeout(() => { this.isRequest = true }, 500) }) .catch(error => { this.$util.msg(error.msg, 2000) }) }, GetInitBeansInfo() { //初始化采美豆信息 this.UserService.GetHomeObtainBeans({ userId: this.userID }) .then(response => { this.beansType = response.data.beansType this.beanNumber = response.data.num this.isActivityBean = true }) .catch(error => { console.log('用户暂无采美豆推送~') }) }, getHomeInformation() { //初始化首页数据 this.CommonService.GetHomeModulesDataInfo({ source: 2 }) .then(res => { let data = res.data this.bannerImageList = data.bannerList this.mallPageModules = data.mallPageModules this.skeletonShow = false this.navBarsList = data.topMenuList this.couponEntry = data.couponEntry this.newsList = data.annlist this.shortcutList = data.shortcutList || [] // 快捷运营 if (!this.hasLogin && this.couponEntry === 1) { this.$store.commit('updateCouponEntry', data.couponEntry) if (uni.getStorageSync('isActivitySwitch')) { this.$store.commit('setActivity', false) } else { this.$store.commit('setActivity', true) } } if(data.centerImage && data.centerImage.length > 0){ this.centerImage = data.centerImage // 获取当前日期的字符串表示(YYYY-MM-DD) const currentDate = new Date().toISOString().split('T')[0] console.log('currentDate',currentDate) // 从localStorage获取上次显示弹窗的日期 const lastPopupDate = uni.getStorageSync('lastPopupDate') console.log('lastPopupDate',lastPopupDate) // 检查今天是否已经显示过弹窗 if (lastPopupDate !== currentDate) { // 显示弹窗和遮罩层 this.centerImageShow = true } } this.GetHomeTopDataInfo() this.GetHomeFloorInfo() if (this.hasLogin) { this.initShoppingCartCount() this.updateNoticeNum() } this.isNavRequest = true }) .catch(error => { this.$util.msg(error.msg, 2000) }) }, initShoppingCartCount() { // 获取购物车数量 this.OrderService.ShoppingCartCount({ userId: this.userID }).then(res => { this.$store.commit('updateAllNum', res.data) }) }, handleClick(data) { const pageId = 306 this.$api.navigateTo('/pages/user/coupon/coupon-collection') this.$store.commit('setActivity', data) uni.setStorageSync('lockTime', Date.now()) uni.setStorageSync('isActivitySwitch', true) // 友盟自定义事件 // if(process.env.NODE_ENV != 'development'){ // this.$uma.trackEvent('meibohui_click', { // Um_Key_PageName: '美博会', // Um_Key_PageCategory: '活动专题页面', // Um_Key_SourcePage: '首页', // }) // } }, handleCancelClick(data) { this.$store.commit('setActivity', data) uni.setStorageSync('lockTime', Date.now()) uni.setStorageSync('isActivitySwitch', true) }, // 关闭广告弹窗 handleCenterImageCancelClick(){ const currentDate = new Date().toISOString().split('T')[0] console.log('currentDate',currentDate) // 更新localStorage中的上次显示弹窗的日期 uni.setStorageSync('lastPopupDate', currentDate) this.centerImageShow = false }, // 广告弹窗跳转 handleCenterImageClick(item){ this.$api.FlooryNavigateTo(item) }, handleBeanlClick() { this.isActivityBean = false }, } } export default homeMiXins