public.js 14 KB

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