public.js 14 KB

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