$(function(){ //导航 $(".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(){ $('.login').fadeOut(800) $('#form_register').fadeIn(800) }) $('#form_login').submit(function(e){ e.preventDefault(); var Suser=$('#Lo_user').val(); var Spass=$('#Lo_pass').val(); var check_experts=$('#checks').prop('checked'); if(Suser==''||Spass==''){ msg('请填写用户名/密码.'); return false; }else{ $('.loading').show(); let txt = "登录中,请稍后...",htmls=[],i=0, txtArr = txt.split(''); txtArr.map(item=>{ htmls.push(` ${item} `) }); $('.loading div p').html(htmls); $.ajax({ method: "POST", dataType: "json", url: globalConfig.context + "/signin", data: { "username": Suser, "password": Spass, 'type':'0' }, 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 { msg('登录成功,2秒后跳转个人中心'); setTimeout(()=>{ window.location.href = globalConfig.context + "/user/account/index.html"; },2000) } } } }) } }) //提示框渐隐函数 function msg(mess) { if($('.smg').hasClass('active')){ return ; } $('.smg').addClass('active'); $('#msg').val(mess); setTimeout(function () { $('.smg').removeClass('active') $('#msg').val(''); }, 2000) } // //在线客服 // (function(m, ei, q, i, a, j, s) { // m[i] = m[i] || function() { // (m[i].a = m[i].a || []).push(arguments) // }; // j = ei.createElement(q), // s = ei.getElementsByTagName(q)[0]; // j.async = true; // j.charset = 'UTF-8'; // j.src = 'https://static.meiqia.com/dist/meiqia.js?_=t'; // s.parentNode.insertBefore(j, s); // })(window, document, 'script', '_MEIQIA'); // _MEIQIA('entId', 77931); // _MEIQIA('withoutBtn'); //点击登录界面的忘记密码 ,将会弹出忘记密码界面 $('.login_check a').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(); if(!(use_forget).trim()){ msg('亲,请填写用户名') return; }; if(!(phone_forget).trim()){ msg('亲,请填写正确的手机号码') return; }; if(!(phone_n_forget).trim()){ msg('亲,请填写手机验证码') return; }; $.ajax({ type: "POST", dataType: "json", url: globalConfig.context + "/open/checkMNCode", data: { 'userName': use_forget, 'mobile':phone_forget, 'mobileCode': phone_n_forget }, 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"); 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: { 'userName':use_forget, "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, "type": types, "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'); } }) //购物动作 $('.shopIcon .tint').hide(); $('.shopCar').click(function(){ if( $('.shopIcon .tint').hasClass('active')){ return false; }else{ btnFn(); getLoc(); $('.shopIcon .tint').show(); $('.shopIcon .tint').css({'opacity':1}) $('.shopIcon .tint').addClass('active'); setTimeout(()=>{ $('.shopIcon .tint').removeClass('active'); $('.shopIcon .tint').hide(); },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' }) }) } } });