Ei kuvausta

fund_h5_api.js 24KB

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