暂无描述

fund_h5_api.js 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. var token = '';
  2. var tid = '';
  3. var returnUrl = '';
  4. var cityInfo = '';
  5. var retrievePwd = '';
  6. var appName = '';
  7. var qs = parseQueryString(window.location.href);
  8. var cityName = qs.name || "";
  9. var httpStr=location.href.substr(0,location.href.indexOf("?") + 1); //str得到?之前的字符串
  10. $().ready(function() {
  11. if (qs.returnUrl) {
  12. returnUrl = qs.returnUrl;
  13. }
  14. if (qs.appName) {
  15. appName = qs.appName;
  16. }
  17. if (qs.token) {
  18. token = qs.token;
  19. } else {
  20. showMsg('未提供token!')
  21. }
  22. if (qs.name && qs.code) {
  23. $('.city-name').text(qs.name).attr('data-code', qs.code);
  24. }
  25. var agreementLink = $('.agreement-wrapper a');
  26. agreementLink.attr('href', agreementLink.attr('href') + '?appName=' + appName);
  27. httpStr += "returnUrl=" + returnUrl + "&appName=" + appName;
  28. httpStr = encodeURIComponent(httpStr)
  29. $("nav p span").html(cityName+"公积金查询")
  30. getLoginInfo();
  31. //头部切换公积金类型
  32. switchingType();
  33. // 贷款推荐位
  34. // loan();
  35. loanClick();
  36. });
  37. //头部切换公积金类型
  38. function switchingType() {
  39. var btn = $("nav p");
  40. btn.click(function () {
  41. console.log(cityInfo)
  42. if(cityInfo !='' && cityInfo){
  43. window.location.href = './typeChoice.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : '') + '&httpStr=' + httpStr;
  44. }else{
  45. showMsg('获取城市信息失败:' + cityInfo.region + '公积金查询');
  46. }
  47. })
  48. }
  49. /**
  50. * [showMsg 提示各种错误信息,3s后消失]
  51. */
  52. function showMsg(msg) {
  53. var msgBox = $('.alert-info');
  54. msgBox.children('p').text(msg);
  55. msgBox.show();
  56. setTimeout(function() {
  57. msgBox.hide();
  58. }, 3000);
  59. }
  60. /**
  61. * [showDialog 弹窗提示,传不同的参数提示不同的内容以及按钮的内容和点击之后的作用]
  62. * failed 任务失败,点击关闭弹窗
  63. * maintain 当前城市维护中,点击关闭弹窗
  64. * timeout token过期,点击关闭页面
  65. */
  66. function showDialog(type) {
  67. var mask = $('.mask');
  68. mask.show();
  69. $('.dialog-wrapper input').val('确定');
  70. $('.dialog-wrapper div').hide();
  71. if (type === 'failed') {
  72. $('.dialog-failed').show();
  73. // $('.mask').siblings().hide();
  74. } else if (type === 'maintain') {
  75. $('.dialog-maintain').show();
  76. } else if (type === 'timeout') {
  77. $('.dialog-timeout').show();
  78. $('.dialog-wrapper input').val('关闭').click(function() {
  79. redirectToFailedReturnUrl(tid, 'failed', 1020, '无效的token, 会话不存在或已过期');
  80. })
  81. } else if (type === 'forget') {
  82. var html = '如果您忘记密码,需前往' + qs.name+ '公积金官网<br>重置密码';
  83. $('.dialog-wrapper input').val('复制链接')
  84. $('.dialog-forget').show();
  85. cituInfoData();
  86. // tips.find(function(item, index) {
  87. // if(item.region == cityInfo.region){
  88. // if(item.forget_pwd){
  89. // html = item.forget_pwd[0].content;
  90. // if(item.forget_pwd[0].btnContent == "立即前往"){
  91. // $('.dialog-wrapper input').val('复制链接')
  92. // }else if(item.forget_pwd[0].btnContent == "我知道了"){
  93. // $('.dialog-wrapper input').val('我知道了')
  94. // }
  95. // }
  96. //
  97. // }
  98. // })
  99. // $('.dialog-forget').find('p').html(html)
  100. $('.dialog-wrapper input').click(function() {
  101. tips.find(function(item, index) {
  102. if(item.region == cityInfo.region){
  103. if($('.dialog-wrapper input').val() == "复制链接"){
  104. if(item.URL.password){
  105. retrievePwd = item.URL.password;
  106. goCopy(retrievePwd);
  107. // window.location.href="iframeUrl.html?url=" + retrievePwd;
  108. // window.webkit.messageHandlers.OutPushMessageHandler.postMessage({'name':qs.name,'url':retrievePwd});
  109. }else if(item.URL.web){
  110. retrievePwd = item.URL.web;
  111. goCopy(retrievePwd);
  112. // window.location.href="iframeUrl.html?url=" + retrievePwd;
  113. // window.webkit.messageHandlers.OutPushMessageHandler.postMessage({'name':qs.name,'url':retrievePwd});
  114. }
  115. }
  116. }
  117. })
  118. })
  119. }
  120. }
  121. /**
  122. * [enableCommitButton 启用/禁用提交按钮]
  123. * @param {Boolean} isEnableButton [是否启用提交按钮]
  124. */
  125. function enableCommitButton(isEnableButton) {
  126. var commitButton = $('#submitButton');
  127. if (isEnableButton) {
  128. commitButton.attr('disabled', false).removeClass('disable-commit').addClass('enable-commit');
  129. } else {
  130. commitButton.attr('disabled', true).removeClass('enable-commit').addClass('disable-commit');
  131. }
  132. }
  133. /**
  134. * [isInputReady 检查参数是否输入完毕]
  135. * @return {Boolean} [参数是否输入完毕]
  136. */
  137. function isInputReady() {
  138. var isInputReady = true;
  139. var activeID = $('.tab-tab-active').attr('data-id');
  140. $('.tab-content [data-id="' + activeID + '"]')
  141. .find('input')
  142. .each(
  143. function(index, item) {
  144. if ($(item).val().trim() === '') {
  145. isInputReady = false;
  146. }
  147. if (!$('.check').hasClass('check-active')) {
  148. isInputReady = false;
  149. }
  150. })
  151. return isInputReady;
  152. }
  153. /**
  154. * [initEvent 初始化各种事件]
  155. */
  156. function initEvent() {
  157. var tabs = $('.tab-tab');
  158. var activeID = $('.tab-tab-active').attr('data-id');
  159. // tab页切换
  160. tabs.click(function(event) {
  161. var currItem = $(this);
  162. var currId = currItem.attr('data-id');
  163. $('.tab-tab[data-id="' + currId + '"]').addClass('tab-tab-active').siblings().removeClass('tab-tab-active');
  164. $('.tab-content div[data-id=' + currId + ']').show().siblings().hide();
  165. enableCommitButton(isInputReady());
  166. })
  167. // 监测用户输入来设置提交按钮的状态
  168. $('.tab-content').on('keyup', function() {
  169. enableCommitButton(isInputReady());
  170. })
  171. // 确定按钮点击事件
  172. $('#closeMask').click(function(event) {
  173. $('.mask').removeClass('bg-white').hide().siblings().show();
  174. $('#tid').hide();
  175. $('.alert-info').hide();
  176. $('.loading-wrapper').hide();
  177. })
  178. //阻止冒泡
  179. $(".dialog-wrapper").click(function (){
  180. return false
  181. })
  182. //点击mask阴影
  183. $(".mask").click(function() {
  184. $('.mask').removeClass('bg-white').hide().siblings().show();
  185. $('#tid').hide();
  186. $('.alert-info').hide();
  187. $('.loading-wrapper').hide();
  188. })
  189. // 解析协议checkBox选中/取消选中事件
  190. $('.check').click(function() {
  191. var currentItem = $(this);
  192. if (currentItem.hasClass('check-active')) {
  193. enableCommitButton(false);
  194. currentItem.removeClass('check-active');
  195. } else {
  196. currentItem.addClass('check-active');
  197. enableCommitButton(isInputReady());
  198. }
  199. })
  200. // 提交按钮点击事件
  201. $('#submitButton').click(function() {
  202. if (isInputValid()) {
  203. submitTask();
  204. }
  205. });
  206. // 导航栏左上角退出H5的点击事件
  207. $('#back').click(function() {
  208. redirectToFailedReturnUrl(tid, 'failed', 1020, '退出公积金查询页');
  209. // window.history.go(-1)
  210. // window.webkit.messageHandlers.PopRootMessageHandler.postMessage({name:"1"});
  211. })
  212. }
  213. /**
  214. * [getLoginInfo 获取城市登录信息]
  215. */
  216. function getLoginInfo() {
  217. var regionCode = $('.city-name').attr('data-code');
  218. $.ajax({
  219. type: "GET",
  220. url: BASEURL + 'city_list?type=fund&token=' + token + '&regionCode=' + regionCode + '&time=' + Math.round(Date.now() / 1000),
  221. // url: '../../city_list?type=fund&token=' + token + '&regionCode=' + regionCode + '&time=' + Math.round(Date.now() / 1000),
  222. contentType: 'application/json;charset=utf-8',
  223. success: function(data) {
  224. cityInfo = data;
  225. return renderLoginInfo(data);
  226. },
  227. error: function(err) {
  228. // return showMsg('获取城市信息失败:' + JSON.stringify(err));
  229. return showMsg('获取城市信息失败:' + qs.name + '公积金查询');
  230. }
  231. });
  232. }
  233. /**
  234. * [renderLoginInfo 渲染城市登录信息]
  235. * @param {[type]} cityInfo [城市登录信息]
  236. */
  237. function renderLoginInfo(cityInfo) {
  238. var tabWrapper = $('.tab-tab-wrapper');
  239. var tabConWrapper = $('.tab-content');
  240. var tabsHtmlStr = '';
  241. var tabConHtmlStr = '';
  242. $('.city-name').text(cityInfo.region).attr('data-code', cityInfo.regionCode);
  243. // $('.choose-city a').attr('href', './choose_city.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : ''));
  244. $('nav span a').attr('href', './choose_city.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : ''));
  245. $('.obtainPwd a').attr('href', './queryHelp.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : '') + '&httpStr=' + httpStr);
  246. for (var index in cityInfo.loginTypes) {
  247. var loginType = cityInfo.loginTypes[index];
  248. // if(cityInfo.loginTypes.length != 1){
  249. if (index === '0') {
  250. tabsHtmlStr += '<div class="tab-tab tab-tab-active" data-id ="' + loginType.loginTypeId + '"><p class="tab-title">' + loginType.loginLabel + '</p><i class="hr-active"></i></div>';
  251. tabConHtmlStr += '<div data-id="' + loginType.loginTypeId + '" style="display:block">';
  252. } else {
  253. tabsHtmlStr += '<div class="tab-tab" data-id ="' + loginType.loginTypeId + '"><p class="tab-title">' + loginType.loginLabel + '</p><i class="hr-active"></i></div>';
  254. tabConHtmlStr += '<div data-id="' + loginType.loginTypeId + '" style="display:none">';
  255. }
  256. // }
  257. for (var loginField of loginType.loginFields) {
  258. var type = '';
  259. var placeStr = '';
  260. if (loginField.name.includes('联名卡')) {
  261. placeStr = '请输入公积金联名卡号';
  262. } else if (loginField.name.includes('身份证')) {
  263. placeStr = '请输入身份证';
  264. } else if (loginField.name.includes('手机号')) {
  265. placeStr = '请输入手机号';
  266. } else if (loginField.name.includes('用户名')) {
  267. placeStr = '请输入用户名';
  268. } else if (loginField.name.includes('账号')) {
  269. placeStr = '请输入账号';
  270. } else if (loginField.name.includes('姓名')) {
  271. placeStr = '请输入姓名';
  272. } else if (loginField.name.includes('登录名')) {
  273. placeStr = '请输入登录名';
  274. } else if (loginField.name.includes('存折账号')) {
  275. placeStr = '请输入存折账号';
  276. } else if (loginField.name.includes('密码')) {
  277. placeStr = '请输入密码';
  278. type = 'password';
  279. }
  280. if(qs.name == "北京"){
  281. if (loginField.name.includes('身份证')) {
  282. placeStr = '首次查询请选择联名卡号';
  283. }
  284. }
  285. if(loginField.name.includes('密码')){
  286. tabConHtmlStr += '<div class="input-wrapper inputForget" ><label for="">' + loginField.name + ':</label><input id="' + loginField.code + '" type="' + type + '" placeholder="' + placeStr + '"><div class="forget" onclick="forgetEvent()">忘记密码</div></div>';
  287. }else{
  288. tabConHtmlStr += '<div class="input-wrapper" ><label for="">' + loginField.name + ':</label><input id="' + loginField.code + '" type="' + type + '" placeholder="' + placeStr + '"></div>';
  289. }
  290. }
  291. tabConHtmlStr += '</div>';
  292. }
  293. tabWrapper.html(tabsHtmlStr);
  294. tabConWrapper.html(tabConHtmlStr);
  295. if(cityInfo.loginTypes !=undefined){
  296. if(cityInfo.loginTypes.length == 1){
  297. $(".tab-tab").css({
  298. 'position':'absolute',
  299. 'left':'-5000px'
  300. })
  301. }
  302. }
  303. renderTips($('.city-name').text());
  304. initEvent(); // 各种事件绑定
  305. checkToken();
  306. }
  307. //点击忘记密码按钮
  308. function forgetEvent () {
  309. showDialog('forget')
  310. }
  311. /**
  312. * [isInputValid 校验输入信息是否合法]
  313. * @return {Boolean} [输入信息是否合法]
  314. */
  315. function isInputValid() {
  316. var isInputValid = true;
  317. var activeID = $('.tab-tab-active').attr('data-id');
  318. $('.tab-content [data-id="' + activeID + '"]')
  319. .find('input')
  320. .each(
  321. function(index, item) {
  322. var currentEle = $(item);
  323. // 通过label标签里面的文本来判断输入项的类型
  324. // 例如:
  325. // 身份证号:
  326. var labelText = currentEle.parent().find('label').text().replace(':', '');
  327. var value = currentEle.val();
  328. var reg = null;
  329. if (labelText && labelText.includes('身份证')) {
  330. reg = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/;
  331. if (!reg.test(value)) {
  332. showMsg('身份证输入格式不正确');
  333. isInputValid = false;
  334. return false;
  335. }
  336. }
  337. if (labelText && (labelText.includes('电话') || labelText.includes('手机'))) {
  338. reg = /^1[3456879]\d{9}$/;
  339. if (!reg.test(value)) {
  340. showMsg('电话(手机)号码输入格式不正确')
  341. isInputValid = false;
  342. return false;
  343. }
  344. }
  345. if (labelText && labelText.includes('公积金')) {
  346. reg = /^\d+$/;
  347. if (!reg.test(value)) {
  348. showMsg('公积金账号输入格式不正确')
  349. isInputValid = false;
  350. return false;
  351. }
  352. }
  353. if (labelText && labelText.includes('联名卡')) {
  354. reg = /^\d+$/;
  355. if (!reg.test(value)) {
  356. showMsg('联名卡输入格式不正确')
  357. isInputValid = false;
  358. return false;
  359. }
  360. }
  361. })
  362. return isInputValid;
  363. }
  364. /**
  365. * [checkToken 校验token信息]
  366. */
  367. function checkToken() {
  368. var getTokenInfo = $.ajax({
  369. type: 'GET',
  370. url: BASEURL + 'token?token=' + token + '&time=' + Math.round(Date.now() / 1000),
  371. // url: '../../token?token=' + token + '&time=' + Math.round(Date.now() / 1000),
  372. timeout: 30000,
  373. contentType: 'application/json;charset=utf-8'
  374. });
  375. getTokenInfo.done(function(data) {
  376. if(data.region){//我添加的
  377. $("nav p span").html(cityName+"公积金查询")
  378. cityName = data.region;
  379. tips.find(function(item, index) {
  380. if (item.region === data.region) {
  381. $('.city-name').text(data.region).attr('data-code', item.regionCode);
  382. }
  383. });
  384. }
  385. if (data.returnUrl && !returnUrl) {
  386. window.sessionStorage.isTokenValid = true;
  387. returnUrl = data.returnUrl;
  388. }
  389. if (data.appName) {
  390. var agreementLink = $('.agreement-wrapper a');
  391. agreementLink.attr('href', agreementLink.attr('href') + '?appName=' + data.appName);
  392. }
  393. if (data.region && data.loginLabel && data.inputData) {
  394. // 防止每次刷新都提交任务
  395. if (!window.sessionStorage.tid) {
  396. var task = {
  397. type: 'fund',
  398. region: data.region,
  399. loginLabel: data.loginLabel,
  400. inputData: JSON.parse(data.inputData),
  401. }
  402. return submitTask(task);
  403. }
  404. }
  405. if (data.tid) {
  406. $("#tid").val(data.tid);
  407. tid = data.tid;
  408. autoInputTaskInfo();
  409. // checkTaskStatus(data.tid);
  410. }
  411. });
  412. getTokenInfo.fail(function(error) {
  413. window.sessionStorage.isTokenValid = false;
  414. enableCommitButton(false);
  415. if (error.responseJSON.code === 1020) {
  416. showDialog('timeout');
  417. } else {
  418. showMsg(error.responseJSON.error);
  419. }
  420. });
  421. }
  422. /**
  423. * [submitTask 提交查询任务]
  424. * @param {[type]} data [查询任务相关参数]
  425. */
  426. function submitTask(data) {
  427. showLoading(true);
  428. var url = BASEURL + "task?token=" + token + "&time=" + Math.round(Date.now() / 1000);
  429. // var url = "../../task?token=" + token + "&time=" + Math.round(Date.now() / 1000);
  430. var task = data || getTaskInfo();
  431. data ? null : saveTaskInfo();
  432. var posting = $.ajax({
  433. type: "POST",
  434. url: url,
  435. data: JSON.stringify(task),
  436. timeout: 30000,
  437. contentType: 'application/json;charset=utf-8'
  438. });
  439. posting.done(function(task) {
  440. console.log(task+"000")
  441. tid = task.tid;
  442. $("#tid").val(task.tid); // for next submit
  443. window.sessionStorage.tid = tid;
  444. checkTaskStatus(task.tid);
  445. });
  446. posting.fail(function(error) {
  447. showLoading(false);
  448. if (error.responseJSON.code === 1029) {
  449. showDialog('maintain');
  450. } else if (error.responseJSON.code === 1011) {
  451. showMsg('身份证输入不正确');
  452. } else if (error.responseJSON.code === 1020) {
  453. showDialog('timeout');
  454. } else {
  455. showDialog('failed');
  456. }
  457. });
  458. }
  459. /**
  460. * [getTaskInfo 获取提交任务所需参数]
  461. * @return {[Object]} [提交任务所需参数]
  462. */
  463. function getTaskInfo() {
  464. var task = {};
  465. var activeID = $('.tab-tab-active').attr('data-id');
  466. task.region = $('.city-name').attr('data-code');
  467. task.loginLabel = $(".tab-tab-active").text().trim();
  468. task.inputData = []; // 完整记录用户输入信息
  469. $("div[data-id='" + activeID + "'] input").each(function(index, item) {
  470. var currEle = $(item);
  471. task.inputData.push({
  472. key: currEle.attr('id'),
  473. value: currEle.val()
  474. })
  475. })
  476. if ($("#tid").val()) {
  477. task.tid = $("#tid").val();
  478. } else {
  479. task.type = 'fund';
  480. }
  481. return task;
  482. }
  483. /**
  484. * [saveTaskInfo 保存提交用户输入的信息在sessionStorage中,用于用户刷新后数据回填]
  485. */
  486. function saveTaskInfo() {
  487. var ss = window.sessionStorage;
  488. var activeID = $('.tab-tab-active').attr('data-id');
  489. ss.activeID = activeID;
  490. var inputList = $('div [data-id="' + activeID + '"] input');
  491. inputList.each(function(index, item) {
  492. var currentEle = $(item);
  493. ss[currentEle.attr('id')] = currentEle.val();
  494. })
  495. }
  496. /**
  497. * [autoInputTaskInfo 用于用户刷新后从sessionStorage中拿到数据数据回填]
  498. */
  499. function autoInputTaskInfo() {
  500. var ss = window.sessionStorage;
  501. var activeID = $('.tab-tab-active').attr('data-id');
  502. if (ss.activeID && (activeID !== ss.activeID)) {
  503. $('.tab-tab[data-id="' + ss.activeID + '"]').addClass('tab-tab-active').siblings().removeClass('tab-tab-active');
  504. $('.tab-content div[data-id=' + ss.activeID + ']').show().siblings().hide();
  505. }
  506. $("#tid").val(ss.tid);
  507. tid = ss.tid;
  508. for (var key in ss) {
  509. var currentEle = $("div [data-id='" + ss.activeID + "'] #" + key);
  510. currentEle.length > 0 ? currentEle.val(ss[key]) : null;
  511. }
  512. enableCommitButton(isInputReady());
  513. }
  514. /**
  515. * [checkTaskStatus 轮询任务状态]
  516. * @param {[type]} tid [tid]
  517. */
  518. function checkTaskStatus(tid) {
  519. var url = BASEURL + 'task?tid=' + tid + '&token=' + token + '&time=' + Math.round(Date.now() / 1000);
  520. // var url = '../../task?tid=' + tid + '&token=' + token + '&time=' + Math.round(Date.now() / 1000);
  521. var getting = $.get(url);
  522. getting.fail(function(error) {
  523. showMsg(error.responseJSON.error);
  524. });
  525. getting.done(function(task) {
  526. if (task.status === 'done') {
  527. console.log("成功")
  528. $.ajax({
  529. type:"get",
  530. url: returnUrl + token +"&tid=" + tid + "&city=" + qs.name,
  531. dataType:'json',
  532. success: function (res) {
  533. console.log(res)
  534. }
  535. })
  536. process.stop(100);
  537. $("#tid").val('');
  538. showLoading(false);
  539. redirectToSucsessReturnUrl(task.tid, 'success');
  540. return;
  541. }
  542. if (task.status === "processing") {
  543. if ($('.loading-wrapper').css('display') === 'none') {
  544. showLoading(true);
  545. }
  546. setTimeout(function() {
  547. checkTaskStatus(tid);
  548. }, 1000);
  549. return;
  550. }
  551. if (task.status === "failed") {
  552. process.stop(100);
  553. tid = '';
  554. $("#tid").val('');
  555. showLoading(false);
  556. window.sessionStorage.clear();
  557. if (task.failCode === 1029) {
  558. showDialog('maintain');
  559. } else {
  560. showDialog('failed');
  561. }
  562. return;
  563. }
  564. if (task.status == "suspended") {
  565. console.log("填写有误")
  566. $.ajax({
  567. type:"get",
  568. url: returnUrl + token +"&tid=" + tid + "&city=" + qs.name,
  569. dataType:'json',
  570. success: function (res) {
  571. console.log(res)
  572. }
  573. })
  574. process.stop(0);
  575. showLoading(false);
  576. enableCommitButton(false);
  577. switch (task.need) {
  578. case 'changeLoginType': // 无记录,请尝试切换登录类型
  579. case 'regionOrLogintype': // 请选择地区信息 | 请选择登录类型 | 请选择补充地区信息 | 该地区不支持公积金 | 发送的fundId或loginTypeId错误
  580. // 你不是本地用户,请选择所属地区进行登录 | 所选的城市暂不支持,请选择其它城市登录
  581. showMsg('你不是本地用户,请选择所属地区进行登录');
  582. break;
  583. case 'accountOrpassword':
  584. showMsg('账号或密码输入错误');
  585. break;
  586. case 'parameterError':
  587. showMsg('输入的信息有误');
  588. break;
  589. default:
  590. showMsg(task.need);
  591. break;
  592. }
  593. }
  594. });
  595. }
  596. /**
  597. * [showLoading 显示loading界面]
  598. * @param {Boolean} isShow [description]
  599. */
  600. function showLoading(isShow) {
  601. if (isShow) {
  602. // 防止页面刷新之后进度从0开始
  603. if (window.sessionStorage.processRate) {
  604. process.start(parseInt(window.sessionStorage.processRate));
  605. } else {
  606. process.start(0);
  607. }
  608. $('.loading-wrapper').show().siblings().hide();
  609. $('html').addClass('bg-white');
  610. } else {
  611. process.stop(0);
  612. $('html').removeClass('bg-white');
  613. $('.loading-wrapper').hide().siblings().show();
  614. }
  615. }
  616. /**
  617. * [redirectToFailedReturnUrl 跳到redirectURL]
  618. */
  619. function redirectToFailedReturnUrl(tid, result, failCode, reason) {
  620. if (returnUrl.indexOf('?') < 0) {
  621. returnUrl += "?result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason + "&city=" + qs.name;
  622. } else {
  623. returnUrl += "&result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason + "&city=" + qs.name;
  624. }
  625. window.sessionStorage.clear();
  626. window.location.href = returnUrl;
  627. }
  628. /**
  629. * [redirectToSucsessReturnUrl 跳到redirectURL]
  630. */
  631. function redirectToSucsessReturnUrl(tid, result) {
  632. if (returnUrl.indexOf('?') < 0) {
  633. returnUrl += "?result=" + result + "&tid=" + tid + "&token=" + token + "&city=" + qs.name;
  634. } else {
  635. returnUrl += "&result=" + result + "&tid=" + tid + "&token=" + token + "&city=" + qs.name;
  636. }
  637. window.sessionStorage.clear();
  638. window.location.href = returnUrl;
  639. }
  640. /**
  641. * [renderTips 渲染常见问题]
  642. * @param {[type]} region [description]
  643. */
  644. function renderTips(region) {
  645. var tipStr = "<p>常见问题</p>";
  646. var defaultTip = null;
  647. var defaultRegion = '北京';
  648. var tipContent = tips.find(function(item, index) {
  649. if (item.region === defaultRegion) {
  650. defaultTip = item;
  651. }
  652. return item.region === region;
  653. });
  654. if (!tipContent) {
  655. tipContent = defaultTip; // 默认北京
  656. }
  657. tipContent = tipContent.tip;
  658. for (var list of tipContent) {
  659. tipStr += "<p>" + list.title + "</p>";
  660. if (list.content) {
  661. for (var tip of list.content) {
  662. tipStr += "<p>" + tip + "</p>"
  663. }
  664. }
  665. }
  666. $('.tips').html(tipStr);
  667. }
  668. /**
  669. * [Process 任务进度显示]
  670. */
  671. function Process(opt) {
  672. this.ele = opt.ele;
  673. this.rate = 0;
  674. this.afterStart = opt.afterStart;
  675. this.afterStop = opt.afterStop;
  676. this.timer = null;
  677. this.step = null;
  678. this._getInterval = function() {
  679. return Math.round((Math.random() * 100) + 300);
  680. };
  681. this._getStep = function() {
  682. return Math.round(Math.random() * 3);
  683. };
  684. }
  685. Process.prototype.start = function(rate) {
  686. this.rate = rate == undefined ? this.rate : rate;
  687. let _this = this;
  688. let interval = this._getInterval();
  689. this.timer = setInterval(function() {
  690. interval = _this._getInterval();
  691. _this.step = _this._getStep();
  692. _this.afterStart && _this.afterStart.call(_this);
  693. }, interval);
  694. }
  695. Process.prototype.stop = function(rate) {
  696. this.rate = rate == undefined ? this.rate : rate;
  697. clearInterval(this.timer);
  698. this.afterStop && this.afterStop();
  699. }
  700. var process = new Process({
  701. ele: $('.process'),
  702. interval: 1000,
  703. afterStart: function() {
  704. this.rate += this.step;
  705. if (this.rate >= 97) {
  706. this.rate = 99;
  707. this.stop(this.rate);
  708. }
  709. this.ele.text(this.rate + '%');
  710. window.sessionStorage.processRate = this.rate;
  711. },
  712. afterStop: function() {
  713. this.ele.text(this.rate + '%');
  714. window.sessionStorage.processRate = this.rate;
  715. }
  716. })
  717. //忘记密码文案
  718. function cituInfoData () {
  719. $.ajax({
  720. type:"POST",
  721. url: "/api/city/listinfo",
  722. data:{
  723. 'region': qs.name
  724. },
  725. dataType:'json',
  726. success: function (res) {
  727. console.log(res)
  728. if(res.errno == 0 && res.rst && res.rst.city){
  729. var data = res.rst.city.city;
  730. if(data.pwd_info){
  731. $(".dialog-forget").find("p").html(data.pwd_info);
  732. }else{
  733. $(".dialog-forget").find("p").html(`如果您忘记密码,需前往${qs.name}公积金官网重置密码.`)
  734. }
  735. }else{
  736. showMsg(res.err)
  737. }
  738. }
  739. });
  740. }
  741. function swiper () {
  742. var swiper = new Swiper('.swiper-container', {
  743. slidesPerView: 1,
  744. spaceBetween: 0,
  745. loop: true,
  746. pagination: '.swiper-pagination',
  747. });
  748. }
  749. //贷款推荐位
  750. //function loan () {
  751. // $.ajax({
  752. // type:"POST",
  753. // url: "/api/hot/getactivitylist",
  754. // dataType:'json',
  755. // success: function (res) {
  756. // if(res.errno == 0 && res.rst && res.rst.activitylist && res.rst.activitylist.rst){
  757. // var html = `<p class="bannerTop"><span>解决日常资金周转?为您推荐优质贷款</span></p>
  758. // <div class="swiper-container">
  759. // <div class="swiper-wrapper">`;
  760. // res.rst.activitylist.rst.data.forEach(function (item, index) {
  761. // var lilv = '';
  762. // if(item.day_rate != undefined && item.day_rate && item.day_rate !=null){
  763. // lilv = item.day_rate;
  764. // }else if(item.monthly_rate != undefined && item.monthly_rate && item.monthly_rate !=null){
  765. // lilv = item.monthly_rate;
  766. // }
  767. // html += `<div class="swiper-slide">
  768. // <div class="mySwiper" data-id="${item.id}" data-name="${item.name}">
  769. // <img class="img" src="${item.icon}" />
  770. // <div class="con">
  771. // <h3>${item.name}</h3>
  772. // <p>利率 ${lilv}%</p>
  773. // <p>${item.description}</p>
  774. // </div>
  775. // <div class="button">立即查看</div>
  776. // </div>
  777. // </div>`
  778. // })
  779. // html += `</div>
  780. // <div class="swiper-pagination"></div>
  781. // </div>
  782. // <div class="data"><icon></icon>数据加密 | 官网直连 | 保险承诺</div>`
  783. // $(".loan_recommendation").html(html);
  784. // loanClick();
  785. // swiper ();
  786. // }else{
  787. // showMsg(res.rst.activitylist.err)
  788. // }
  789. // }
  790. // });
  791. //}
  792. //推广统计的接口
  793. function extension_statistics (id,name) {
  794. $.ajax({
  795. type:"POST",
  796. url: "/api/hot/getactivitylink",
  797. data:{
  798. 'id': id
  799. },
  800. dataType:'json',
  801. success: function (res) {
  802. console.log(res)
  803. if(res.errno == 0 && res.rst){
  804. var url = res.rst.link;
  805. url = encodeURIComponent(url);
  806. window.location.href='loan.html?url=' + url
  807. }else{
  808. showMsg(res.err)
  809. }
  810. }
  811. });
  812. }
  813. function loanClick () {
  814. $(".mySwiper").click(function () {
  815. // var id = $(this).attr('data-id');
  816. // var name = $(this).attr('data-name');
  817. // extension_statistics(id,name)
  818. extension_statistics(383,"贷款")
  819. })
  820. }