public.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. }
  77. })
  78. $('#form_login').submit(function(e){
  79. let hrefs=window.location.href,jump=window.location.hash,jumpState=false,
  80. urls = hrefs.split('/').pop();
  81. if(urls=='evaluate'||urls=='shopList'||jump=='#jump'){
  82. jumpState=true;
  83. }
  84. e.preventDefault();
  85. var Suser=$('#Lo_user').val();
  86. var Spass=$('#Lo_pass').val();
  87. var type=$(".login_pass>#customerType").val();
  88. var check_experts=$('#checks').prop('checked');
  89. if(Suser==''||Spass==''){
  90. msg('请填写用户名/密码.');
  91. return false;
  92. }else{
  93. $('.loading').show();
  94. let txt = "登录中,请稍后...",htmls=[],i=0,
  95. txtArr = txt.split('');
  96. txtArr.map(item=>{
  97. htmls.push(`
  98. <span>${item}</span>
  99. `)
  100. });
  101. $('.loading div p').html(htmls);
  102. $.ajax({
  103. method: "POST",
  104. dataType: "json",
  105. url: globalConfig.context + "/signin",
  106. data: {
  107. "mobile": Suser,
  108. "password": Spass,
  109. 'type':type
  110. },
  111. success: function (rest) {
  112. $('.loading').hide();
  113. if (rest.error && rest.error.length) {
  114. msg(rest.error[0].message);
  115. } else {
  116. var data = rest.data;
  117. if (data && data.requestURI) {
  118. var path = globalConfig.context + data.requestURI;
  119. if (data.queryString) {
  120. path += '?' + data.queryString;
  121. }
  122. if (window.location.hash) {
  123. path += window.location.hash;
  124. }
  125. window.location.href = path;
  126. } else {
  127. if(!jumpState){
  128. msg('登录成功,2秒后跳转个人中心');
  129. setTimeout(()=>{
  130. window.location.href = globalConfig.context + "/user/account/index.html";
  131. },2000)
  132. }else{
  133. msg('登录成功');
  134. setTimeout(()=>{
  135. window.location.reload();
  136. },1000)
  137. }
  138. }
  139. }
  140. }
  141. })
  142. }
  143. })
  144. //提示框渐隐函数
  145. function msg(mess) {
  146. if($('.smg').hasClass('active')){
  147. return ;
  148. }
  149. $('.smg').addClass('active');
  150. $('#msg').val(mess);
  151. setTimeout(function () {
  152. $('.smg').removeClass('active')
  153. $('#msg').val('');
  154. }, 2000)
  155. }
  156. //点击登录界面的忘记密码 ,将会弹出忘记密码界面
  157. $('.login_check a').click(function(e){
  158. e.preventDefault();
  159. $('#forget_user').val('');
  160. $('#forget_phone').val('');
  161. $('#photo_n').val('');
  162. $('.login').fadeOut(800);
  163. $('#form_register').fadeOut(800);
  164. $("#forget").fadeIn(800);
  165. });
  166. //点击忘记密码右上角的×,将会关闭界面并清空里面的内容
  167. $('#forget .login_close').click(function(){
  168. $('#forget').fadeOut(800);
  169. $('#form_register').fadeIn(800);
  170. $("#forget_phone").val("");
  171. $("#forget_yanzheng").val("");
  172. $("#photo_n").val("");
  173. });
  174. //点击取消,相当于点击×
  175. $("#forget .fastener_right").click(function(){
  176. $('#forget .login_close').click();
  177. });
  178. //点击重置密码右上角的×,将会关闭界面并清空里面的内容
  179. $('#new_password .login_close').click(function(){
  180. $('#new_password').fadeOut(800)
  181. $('#form_register').fadeIn(800)
  182. });
  183. //点击取消,相当于点击×
  184. $("#new_password .fastener_right").click(function(){
  185. $('#new_password .login_close').click();
  186. });
  187. let use_forget,phone_forget;
  188. //点击忘记密码里面的确认,则发送一个请求,并跳转到重置密码界面
  189. $('#forget_form').submit(function(e){
  190. e.preventDefault();
  191. use_forget = $('#forget_user').val();
  192. phone_forget=$("#forget_phone").val();
  193. var phone_n_forget=$("#photo_n").val();
  194. var type=$(".login_pa>#customerTy").val();
  195. if(!(phone_forget).trim()){
  196. msg('亲,请填写正确的手机号码')
  197. return;
  198. };
  199. if(!(phone_n_forget).trim()){
  200. msg('亲,请填写手机验证码')
  201. return;
  202. };
  203. $.ajax({
  204. type: "POST",
  205. dataType: "json",
  206. url: globalConfig.context + "/open/checkMNCode",
  207. data: {
  208. 'mobile':phone_forget,
  209. 'mobileCode': phone_n_forget,
  210. 'type':type
  211. },
  212. success: function (rest) {
  213. if (rest.error && rest.error.length) {
  214. msg(rest.error[0].message);
  215. } else {
  216. $('#forget').fadeOut(800);
  217. $('#form_register').fadeOut(800);
  218. $("#new_password").fadeIn(800);
  219. $(".password_top>h4").attr("val",rest.data);
  220. $('#new_pass').val();
  221. $('#new_pass_again').val();
  222. }
  223. }
  224. })
  225. });
  226. //点击重置密码里面的确认,则发送一个请求,并关闭重置密码界面
  227. $('#new_password_form').submit(function(e){
  228. e.preventDefault();
  229. var pass_pattern=/^[a-zA-Z0-9]{6,12}$/;
  230. var new_pass=$("#new_pass").val();
  231. var new_pass_again=$("#new_pass_again").val();
  232. var reset_code=$(".password_top>h4").attr("val");
  233. var type=$(".login_pa>#customerTy").val();
  234. if(!new_pass||!new_pass_again){
  235. msg('亲,新旧密码必填!')
  236. return;
  237. }
  238. if(new_pass!==new_pass_again){
  239. msg('亲,两次密码不一致')
  240. return;
  241. }
  242. if(!pass_pattern.test(new_pass)){
  243. msg('亲,密码格式不正确')
  244. return ;
  245. }
  246. $.ajax({
  247. type: "post",
  248. dataType: "json",
  249. url: globalConfig.context + "/open/resetPassword",
  250. data: {
  251. 'type':type,
  252. "newPwd": new_pass,
  253. 'mobile':phone_forget,
  254. 'resetCode':reset_code
  255. },
  256. success: function (rest) {
  257. if (rest.error && rest.error.length) {
  258. msg(rest.error[0].message);
  259. } else {
  260. $('.login').fadeIn(800);
  261. $('#form_register').fadeOut(800);
  262. $("#new_password").fadeOut(800);
  263. msg('修改成功!');
  264. }
  265. }
  266. })
  267. });
  268. //手机号码的验证
  269. function photoyanzheng(){
  270. var pho_pattern=/^1[3|4|5|7|8][0-9]{9}$/;
  271. $("#forget_phone").keyup(function(){
  272. var phol= $(this).val();
  273. if(pho_pattern.test(phol)){
  274. $('#photo_m').attr('disabled', false);
  275. $("#photo_m").css("color","#F18101");
  276. }else if(!pho_pattern.test(phol)){
  277. $('#photo_m').attr('disabled', true);
  278. $("#photo_m").css("color","#ccc");
  279. }
  280. });
  281. $('#forget_phone').blur(function () {
  282. var pho= $(this).val();
  283. if (pho==''||!pho_pattern.test(pho)) {
  284. $(this).val('');
  285. $(this).attr('placeholder', '请输入正确的号码')
  286. } else{
  287. $('#photo_m').attr('disabled', false);
  288. $("#photo_m").css("color","#F18101");
  289. }
  290. })
  291. }
  292. photoyanzheng();
  293. //点击刷新图片验证码
  294. $('.yanzhengma_cont_').click(function () {
  295. $('.yanzhengma_cont_ img').attr('src', (globalConfig.context + "/open/getVCode?t=" + Math.random()))
  296. });
  297. var tt = 30;
  298. $('#photo_m').click(function () {
  299. //手机验证功能
  300. var ophoto = $('#forget_phone').val();
  301. var types = $('#forget_checks').prop("checked") ? '0' : '1';
  302. var phott = $('#forget_yanzheng').val();
  303. //验证码倒计时
  304. $('#photo_m').attr('disabled', true);
  305. $(this).attr('disabled', true);
  306. var timer = setInterval(function () {
  307. tt -= 1;
  308. $('#photo_m').attr('disabled', true);
  309. $(this).val("发送"+'('+tt+'s'+')');
  310. $(this).css({color:'#cccccc'})
  311. if (tt == 0) {
  312. clearInterval(timer);
  313. $('#photo_m').attr('disabled', false);
  314. $(this).attr('disabled', false);
  315. tt=30;
  316. $(this).css({color:'rgb(241, 129, 1)'})
  317. $(this).val('重新发送');
  318. }
  319. }.bind(this), 1000);
  320. $.ajax({
  321. type: "GET",
  322. url: globalConfig.context + "/open/getMCode",
  323. data: {
  324. "mobile": ophoto,
  325. "sign": false,
  326. "verificationCode": phott
  327. },
  328. success: function (data) {
  329. if (data.error && data.error.length) {
  330. msg(data.error[0].message);
  331. } else {
  332. msg('发送成功');
  333. }
  334. return true;
  335. }
  336. });
  337. });
  338. //loading
  339. loading();
  340. function loading(){
  341. clearInterval(setTime)
  342. let txt = "努力加载中...",htmls=[],i=0,
  343. txtArr = txt.split('');
  344. let ps = document.createElement('p');
  345. txtArr.map(item=>{
  346. htmls.push(`
  347. <span>${item}</span>
  348. `)
  349. });
  350. ps.innerHTML=htmls.join('');
  351. $('.loading div').html(ps);
  352. function active(){
  353. i++;
  354. if(i>txtArr.length){
  355. i=0;
  356. };
  357. $('.loading p span').eq(i).addClass('active').siblings().removeClass('active');
  358. }
  359. var setTime =setInterval(()=>{active()},100);
  360. }
  361. //网站导航
  362. $('.navigationList').mouseenter(function(){
  363. $('.navWrapper').slideDown(100)
  364. })
  365. $('.navWrapper').mouseleave(function(){
  366. $('.navWrapper').slideUp(100)
  367. $('.navWrapper').stop(false,true);
  368. })
  369. /* 购物车部分 */
  370. //获取购物车商品位置
  371. tint();
  372. function tint(){
  373. if($('a').hasClass('shopCar')){
  374. let shopH = $('.shopCar').offset().top,
  375. shopCH = $('.shopIcon').offset().top,
  376. shopL = $('.shopCar').offset().left,
  377. shopC = $('.shopIcon').offset().left;
  378. $('.shopIcon .tint').css({'top':(shopH-shopCH)+'px','left':-(shopC-shopL)+'px'})
  379. }
  380. }
  381. //购物车
  382. {
  383. //数量
  384. $('#number').keyup(function(){
  385. if($(this).val()>99){
  386. $(this).val('99');
  387. }
  388. if($(this).val()<1){
  389. $(this).val('1');
  390. }
  391. })
  392. //购物动作
  393. $('.shopIcon .tint').hide();
  394. $('.shopCar').click(function(){
  395. if( $('.shopIcon .tint').hasClass('active')){
  396. return false;
  397. }else{
  398. btnFn();
  399. getLoc();
  400. $('.shopIcon .tint').show();
  401. $('.shopIcon .tint').css({'opacity':1})
  402. $('.shopIcon .tint').addClass('active');
  403. setTimeout(()=>{
  404. $('.shopIcon .tint').removeClass('active');
  405. $('.shopIcon .tint').hide();
  406. },800)
  407. }
  408. })
  409. //本地存储
  410. var shopList = [],
  411. preShop,
  412. state = false;
  413. init();
  414. function init() {
  415. getLoc();
  416. }
  417. //初始判断是否有存储
  418. function getLoc(){
  419. let oldlist = localStorage.getItem('shopList');
  420. if(oldlist){
  421. preShop = JSON.parse(oldlist);
  422. shopList=preShop.data;
  423. let nubTotal =0;
  424. shopList.map(item=>{
  425. nubTotal+=parseInt(item.number)
  426. })
  427. $('.numberTotal').text(nubTotal)
  428. };
  429. };
  430. //点击加入商品
  431. var hash = window.location.search,ids='',idList=[];
  432. if(hash.indexOf('&')){
  433. idList=hash.split('&');
  434. ids=idList[0].split('=')[1];
  435. }else{
  436. ids= hash.split('=')[1];
  437. }
  438. function btnFn() {
  439. //每次点击时获取上次存储的数据累加
  440. getLoc();
  441. state = true;
  442. var name = escape($('.cname').text()), //中文进行编译
  443. id=ids,
  444. companyName=$('.companyName').text(),
  445. type=$('.cname').attr('data'),
  446. img = $('.serviceDetailsImg>img').attr('src'),
  447. number = parseInt($('#number').val()),
  448. type=$('.orderType').attr('type'),
  449. price = $('.price').text();
  450. // 商品信息对象
  451. let pro = new Object();
  452. pro.id = id;
  453. pro.type=type;
  454. pro.name = name;
  455. pro.img = img;
  456. pro.companyName=companyName;
  457. pro.number = number;
  458. pro.price = price;
  459. //初始加入
  460. if(shopList.length < 1) {
  461. shopList.push(pro);
  462. local(shopList)
  463. return;
  464. };
  465. //判断是否重复加入
  466. shopList.map((item, index) => {
  467. if(item.id === ids) {
  468. shopList[index].number = parseInt(shopList[index].number) + parseInt(number);
  469. state = false;
  470. }
  471. });
  472. if(state) {
  473. shopList.push(pro);
  474. };
  475. local(shopList);
  476. };
  477. function local (shopList){
  478. let data=new Object();
  479. data.data=shopList;
  480. let setData = JSON.stringify(data);
  481. //本地存储
  482. localStorage.setItem('shopList',setData);
  483. };
  484. //title处理
  485. titleLen();
  486. function titleLen(){
  487. $('.RecommendTitle h2,.patentTitle h2').mouseenter(function(){
  488. let h2Len = $(this).text(),
  489. lenW = (h2Len.length)*30;
  490. $(this).siblings().css({
  491. width:lenW+'px',
  492. transition: 'all .5s ease-in-out'
  493. })
  494. })
  495. $('.RecommendTitle h2,.patentTitle h2').mouseout(function(){
  496. let h2Len = $(this).text(),
  497. lenW = (h2Len.length)*30;
  498. $(this).siblings().css({
  499. width:'54px'
  500. })
  501. })
  502. }
  503. }
  504. //banner 箭头高度处理
  505. function bannerFun(){
  506. let imgH = $('.carousel-inner div').eq(0).find('img').innerHeight();
  507. $('.carousel-control').css({'height':(imgH)+'px','line-height':(imgH)+'px'})
  508. }
  509. //bannerFun();
  510. };