123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- var isFormal = window.location.href.indexOf('www.caimei365.com') !== -1;
- if(isFormal){var _czc = _czc || [];_czc.push(["_setAccount", "1279558759"]);}
- 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; i<titArr.length; i++){
- _self.asideNav.push({
- id: $(titArr[i]).attr("data-id"),
- value: $(titArr[i]).text()
- })
- }
- }
- },
- // 商品楼层轮播
- swiperFloor: function(){
- setTimeout(function(){
- // 商品轮播
- if (isPC) {
- var cell = $(".swiper-pagination-floor");
- var size = Math.ceil(cell.attr("data-id")/5);
- var span = '';
- for (var i = 0; i < size; i++) {
- span += '<span></span>';
- }
- cell.html(span);
- $('#recommendBox').slide({
- mainCell:".recommendBox-wrapper",
- titCell:".swiper-pagination-floor span",
- effect: "leftLoop",
- autoPlay: false,
- scroll:5,
- vis:5
- });
- } else {
- var swiper = new Swiper('#recommendBox', {
- slidesPerView: 2,
- slidesPerColumn: 2,
- spaceBetween:0,
- slidesPerGroup: 2,
- autoplay: {
- delay: 3000,
- disableOnInteraction: false
- },
- pagination: {
- el: '.swiper-pagination'
- }
- });
- }
- // 图片懒加载
- setTimeout(function(){
- $("#recommendBox img[data-original]").lazyload();
- },0)
- },500);
- },
- showSubNav: function(event){
- var el = event.currentTarget;
- var parent = $(el).parent();
- parent.siblings().removeAttr("style").removeClass("on").find(".navItem").hide();
- if (parent.hasClass("on")) {
- parent.removeAttr("style").removeClass("on").find(".navItem").slideUp(200);
- } else {
- var height = parent.height();
- parent.addClass("on").find(".navItem").slideDown(200);
- if (parent.find(".navItem").length>0) {
- 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 (priceFlag===3 || 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();
- }
- // Dom加载后
- this.$nextTick(function(){
- // 图片懒加载
- $("img[data-original]").lazyload();
- });
- // 侧边栏滚动判断
- 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 && $(window).width()>1400) {
- 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');
- // var eTime = this.diffTime(lockTime);
- // _this.showflag = eTime;
- // }else{
- // setTimeout(function () {
- // _this.showflag = true;
- // },1000);
- // }
- }
- });
|