// 首页数据 import Vue from 'vue' import { mapState,mapMutations} from 'vuex' import authorize from '@/common/config/authorize.js' const homeMiXins = { data() { return { bankInfo:{} } }, 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.homePageFloor this.hotListPageFloor = data.pageFloorList this.supplierObj = data.supplierImage 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 if (!this.hasLogin && this.couponEntry == 1) { if (uni.getStorageSync('isActivitySwitch')) { this.$store.commit('setActivity', false) } else { this.$store.commit('setActivity', true) } } this.GetHomeTopDataInfo() this.GetHomeFloorInfo() if (this.hasLogin) { this.initShoppingCartCount() } 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) }, handleBeanlClick() { this.isActivityBean = false } } } export default homeMiXins