No Description

fund_h5_api.js 25KB

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