window.onload=function(){ //导航 if($('.carousel-inner div').length<=1){ $('#myCarousel').removeClass('slide'); } //百度统计图片处理 navTop() //导航 function navTop() { $(window).scroll(function(){ var scrolltop=$(document).scrollTop(); if(scrolltop>0){ $('.topNav').addClass('navFix') }else{ $('.topNav').removeClass('navFix'); } }); } $(".index_blur").html("×"); $(".pub_fix").after("
侧边导航
"); $(".index_blur").click(function(){ $(".pub_fix").animate({right:"-70px"},"fast",function(){ $(".right_cebian").show("fast"); }); }); $(".right_cebian").click(function(){ $(".right_cebian").hide("fast"); $(".pub_fix").animate({right:"20px"},"fast",function(){ }); }); //二级导航 $('.nav ul li').mouseenter(function(){ $(this).find('.subnavigation').slideDown(100); }); $('.nav ul li').mouseleave(function(){ $(this).find('.subnavigation').slideUp(100); $('.nav ul li').stop(false,true); }); //挂件 $(window).scroll(function(){ // 滚动条距离顶部的距离 大于 200px时 if($(window).scrollTop() >= 200){ $('.pub_fix ul li:eq(0)').addClass('active'); // 开始淡入 } else{ $('.pub_fix ul li:eq(0)').removeClass('active'); // 如果小于等于 200 淡出 } }); $('.pendent_box').click(function(e){ e.preventDefault(); $("body,html").animate({scrollTop:0},500) }); //登陆页面 var hht=$(window).height(); $('.login').height(hht); //点击x $('.log_del').click(function(){ $('#Lo_user').val(''); $('#Lo_user').focus(); $('#Lo_user').css({color:'#333333'}); }) // 登陆事件 $('.head_login').click(function(e){ e.preventDefault(); $('.login').fadeIn(800) $('#form_register').fadeOut(800) }) $('.login_close').click(function(){ let urlHref = window.location.href; if(urlHref.indexOf('signIn')>-1){ $('.login').fadeOut(800) $('#form_register').fadeIn(800) $('.zhuce_input input').val(''); $('#protocol').prop('checked', false) $('#protocol').parent().addClass('cheackeds_no').removeClass('cheackeds'); $('.sub').attr('disabled', true); $('.sub').css({ background: '#CCCCCC', border: 'none' }); $('.Tips').removeClass('active'); $('#photo').val('获取验证码') }else{ $('.login').fadeOut(800) $('#form_register').fadeIn(800) $('.login_right>div').removeClass('active') } }) //登录调用; function loginBegin(type){ let hrefs=window.location.href,jump=window.location.hash,jumpState=false, urls = hrefs.split('/').pop(); if(urls=='evaluate'||urls=='shopList'||jump=='#jump'){ jumpState=true; } $('.loading').show(); let txt = "登录中,请稍后...",htmls=[], txtArr = txt.split(''); txtArr.map(item=>{ htmls.push(` ${item} `) }); $('.loading div p').html(htmls); $.ajax({ method: "POST", dataType: "json", url: globalConfig.context + "/signin", data: { "mobile": $('#Lo_user').val(), "password": $('#Lo_pass').val(), 'type':type }, success: function (rest) { $('.loading').hide(); if (rest.error && rest.error.length) { msg(rest.error[0].message); } else { var data = rest.data; if (data && data.requestURI) { var path = globalConfig.context + data.requestURI; if (data.queryString) { path += '?' + data.queryString; } if (window.location.hash) { path += window.location.hash; } window.location.href = path; } else { if(!jumpState){ msg('登录成功,2秒后跳转个人中心'); setTimeout(()=>{ window.location.href = globalConfig.context + "/user/account/index.html"; },2000) }else{ msg('登录成功'); setTimeout(()=>{ window.location.reload(); },1000) } } } } }) } //登录框获得焦点样式处理演示 loginStyle(); function loginStyle(){ $('.loginSelect label').eq(0).addClass('active'); $('.login_uesr input,.login_pass input').focus(function(){ $(this).parent().addClass('active') }) $('.login_uesr input,.login_pass input').blur(function(){ $(this).parent().removeClass('active') }) } $('#form_login').submit(function(e){ e.preventDefault(); var Suser=$('#Lo_user').val(); var Spass=$('#Lo_pass').val(); if(Suser==''||Spass==''){ msg('请填写用户名/密码.'); return false; }else{ ininUserType(Suser,Spass) } }) function ininUserType(user,pass){ $.ajax({ method:'get', dataType:'json', url:globalConfig.context+'/open/loginCheck', data:{ "mobile":user, "password":pass, }, success:function(data){ if (data.error && data.error.length) { msg(data.error[0].message); return; } if(data.data.type!=null){ loginBegin(data.data.type); }else{ $('.login_right>div').addClass('active') modelLogin(data.data.id); } } }) } function modelLogin(ids){ /* 此处做类型选择处理 */ $('.loginSelect label').eq(0).find('input').prop('checked',true); $('.loginSelect label').eq(0).addClass('active').siblings().removeClass('active'); $('.loginSelect label').click(function(){ let check = $(this).find('input').prop('checked'); if(check){ $(this).addClass('active').parent().siblings().find('label').removeClass('active'); return; }else{ $(this).removeClass('active').parent().siblings().find('label').addClass('active'); } }) $('.typeQren').click(function(e){ e.preventDefault(); let typeMode = $('.loginSelect label input:checked').val(); $.ajax({ method:'post', dataType:'json', url: globalConfig.context+'/open/updateUser', data:{ type:typeMode, id:ids }, success:function(data){ if(data.error&&data.error.length){ msg(data.error[0].message); return; } loginBegin(typeMode); } }) }) } //提示框渐隐函数 function msg(mess) { if($('.smg').hasClass('active')){ return ; } $('.smg').addClass('active'); $('#msg').val(mess); setTimeout(function () { $('.smg').removeClass('active') $('#msg').val(''); }, 2000) } //点击登录界面的忘记密码 ,将会弹出忘记密码界面 $('.login_check .forgetPass').click(function(e){ e.preventDefault(); $('#forget_user').val(''); $('#forget_phone').val(''); $('#photo_n').val(''); $('.login').fadeOut(800); $('#form_register').fadeOut(800); $("#forget").fadeIn(800); }); //点击忘记密码右上角的×,将会关闭界面并清空里面的内容 $('#forget .login_close').click(function(){ $('#forget').fadeOut(800); $('#form_register').fadeIn(800); $("#forget_phone").val(""); $("#forget_yanzheng").val(""); $("#photo_n").val(""); }); //点击取消,相当于点击× $("#forget .fastener_right").click(function(){ $('#forget .login_close').click(); }); //点击重置密码右上角的×,将会关闭界面并清空里面的内容 $('#new_password .login_close').click(function(){ $('#new_password').fadeOut(800) $('#form_register').fadeIn(800) }); //点击取消,相当于点击× $("#new_password .fastener_right").click(function(){ $('#new_password .login_close').click(); }); let use_forget,phone_forget; //点击忘记密码里面的确认,则发送一个请求,并跳转到重置密码界面 $('#forget_form').submit(function(e){ e.preventDefault(); use_forget = $('#forget_user').val(); phone_forget=$("#forget_phone").val(); var phone_n_forget=$("#photo_n").val(); var type=$(".login_pa>#customerTy").val(); if(!(phone_forget).trim()){ msg('亲,请填写正确的手机号码') return; }; if(!(phone_n_forget).trim()){ msg('亲,请填写手机验证码') return; }; $.ajax({ type: "POST", dataType: "json", url: globalConfig.context + "/open/checkMNCode", data: { 'mobile':phone_forget, 'mobileCode': phone_n_forget, 'type':type }, success: function (rest) { if (rest.error && rest.error.length) { msg(rest.error[0].message); } else { $('#forget').fadeOut(800); $('#form_register').fadeOut(800); $("#new_password").fadeIn(800); $(".password_top>h4").attr("val",rest.data); $('#new_pass').val(); $('#new_pass_again').val(); } } }) }); //点击重置密码里面的确认,则发送一个请求,并关闭重置密码界面 $('#new_password_form').submit(function(e){ e.preventDefault(); var pass_pattern=/^[a-zA-Z0-9]{6,12}$/; var new_pass=$("#new_pass").val(); var new_pass_again=$("#new_pass_again").val(); var reset_code=$(".password_top>h4").attr("val"); var type=$(".login_pa>#customerTy").val(); if(!new_pass||!new_pass_again){ msg('亲,新旧密码必填!') return; } if(new_pass!==new_pass_again){ msg('亲,两次密码不一致') return; } if(!pass_pattern.test(new_pass)){ msg('亲,密码格式不正确') return ; } $.ajax({ type: "post", dataType: "json", url: globalConfig.context + "/open/resetPassword", data: { 'type':type, "newPwd": new_pass, 'mobile':phone_forget, 'resetCode':reset_code }, success: function (rest) { if (rest.error && rest.error.length) { msg(rest.error[0].message); } else { $('.login').fadeIn(800); $('#form_register').fadeOut(800); $("#new_password").fadeOut(800); msg('修改成功!'); } } }) }); //手机号码的验证 function photoyanzheng(){ var pho_pattern=/^1[3|4|5|7|8][0-9]{9}$/; $("#forget_phone").keyup(function(){ var phol= $(this).val(); if(pho_pattern.test(phol)){ $('#photo_m').attr('disabled', false); $("#photo_m").css("color","#F18101"); }else if(!pho_pattern.test(phol)){ $('#photo_m').attr('disabled', true); $("#photo_m").css("color","#ccc"); } }); $('#forget_phone').blur(function () { var pho= $(this).val(); if (pho==''||!pho_pattern.test(pho)) { $(this).val(''); $(this).attr('placeholder', '请输入正确的号码') } else{ $('#photo_m').attr('disabled', false); $("#photo_m").css("color","#F18101"); } }) } photoyanzheng(); //点击刷新图片验证码 $('.yanzhengma_cont_').click(function () { $('.yanzhengma_cont_ img').attr('src', (globalConfig.context + "/open/getVCode?t=" + Math.random())) }); var tt = 30; $('#photo_m').click(function () { //手机验证功能 var ophoto = $('#forget_phone').val(); var types = $('#forget_checks').prop("checked") ? '0' : '1'; var phott = $('#forget_yanzheng').val(); //验证码倒计时 $('#photo_m').attr('disabled', true); $(this).attr('disabled', true); var timer = setInterval(function () { tt -= 1; $('#photo_m').attr('disabled', true); $(this).val("发送"+'('+tt+'s'+')'); $(this).css({color:'#cccccc'}) if (tt == 0) { clearInterval(timer); $('#photo_m').attr('disabled', false); $(this).attr('disabled', false); tt=30; $(this).css({color:'rgb(241, 129, 1)'}) $(this).val('重新发送'); } }.bind(this), 1000); $.ajax({ type: "GET", url: globalConfig.context + "/open/getMCode", data: { "mobile": ophoto, "sign": false, "verificationCode": phott }, success: function (data) { if (data.error && data.error.length) { msg(data.error[0].message); } else { msg('发送成功'); } return true; } }); }); //loading loading(); function loading(){ clearInterval(setTime) let txt = "努力加载中...",htmls=[],i=0, txtArr = txt.split(''); let ps = document.createElement('p'); txtArr.map(item=>{ htmls.push(` ${item} `) }); ps.innerHTML=htmls.join(''); $('.loading div').html(ps); function active(){ i++; if(i>txtArr.length){ i=0; }; $('.loading p span').eq(i).addClass('active').siblings().removeClass('active'); } var setTime =setInterval(()=>{active()},100); } //网站导航 $('.navigationList').mouseenter(function(){ $('.navWrapper').slideDown(100) }) $('.navWrapper').mouseleave(function(){ $('.navWrapper').slideUp(100) $('.navWrapper').stop(false,true); }) /* 购物车部分 */ //获取购物车商品位置 tint(); function tint(){ if($('a').hasClass('shopCar')){ let shopH = $('.shopCar').offset().top, shopCH = $('.shopIcon').offset().top, shopL = $('.shopCar').offset().left, shopC = $('.shopIcon').offset().left; $('.shopIcon .tint').css({'top':(shopH-shopCH)+'px','left':-(shopC-shopL)+'px'}) } } //购物车 { //数量 $('#number').keyup(function(){ if($(this).val()>99){ $(this).val('99'); } if($(this).val()<1){ $(this).val('1'); } }) //购物动作 $('.shopCar').click(function(){ if( $('.shopIcon .tint').hasClass('active')){ return false; }else{ btnFn(); getLoc(); $('.shopIcon .tint').addClass('active'); setTimeout(()=>{ $('.shopIcon .tint').removeClass('active') },800) } }) //本地存储 var shopList = [], preShop, state = false; init(); function init() { getLoc(); } //初始判断是否有存储 function getLoc(){ let oldlist = localStorage.getItem('shopList'); if(oldlist){ preShop = JSON.parse(oldlist); shopList=preShop.data; let nubTotal =0; shopList.map(item=>{ nubTotal+=parseInt(item.number) }) $('.numberTotal').text(nubTotal) }; }; //点击加入商品 var hash = window.location.search,ids='',idList=[]; if(hash.indexOf('&')){ idList=hash.split('&'); ids=idList[0].split('=')[1]; }else{ ids= hash.split('=')[1]; } function btnFn() { //每次点击时获取上次存储的数据累加 getLoc(); state = true; var name = escape($('.cname').text()), //中文进行编译 id=ids, companyName=$('.companyName').text(), type=$('.cname').attr('data'), img = $('.serviceDetailsImg>img').attr('src'), number = parseInt($('#number').val()), type=$('.orderType').attr('type'), price = $('.price').text(); // 商品信息对象 let pro = new Object(); pro.id = id; pro.type=type; pro.name = name; pro.img = img; pro.companyName=companyName; pro.number = number; pro.price = price; //初始加入 if(shopList.length < 1) { shopList.push(pro); local(shopList) return; }; //判断是否重复加入 shopList.map((item, index) => { if(item.id === ids) { shopList[index].number = parseInt(shopList[index].number) + parseInt(number); state = false; } }); if(state) { shopList.push(pro); }; local(shopList); }; function local (shopList){ let data=new Object(); data.data=shopList; let setData = JSON.stringify(data); //本地存储 localStorage.setItem('shopList',setData); }; //title处理 titleLen(); function titleLen(){ $('.RecommendTitle h2,.patentTitle h2').mouseenter(function(){ let h2Len = $(this).text(), lenW = (h2Len.length)*30; $(this).siblings().css({ width:lenW+'px', transition: 'all .5s ease-in-out' }) }) $('.RecommendTitle h2,.patentTitle h2').mouseout(function(){ let h2Len = $(this).text(), lenW = (h2Len.length)*30; $(this).siblings().css({ width:'54px' }) }) } } //banner 箭头高度处理 function bannerFun(){ let imgH = $('.carousel-inner div').eq(0).find('img').innerHeight(); $('.carousel-control').css({'height':(imgH)+'px','line-height':(imgH)+'px'}) } //bannerFun(); $('.technology .technology_login').click(function() { let loginTxt=$('.head_login')[0]; if(loginTxt&&($(loginTxt).text())=='登录'){ $('.head_login').click(); window.location.hash='jump'; return false; }else{ if(window.adminData&&window.adminData.mobile){ msg('账号不正确,请退出重新登入。') return; } window.location.href= globalConfig.context+'/user/account/index.html#/demand'; } }) };