public.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. window.onload=function(){
  2. //导航
  3. if($('.carousel-inner div').length<=1){
  4. $('#myCarousel').removeClass('slide');
  5. }
  6. //百度统计图片处理
  7. navTop()
  8. //导航
  9. function navTop() {
  10. $(window).scroll(function(){
  11. var scrolltop=$(document).scrollTop();
  12. if(scrolltop>0){
  13. $('.topNav').addClass('navFix')
  14. }else{
  15. $('.topNav').removeClass('navFix');
  16. }
  17. });
  18. }
  19. $(".index_blur").html("×");
  20. $(".pub_fix").after("<div class='right_cebian'>侧边导航</div>");
  21. $(".index_blur").click(function(){
  22. $(".pub_fix").animate({right:"-70px"},"fast",function(){
  23. $(".right_cebian").show("fast");
  24. });
  25. });
  26. $(".right_cebian").click(function(){
  27. $(".right_cebian").hide("fast");
  28. $(".pub_fix").animate({right:"20px"},"fast",function(){
  29. });
  30. });
  31. //二级导航
  32. $('.nav ul li').mouseenter(function(){
  33. $(this).find('.subnavigation').slideDown(100);
  34. });
  35. $('.nav ul li').mouseleave(function(){
  36. $(this).find('.subnavigation').slideUp(100);
  37. $('.nav ul li').stop(false,true);
  38. });
  39. //挂件
  40. $(window).scroll(function(){
  41. // 滚动条距离顶部的距离 大于 200px时
  42. if($(window).scrollTop() >= 200){
  43. $('.pub_fix ul li:eq(0)').addClass('active'); // 开始淡入
  44. } else{
  45. $('.pub_fix ul li:eq(0)').removeClass('active'); // 如果小于等于 200 淡出
  46. }
  47. });
  48. $('.pendent_box').click(function(e){
  49. e.preventDefault();
  50. $("body,html").animate({scrollTop:0},500)
  51. });
  52. //登陆页面
  53. var hht=$(window).height();
  54. $('.login').height(hht);
  55. //点击x
  56. $('.log_del').click(function(){
  57. $('#Lo_user').val('');
  58. $('#Lo_user').focus();
  59. $('#Lo_user').css({color:'#333333'});
  60. })
  61. // 登陆事件
  62. $('.head_login').click(function(e){
  63. e.preventDefault();
  64. $('.login').fadeIn(800)
  65. $('#form_register').fadeOut(800)
  66. })
  67. $('.login_close').click(function(){
  68. let urlHref = window.location.href;
  69. if(urlHref.indexOf('signIn')>-1){
  70. $('.login').fadeOut(800)
  71. $('#form_register').fadeIn(800)
  72. window.location.reload();
  73. }else{
  74. $('.login').fadeOut(800)
  75. $('#form_register').fadeIn(800)
  76. $('.login_right>div').removeClass('active')
  77. }
  78. })
  79. //登录调用;
  80. function loginBegin(type){
  81. let hrefs=window.location.href,jump=window.location.hash,jumpState=false,
  82. urls = hrefs.split('/').pop();
  83. if(urls=='evaluate'||urls=='shopList'||jump=='#jump'){
  84. jumpState=true;
  85. }
  86. $('.loading').show();
  87. let txt = "登录中,请稍后...",htmls=[],
  88. txtArr = txt.split('');
  89. txtArr.map(item=>{
  90. htmls.push(`
  91. <span>${item}</span>
  92. `)
  93. });
  94. $('.loading div p').html(htmls);
  95. $.ajax({
  96. method: "POST",
  97. dataType: "json",
  98. url: globalConfig.context + "/signin",
  99. data: {
  100. "mobile": $('#Lo_user').val(),
  101. "password": $('#Lo_pass').val(),
  102. 'type':type
  103. },
  104. success: function (rest) {
  105. $('.loading').hide();
  106. if (rest.error && rest.error.length) {
  107. msg(rest.error[0].message);
  108. } else {
  109. var data = rest.data;
  110. if (data && data.requestURI) {
  111. var path = globalConfig.context + data.requestURI;
  112. if (data.queryString) {
  113. path += '?' + data.queryString;
  114. }
  115. if (window.location.hash) {
  116. path += window.location.hash;
  117. }
  118. window.location.href = path;
  119. } else {
  120. if(!jumpState){
  121. msg('登录成功,2秒后跳转个人中心');
  122. setTimeout(()=>{
  123. window.location.href = globalConfig.context + "/user/account/index.html";
  124. },2000)
  125. }else{
  126. msg('登录成功');
  127. setTimeout(()=>{
  128. window.location.reload();
  129. },1000)
  130. }
  131. }
  132. }
  133. }
  134. })
  135. }
  136. //登录框获得焦点样式处理演示
  137. loginStyle();
  138. function loginStyle(){
  139. $('.loginSelect label').eq(0).addClass('active');
  140. $('.login_uesr input,.login_pass input').focus(function(){
  141. $(this).parent().addClass('active')
  142. })
  143. $('.login_uesr input,.login_pass input').blur(function(){
  144. $(this).parent().removeClass('active')
  145. })
  146. }
  147. $('#form_login').submit(function(e){
  148. e.preventDefault();
  149. var Suser=$('#Lo_user').val();
  150. var Spass=$('#Lo_pass').val();
  151. if(Suser==''||Spass==''){
  152. msg('请填写用户名/密码.');
  153. return false;
  154. }else{
  155. ininUserType(Suser,Spass)
  156. }
  157. })
  158. function ininUserType(user,pass){
  159. $.ajax({
  160. method:'get',
  161. dataType:'json',
  162. url:globalConfig.context+'/open/loginCheck',
  163. data:{
  164. "mobile":user,
  165. "password":pass,
  166. },
  167. success:function(data){
  168. if (data.error && data.error.length) {
  169. msg(data.error[0].message);
  170. return;
  171. }
  172. if(data.data.type!=null){
  173. loginBegin(data.data.type);
  174. }else{
  175. $('.login_right>div').addClass('active')
  176. modelLogin(data.data.id);
  177. }
  178. }
  179. })
  180. }
  181. function modelLogin(ids){
  182. /* 此处做类型选择处理 */
  183. $('.loginSelect label').eq(0).find('input').prop('checked',true);
  184. $('.loginSelect label').eq(0).addClass('active').siblings().removeClass('active');
  185. $('.loginSelect label').click(function(){
  186. let check = $(this).find('input').prop('checked');
  187. if(check){
  188. $(this).addClass('active').parent().siblings().find('label').removeClass('active');
  189. return;
  190. }else{
  191. $(this).removeClass('active').parent().siblings().find('label').addClass('active');
  192. }
  193. })
  194. $('.typeQren').click(function(e){
  195. e.preventDefault();
  196. let typeMode = $('.loginSelect label input:checked').val();
  197. $.ajax({
  198. method:'post',
  199. dataType:'json',
  200. url: globalConfig.context+'/open/updateUser',
  201. data:{
  202. type:typeMode,
  203. id:ids
  204. },
  205. success:function(data){
  206. if(data.error&&data.error.length){
  207. msg(data.error[0].message);
  208. return;
  209. }
  210. loginBegin(typeMode);
  211. }
  212. })
  213. })
  214. }
  215. //提示框渐隐函数
  216. function msg(mess) {
  217. if($('.smg').hasClass('active')){
  218. return ;
  219. }
  220. $('.smg').addClass('active');
  221. $('#msg').val(mess);
  222. setTimeout(function () {
  223. $('.smg').removeClass('active')
  224. $('#msg').val('');
  225. }, 2000)
  226. }
  227. //点击登录界面的忘记密码 ,将会弹出忘记密码界面
  228. $('.login_check .forgetPass').click(function(e){
  229. e.preventDefault();
  230. $('#forget_user').val('');
  231. $('#forget_phone').val('');
  232. $('#photo_n').val('');
  233. $('.login').fadeOut(800);
  234. $('#form_register').fadeOut(800);
  235. $("#forget").fadeIn(800);
  236. });
  237. //点击忘记密码右上角的×,将会关闭界面并清空里面的内容
  238. $('#forget .login_close').click(function(){
  239. $('#forget').fadeOut(800);
  240. $('#form_register').fadeIn(800);
  241. $("#forget_phone").val("");
  242. $("#forget_yanzheng").val("");
  243. $("#photo_n").val("");
  244. });
  245. //点击取消,相当于点击×
  246. $("#forget .fastener_right").click(function(){
  247. $('#forget .login_close').click();
  248. });
  249. //点击重置密码右上角的×,将会关闭界面并清空里面的内容
  250. $('#new_password .login_close').click(function(){
  251. $('#new_password').fadeOut(800)
  252. $('#form_register').fadeIn(800)
  253. });
  254. //点击取消,相当于点击×
  255. $("#new_password .fastener_right").click(function(){
  256. $('#new_password .login_close').click();
  257. });
  258. let use_forget,phone_forget;
  259. //点击忘记密码里面的确认,则发送一个请求,并跳转到重置密码界面
  260. $('#forget_form').submit(function(e){
  261. e.preventDefault();
  262. use_forget = $('#forget_user').val();
  263. phone_forget=$("#forget_phone").val();
  264. var phone_n_forget=$("#photo_n").val();
  265. var type=$(".login_pa>#customerTy").val();
  266. if(!(phone_forget).trim()){
  267. msg('亲,请填写正确的手机号码')
  268. return;
  269. };
  270. if(!(phone_n_forget).trim()){
  271. msg('亲,请填写手机验证码')
  272. return;
  273. };
  274. $.ajax({
  275. type: "POST",
  276. dataType: "json",
  277. url: globalConfig.context + "/open/checkMNCode",
  278. data: {
  279. 'mobile':phone_forget,
  280. 'mobileCode': phone_n_forget,
  281. 'type':type
  282. },
  283. success: function (rest) {
  284. if (rest.error && rest.error.length) {
  285. msg(rest.error[0].message);
  286. } else {
  287. $('#forget').fadeOut(800);
  288. $('#form_register').fadeOut(800);
  289. $("#new_password").fadeIn(800);
  290. $(".password_top>h4").attr("val",rest.data);
  291. $('#new_pass').val();
  292. $('#new_pass_again').val();
  293. }
  294. }
  295. })
  296. });
  297. //点击重置密码里面的确认,则发送一个请求,并关闭重置密码界面
  298. $('#new_password_form').submit(function(e){
  299. e.preventDefault();
  300. var pass_pattern=/^[a-zA-Z0-9]{6,12}$/;
  301. var new_pass=$("#new_pass").val();
  302. var new_pass_again=$("#new_pass_again").val();
  303. var reset_code=$(".password_top>h4").attr("val");
  304. var type=$(".login_pa>#customerTy").val();
  305. if(!new_pass||!new_pass_again){
  306. msg('亲,新旧密码必填!')
  307. return;
  308. }
  309. if(new_pass!==new_pass_again){
  310. msg('亲,两次密码不一致')
  311. return;
  312. }
  313. if(!pass_pattern.test(new_pass)){
  314. msg('亲,密码格式不正确')
  315. return ;
  316. }
  317. $.ajax({
  318. type: "post",
  319. dataType: "json",
  320. url: globalConfig.context + "/open/resetPassword",
  321. data: {
  322. 'type':type,
  323. "newPwd": new_pass,
  324. 'mobile':phone_forget,
  325. 'resetCode':reset_code
  326. },
  327. success: function (rest) {
  328. if (rest.error && rest.error.length) {
  329. msg(rest.error[0].message);
  330. } else {
  331. $('.login').fadeIn(800);
  332. $('#form_register').fadeOut(800);
  333. $("#new_password").fadeOut(800);
  334. msg('修改成功!');
  335. }
  336. }
  337. })
  338. });
  339. //手机号码的验证
  340. function photoyanzheng(){
  341. var pho_pattern=/^1[3|4|5|7|8][0-9]{9}$/;
  342. $("#forget_phone").keyup(function(){
  343. var phol= $(this).val();
  344. if(pho_pattern.test(phol)){
  345. $('#photo_m').attr('disabled', false);
  346. $("#photo_m").css("color","#F18101");
  347. }else if(!pho_pattern.test(phol)){
  348. $('#photo_m').attr('disabled', true);
  349. $("#photo_m").css("color","#ccc");
  350. }
  351. });
  352. $('#forget_phone').blur(function () {
  353. var pho= $(this).val();
  354. if (pho==''||!pho_pattern.test(pho)) {
  355. $(this).val('');
  356. $(this).attr('placeholder', '请输入正确的号码')
  357. } else{
  358. $('#photo_m').attr('disabled', false);
  359. $("#photo_m").css("color","#F18101");
  360. }
  361. })
  362. }
  363. photoyanzheng();
  364. //点击刷新图片验证码
  365. $('.yanzhengma_cont_').click(function () {
  366. $('.yanzhengma_cont_ img').attr('src', (globalConfig.context + "/open/getVCode?t=" + Math.random()))
  367. });
  368. var tt = 30;
  369. $('#photo_m').click(function () {
  370. //手机验证功能
  371. var ophoto = $('#forget_phone').val();
  372. var types = $('#forget_checks').prop("checked") ? '0' : '1';
  373. var phott = $('#forget_yanzheng').val();
  374. //验证码倒计时
  375. $('#photo_m').attr('disabled', true);
  376. $(this).attr('disabled', true);
  377. var timer = setInterval(function () {
  378. tt -= 1;
  379. $('#photo_m').attr('disabled', true);
  380. $(this).val("发送"+'('+tt+'s'+')');
  381. $(this).css({color:'#cccccc'})
  382. if (tt == 0) {
  383. clearInterval(timer);
  384. $('#photo_m').attr('disabled', false);
  385. $(this).attr('disabled', false);
  386. tt=30;
  387. $(this).css({color:'rgb(241, 129, 1)'})
  388. $(this).val('重新发送');
  389. }
  390. }.bind(this), 1000);
  391. $.ajax({
  392. type: "GET",
  393. url: globalConfig.context + "/open/getMCode",
  394. data: {
  395. "mobile": ophoto,
  396. "sign": false,
  397. "verificationCode": phott
  398. },
  399. success: function (data) {
  400. if (data.error && data.error.length) {
  401. msg(data.error[0].message);
  402. } else {
  403. msg('发送成功');
  404. }
  405. return true;
  406. }
  407. });
  408. });
  409. //loading
  410. loading();
  411. function loading(){
  412. clearInterval(setTime)
  413. let txt = "努力加载中...",htmls=[],i=0,
  414. txtArr = txt.split('');
  415. let ps = document.createElement('p');
  416. txtArr.map(item=>{
  417. htmls.push(`
  418. <span>${item}</span>
  419. `)
  420. });
  421. ps.innerHTML=htmls.join('');
  422. $('.loading div').html(ps);
  423. function active(){
  424. i++;
  425. if(i>txtArr.length){
  426. i=0;
  427. };
  428. $('.loading p span').eq(i).addClass('active').siblings().removeClass('active');
  429. }
  430. var setTime =setInterval(()=>{active()},100);
  431. }
  432. //网站导航
  433. $('.navigationList').mouseenter(function(){
  434. $('.navWrapper').slideDown(100)
  435. })
  436. $('.navWrapper').mouseleave(function(){
  437. $('.navWrapper').slideUp(100)
  438. $('.navWrapper').stop(false,true);
  439. })
  440. /* 购物车部分 */
  441. //获取购物车商品位置
  442. tint();
  443. function tint(){
  444. if($('a').hasClass('shopCar')){
  445. let shopH = $('.shopCar').offset().top,
  446. shopCH = $('.shopIcon').offset().top,
  447. shopL = $('.shopCar').offset().left,
  448. shopC = $('.shopIcon').offset().left;
  449. $('.shopIcon .tint').css({'top':(shopH-shopCH)+'px','left':-(shopC-shopL)+'px'})
  450. }
  451. }
  452. //购物车
  453. {
  454. //数量
  455. $('#number').keyup(function(){
  456. if($(this).val()>99){
  457. $(this).val('99');
  458. }
  459. if($(this).val()<1){
  460. $(this).val('1');
  461. }
  462. })
  463. //购物动作
  464. $('.shopIcon .tint').hide();
  465. $('.shopCar').click(function(){
  466. if( $('.shopIcon .tint').hasClass('active')){
  467. return false;
  468. }else{
  469. btnFn();
  470. getLoc();
  471. $('.shopIcon .tint').show();
  472. $('.shopIcon .tint').css({'opacity':1})
  473. $('.shopIcon .tint').addClass('active');
  474. setTimeout(()=>{
  475. $('.shopIcon .tint').removeClass('active');
  476. $('.shopIcon .tint').hide();
  477. },800)
  478. }
  479. })
  480. //本地存储
  481. var shopList = [],
  482. preShop,
  483. state = false;
  484. init();
  485. function init() {
  486. getLoc();
  487. }
  488. //初始判断是否有存储
  489. function getLoc(){
  490. let oldlist = localStorage.getItem('shopList');
  491. if(oldlist){
  492. preShop = JSON.parse(oldlist);
  493. shopList=preShop.data;
  494. let nubTotal =0;
  495. shopList.map(item=>{
  496. nubTotal+=parseInt(item.number)
  497. })
  498. $('.numberTotal').text(nubTotal)
  499. };
  500. };
  501. //点击加入商品
  502. var hash = window.location.search,ids='',idList=[];
  503. if(hash.indexOf('&')){
  504. idList=hash.split('&');
  505. ids=idList[0].split('=')[1];
  506. }else{
  507. ids= hash.split('=')[1];
  508. }
  509. function btnFn() {
  510. //每次点击时获取上次存储的数据累加
  511. getLoc();
  512. state = true;
  513. var name = escape($('.cname').text()), //中文进行编译
  514. id=ids,
  515. companyName=$('.companyName').text(),
  516. type=$('.cname').attr('data'),
  517. img = $('.serviceDetailsImg>img').attr('src'),
  518. number = parseInt($('#number').val()),
  519. type=$('.orderType').attr('type'),
  520. price = $('.price').text();
  521. // 商品信息对象
  522. let pro = new Object();
  523. pro.id = id;
  524. pro.type=type;
  525. pro.name = name;
  526. pro.img = img;
  527. pro.companyName=companyName;
  528. pro.number = number;
  529. pro.price = price;
  530. //初始加入
  531. if(shopList.length < 1) {
  532. shopList.push(pro);
  533. local(shopList)
  534. return;
  535. };
  536. //判断是否重复加入
  537. shopList.map((item, index) => {
  538. if(item.id === ids) {
  539. shopList[index].number = parseInt(shopList[index].number) + parseInt(number);
  540. state = false;
  541. }
  542. });
  543. if(state) {
  544. shopList.push(pro);
  545. };
  546. local(shopList);
  547. };
  548. function local (shopList){
  549. let data=new Object();
  550. data.data=shopList;
  551. let setData = JSON.stringify(data);
  552. //本地存储
  553. localStorage.setItem('shopList',setData);
  554. };
  555. //title处理
  556. titleLen();
  557. function titleLen(){
  558. $('.RecommendTitle h2,.patentTitle h2').mouseenter(function(){
  559. let h2Len = $(this).text(),
  560. lenW = (h2Len.length)*30;
  561. $(this).siblings().css({
  562. width:lenW+'px',
  563. transition: 'all .5s ease-in-out'
  564. })
  565. })
  566. $('.RecommendTitle h2,.patentTitle h2').mouseout(function(){
  567. let h2Len = $(this).text(),
  568. lenW = (h2Len.length)*30;
  569. $(this).siblings().css({
  570. width:'54px'
  571. })
  572. })
  573. }
  574. }
  575. //banner 箭头高度处理
  576. function bannerFun(){
  577. let imgH = $('.carousel-inner div').eq(0).find('img').innerHeight();
  578. $('.carousel-control').css({'height':(imgH)+'px','line-height':(imgH)+'px'})
  579. }
  580. //bannerFun();
  581. };