var homeData = new Vue({ el: '#container', data: { userId:0, asideNav: [], liveList:[],//右侧直播模块 cmImageList:[],//右侧活动模块 infoList:[],//右侧文章模块 popupFlag:false }, filters: { NumFormat: function(value) {//处理金额 return Number(value).toFixed(2); }, }, methods: { // 美博会弹窗链接 popupPage:function(){ this.popupFlag=false; window.location.href='/activity/activityTopic.html?id=306&name=美博会'; localStorage.setItem('lockTime',Date.now()); window.localStorage.setItem('isActivityStatus',true); }, // 关闭美博会弹窗 closePopup:function(){ this.popupFlag=false; $('.Popup').slideUp(100); localStorage.setItem('lockTime',Date.now()); localStorage.setItem('isActivityStatus',true); }, diffTime:function(time){ var date = Date.now(); console.log('缓存时间戳',time); console.log('当前时间戳',date); console.log('计算时间戳',(date-time)); return (date -time) < 2*60*1000 ? false : true }, // 页面主图轮播 swiperBanner: function(){ setTimeout(function(){ if (isPC) { $('#swiper-container').slide({ mainCell:".swiper-wrapper-banner", titCell:".swiper-pagination-banner span", effect: "leftLoop", prevCell:".swiper-button-prev", nextCell:".swiper-button-next", interTime: 3000, autoPlay: true, autoPage: false, trigger: "mouseover" }); } else { var swiper = new Swiper('#swiper-container', { loop : true, autoplay: { delay: 3000, disableOnInteraction: false }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' }, pagination: { el: '.swiper-pagination', clickable :true } }); } },300); }, GetHomeRightData: function(){ var _self = this; PublicApi.GetHomeRightData({ source: 1 },function(response){ if(response.code == 0){ var data = response.data; _self.liveList = data.liveList; _self.cmImageList = data.cmImageList; _self.infoList = data.infoList; }else{ CAIMEI.Alert(response.msg, '确定'); } }); }, setAsideNav: function(){ var _self = this; if (isPC) { var titArr = $('.section_page_title').find('h1'); _self.asideNav = []; for (var i=0; i0) { setTimeout(function(){ height += parent.find(".navItem").height(); parent.css("height",height); },200); } } }, // 设置页面查看更多按钮显示 setReadeMore: function(){ $(".section_page_more").each(function(){ var id = $(this).attr('data-id')*1; var size = $(this).attr('data-size')*1; var el = $(this); var readMore = false; if (isPC) { if([1,3].indexOf(id) !== -1 && size>7) { readMore = true; } if([2,4,7].indexOf(id) !== -1 && size>5) { readMore = true; } if(5 === id && size>10) { readMore = true; } } else { if([1,3].indexOf(id) !== -1 && size>3) { readMore = true; } if([2,4].indexOf(id) !== -1 && size>2) { readMore = true; } if(5 === id && size>4) { readMore = true; } } if (readMore) { el.addClass("show"); } else { el.parents(".section_page").find(".section_page_main").addClass("max"); } }); }, // 点击查看更多 showMoreItem: function(e){ var el = e.currentTarget; $(el).parents(".section_page").find(".section_page_main").addClass("max"); $(el).parents(".section_page_more").hide(); }, // 设置页面商品价格 setPriceShown: function(){ var productIds = []; var userId = GLOBAL_USER_ID; var shopId = GLOBAL_SHOP_ID; var userIdentity = GLOBAL_USER_IDENTITY; $(".main_price_text").each(function(){ var id = $(this).attr('data-id'); if (productIds.indexOf(id) === -1) { productIds .push(id); } }); // 获取商品价格列表 $.getJSON(coreServer+"/commodity/price/list",{ userId: GLOBAL_USER_ID, productIds: productIds.join(',') }).done(function (res) { if (res.code === 0 && res.data) { var priceList = res.data; $(".main_price_none").hide(); $(".price_grade_club").hide(); $(".price_grade_shop").hide(); $(".main_price_login").show(); priceList.map(function(price){ // 用户身份 0、个人 1、协销 2、会员机构 3、供应商 4,普通机构 // priceFlag: 0公开价格 1不公开价格 2仅对会员机构公开 var parent = $(".main_price_text.product_"+ price.productId); var priceFlag = parent.find(".main_price_login").attr('data-id')*1; if (userIdentity===2 || (priceFlag === 0 && userIdentity===4 ) || (userIdentity===3 && shopId === price.shopId*1)) { parent.find(".price_o_num").text(Number(price.originalPrice).toFixed(2)); parent.find(".price_num").text(Number(price.price).toFixed(2)); if(price.promotions && price.promotions.type*1===1 && price.promotions.mode*1===1){ parent.find(".main_price_show").hide(); parent.find(".main_price_show.none").show(); } } else if (userIdentity===4 && priceFlag === 2){ parent.find(".main_price_show").hide(); parent.find(".price_grade_club").show(); } else { parent.find(".main_price_show").hide(); parent.find(".price_grade_shop").show(); } }); } }); } }, created: function() { if(GLOBAL_TOKEN){ this.userId = GLOBAL_USER_ID; } }, mounted: function() { var _this = this; // 页面主图轮播 this.swiperBanner(); // 设置页面查看更多 this.setReadeMore(); // 推荐专区商品轮播 this.swiperFloor(); // 设置右侧导航 this.setAsideNav(); // 获取设置商品价格 if (GLOBAL_USER_ID) { this.setPriceShown(); } // 侧边栏滚动判断 var distance = 0; $(window).scroll(function () { if($('body').attr("style") && $('body').attr("style").indexOf('fixed')>0){ return false; } var scrollSize = Math.max($('html').scrollTop(), $('body').scrollTop()); if(scrollSize >300){ $('#sideNav').show(); if(isPC){ // $('#advertising').show(); // 鼠标滚动楼层 setTimeout(function () { distance = scrollSize; },0); // 侧边导航栏高亮 $('.section_page_title').each(function (i,e) { //每个元素距离顶部的距离 var top = $(e).offset().top; if(scrollSize > distance){ if(scrollSize >= (top-300)){ $('#sideNav').find('a').eq(i).addClass('on').siblings().removeClass("on"); } }else { if(scrollSize >= (top-600)){ $('#sideNav').find('a').eq(i).addClass('on').siblings().removeClass("on"); } } }); // 侧边模块固定 fixed if($('#fixed-wrap').length>0) { var tocWrap = $('#fixed-wrap'), changeSize = $("#globalHead").outerHeight() + $("#swiper-container").outerHeight() + $("#sidebar").outerHeight(); //changeSize = document.getElementById("header").offsetHeight + document.getElementById("sidebar").offsetHeight; scrollSize >= changeSize ? tocWrap.addClass("fixed") : tocWrap.removeClass("fixed"); } } }else { $('#sideNav').hide(); $('#advertising').hide(); } }); // 侧边导航 setTimeout(function(){ $('#sideNav').on("click", 'a[data-id]',function () { var id = $(this).attr('data-id'); var floorScroll = $('.section_page_title [data-id='+id+']').offset().top-200; $('html,body').animate({scrollTop: floorScroll},600); }); },2000); //关闭广告图 $('#advertising').on('click','.close',function () { $(this).parents('.item').hide(); }); var isActivityStatus = localStorage.getItem('isActivityStatus'); //新加优惠券弹窗 if(isActivityStatus){ var lockTime = localStorage.getItem('lockTime'); _this.popupFlag = this.diffTime(lockTime); }else{ setTimeout(function () { _this.popupFlag = true; },1000); } } });