public.js 14 KB

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