123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- var homeData = new Vue({
- el: '#container',
- data: {
- userId:0,
- images: [],
- listLoading:true,
- advertising: [],
- asideNav: [],
- productIdArr:[],
- liveList:[],//右侧直播模块
- cmImageList:[],//右侧活动模块
- infoList:[],//右侧文章模块
- pageList:[],//左侧楼层
- supplierImage:'',//供应商banner
- supplierWwwLink:'',//供应商banner 链接
- supplierList:[],//供应商列表
- topMenuList:[],
- showflag:false,
- },
- filters: {
- statusType:function(value) {
- switch (value) {
- case 1:
- return '未开始';
- break;
- case 2:
- return '直播中';
- break;
- case 3:
- return '看回放';
- break;
- }
- },
- statusTypeClass:function(value) {
- switch (value) {
- case 1:
- return 'icon-wart';
- break;
- case 2:
- return 'icon-live';
- break;
- case 3:
- return 'icon-end';
- break;
- }
- },
- NumFormat:function(value) {//处理金额
- return Number(value).toFixed(2);
- },
- },
- methods: {
- zhuanti:function(){
- this.showflag=false;
- window.location.href='/product/beautytopic.html';
- localStorage.setItem('lockTime',Date.now());
- window.localStorage.setItem('isActivityStatus',true);
- },
- closepopup:function(){
- this.showflag=false;
- $('.Popup').slideUp(100);
- localStorage.setItem('lockTime',Date.now());
- localStorage.setItem('isActivityStatus',true);
- },
- GetBanners: function(){
- var _self = this;
- PublicApi.GetHomeBanner({},function(response){
- if(response.code == 0){
- _self.images = response.data;
- _self.listLoading =false;
- _self.SwiperBanner();
- }else{
- CAIMEI.Alert(response.msg, '确定');
- }
- });
- },
- 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);
- },
- GetNavigationMenu :function(){//获取顶部导航分类
- var _self = this;
- PublicApi.GetNavigationMenu({source:1},function(response){
- if(response.code == 0){
- _self.topMenuList = response.data.topMenuList;
- }else{
- CAIMEI.Alert(response.msg, '确定');
- }
- });
- },
- GetHomeFloorData: function(){
- var _self = this;
- PublicApi.GetHomeData({userId:GLOBAL_USER_ID,source:1},function(response){
- if(response.code == 0){
- var data = response.data;
- // var floorList = [];
- _self.pageList = data.homePageFloor;
- _self.liveList = data.liveList;
- _self.supplierList = data.supplierImage.qualitySupplierList;
- _self.supplierImage = data.supplierImage.wwwImage;
- _self.supplierWwwLink = data.supplierImage.wwwLink;
- _self.pageList.forEach(function(page){
- if(page.floorContent){
- if(isPC){
- if(page.floorContent.templateType == '1' || page.floorContent.templateType == '3'){
- if (page.floorImageList.length>7){
- page.isPageMore = true;
- }
- }else if(page.floorContent.templateType == '2' || page.floorContent.templateType == '4' || page.floorContent.templateType == '7'){
- if (page.floorImageList.length>5){
- page.isPageMore = true;
- }
- }else if(page.floorContent.templateType == '5'){
- if (page.floorImageList.length>10){
- page.isPageMore = true;
- }
- }
- }else{
- if(page.floorContent.templateType == '1' || page.floorContent.templateType == '3'){
- if (page.floorImageList.length>3){
- page.isPageMore = true;
- }
- }else if(page.floorContent.templateType == '2' || page.floorContent.templateType == '4'){
- if (page.floorImageList.length>2){
- page.isPageMore = true;
- }
- }else if(page.floorContent.templateType == '5'){
- if (page.floorImageList.length>4){
- page.isPageMore = true;
- }
- }
- }
- }
- });
- console.log(_self.pageList)
- _self.GetHomeRightData();
- setTimeout(function() {
- // 设置侧边导航数据
- _self.SetAsideNav();
- _self.SwiperFloor();
- },500);
- }else{
- CAIMEI.Alert(response.msg, '确定');
- }
- });
- },
- 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, '确定');
- }
- });
- },
- PromotionsFormat:function(promo){//促销活动类型数据处理
- if(promo!=null){
- if(promo.type == 1 && promo.mode == 1){
- return true
- }else{
- return false
- }
- }
- return false
- },
- showMorePageFn:function(page){
- page.isPageMore = !page.isPageMore;
- },
- getAdvertising: function(){
- var _self = this;
- $.getJSON("/home/advertising").done(function (r) {
- if (r.code === 0 && r.data) {
- _self.advertising = r.data;
- }
- });
- },
- SetAsideNav: function(){
- var _self = this;
- var titArr = $('.section_page_title').find('h1');
- 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(){ // 图片懒加载
- $("img[data-original]").lazyload();
- },500);
- setTimeout(function(){
- if (isPC) {
- $('#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'
- }
- });
- }
- },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);
- }
- }
- },
- 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
- }
- },
- created: function() {
- var userInfo = localStorage.getItem('userInfo');
- if(userInfo){
- this.userId = JSON.parse(userInfo).userId;
- }
- this.GetBanners();
- this.GetNavigationMenu();
- this.GetHomeFloorData();
- },
- mounted: function() {
- var _this = this;
- // this.getAdvertising();
- // 侧边栏滚动判断
- var distance = 0;
- $(window).scroll(function () {
- if($('body').attr("style") && $('body').attr("style").indexOf('fixed')>0){
- return false;
- }
- var scoll = Math.max($('html').scrollTop(), $('body').scrollTop());
- if(scoll >300){
- $('#sideNav').show();
- if(isPC){
- $('#advertising').show();
- // 鼠标滚动楼层
- setTimeout(function () {
- distance = scoll;
- },0);
- $('.section_page_title').each(function (i,e) {
- //每个元素距离顶部的距离
- var top = $(e).offset().top;
- if(scoll > distance){
- if(scoll >= (top-300)){
- $('#sideNav').find('a').eq(i).addClass('on').siblings().removeClass("on");
- }
- }else {
- if(scoll >= (top-600)){
- $('#sideNav').find('a').eq(i).addClass('on').siblings().removeClass("on");
- }
- }
- });
- }
- }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);
- }
- }
- });
|