Nenhuma Descrição

fund_h5_api.js 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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. console.log(data)
  226. return renderLoginInfo(data);
  227. },
  228. error: function(err) {
  229. // return showMsg('获取城市信息失败:' + JSON.stringify(err));
  230. return showMsg('获取城市信息失败:' + qs.name + '公积金查询');
  231. }
  232. });
  233. }
  234. /**
  235. * [renderLoginInfo 渲染城市登录信息]
  236. * @param {[type]} cityInfo [城市登录信息]
  237. */
  238. function renderLoginInfo(cityInfo) {
  239. var tabWrapper = $('.tab-tab-wrapper');
  240. var tabConWrapper = $('.tab-content');
  241. var tabsHtmlStr = '';
  242. var tabConHtmlStr = '';
  243. $('.city-name').text(cityInfo.region).attr('data-code', cityInfo.regionCode);
  244. // $('.choose-city a').attr('href', './choose_city.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : ''));
  245. $('nav span a').attr('href', './choose_city.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : ''));
  246. $('.obtainPwd a').attr('href', './queryHelp.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : '') + '&httpStr=' + httpStr);
  247. for (var index in cityInfo.loginTypes) {
  248. var loginType = cityInfo.loginTypes[index];
  249. // if(cityInfo.loginTypes.length != 1){
  250. if (index === '0') {
  251. 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>';
  252. tabConHtmlStr += '<div data-id="' + loginType.loginTypeId + '" style="display:block">';
  253. } else {
  254. tabsHtmlStr += '<div class="tab-tab" data-id ="' + loginType.loginTypeId + '"><p class="tab-title">' + loginType.loginLabel + '</p><i class="hr-active"></i></div>';
  255. tabConHtmlStr += '<div data-id="' + loginType.loginTypeId + '" style="display:none">';
  256. }
  257. // }
  258. for (var loginField of loginType.loginFields) {
  259. var type = '';
  260. var placeStr = '';
  261. if (loginField.name.includes('联名卡')) {
  262. placeStr = '请输入公积金联名卡号';
  263. } else if (loginField.name.includes('身份证')) {
  264. placeStr = '请输入身份证';
  265. } else if (loginField.name.includes('手机号')) {
  266. placeStr = '请输入手机号';
  267. } else if (loginField.name.includes('用户名')) {
  268. placeStr = '请输入用户名';
  269. } else if (loginField.name.includes('账号')) {
  270. placeStr = '请输入账号';
  271. } else if (loginField.name.includes('姓名')) {
  272. placeStr = '请输入姓名';
  273. } else if (loginField.name.includes('登录名')) {
  274. placeStr = '请输入登录名';
  275. } else if (loginField.name.includes('存折账号')) {
  276. placeStr = '请输入存折账号';
  277. } else if (loginField.name.includes('密码')) {
  278. placeStr = '请输入密码';
  279. type = 'password';
  280. }
  281. if(qs.name == "北京"){
  282. if (loginField.name.includes('身份证')) {
  283. placeStr = '首次查询请选择联名卡号';
  284. }
  285. }
  286. if(loginField.name.includes('密码')){
  287. 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>';
  288. }else{
  289. tabConHtmlStr += '<div class="input-wrapper" ><label for="">' + loginField.name + ':</label><input id="' + loginField.code + '" type="' + type + '" placeholder="' + placeStr + '"></div>';
  290. }
  291. }
  292. tabConHtmlStr += '</div>';
  293. }
  294. tabWrapper.html(tabsHtmlStr);
  295. tabConWrapper.html(tabConHtmlStr);
  296. if(cityInfo.loginTypes !=undefined){
  297. if(cityInfo.loginTypes.length == 1){
  298. $(".tab-tab").css({
  299. 'position':'absolute',
  300. 'left':'-5000px'
  301. })
  302. }
  303. }
  304. renderTips($('.city-name').text());
  305. initEvent(); // 各种事件绑定
  306. checkToken();
  307. }
  308. //点击忘记密码按钮
  309. function forgetEvent () {
  310. showDialog('forget')
  311. }
  312. /**
  313. * [isInputValid 校验输入信息是否合法]
  314. * @return {Boolean} [输入信息是否合法]
  315. */
  316. function isInputValid() {
  317. var isInputValid = true;
  318. var activeID = $('.tab-tab-active').attr('data-id');
  319. $('.tab-content [data-id="' + activeID + '"]')
  320. .find('input')
  321. .each(
  322. function(index, item) {
  323. var currentEle = $(item);
  324. // 通过label标签里面的文本来判断输入项的类型
  325. // 例如:
  326. // 身份证号:
  327. var labelText = currentEle.parent().find('label').text().replace(':', '');
  328. var value = currentEle.val();
  329. var reg = null;
  330. if (labelText && labelText.includes('身份证')) {
  331. 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}$)/;
  332. if (!reg.test(value)) {
  333. showMsg('身份证输入格式不正确');
  334. isInputValid = false;
  335. return false;
  336. }
  337. }
  338. if (labelText && (labelText.includes('电话') || labelText.includes('手机'))) {
  339. reg = /^1[3456879]\d{9}$/;
  340. if (!reg.test(value)) {
  341. showMsg('电话(手机)号码输入格式不正确')
  342. isInputValid = false;
  343. return false;
  344. }
  345. }
  346. if (labelText && labelText.includes('公积金')) {
  347. reg = /^\d+$/;
  348. if (!reg.test(value)) {
  349. showMsg('公积金账号输入格式不正确')
  350. isInputValid = false;
  351. return false;
  352. }
  353. }
  354. if (labelText && labelText.includes('联名卡')) {
  355. reg = /^\d+$/;
  356. if (!reg.test(value)) {
  357. showMsg('联名卡输入格式不正确')
  358. isInputValid = false;
  359. return false;
  360. }
  361. }
  362. })
  363. return isInputValid;
  364. }
  365. /**
  366. * [checkToken 校验token信息]
  367. */
  368. function checkToken() {
  369. var getTokenInfo = $.ajax({
  370. type: 'GET',
  371. url: BASEURL + 'token?token=' + token + '&time=' + Math.round(Date.now() / 1000),
  372. // url: '../../token?token=' + token + '&time=' + Math.round(Date.now() / 1000),
  373. timeout: 30000,
  374. contentType: 'application/json;charset=utf-8'
  375. });
  376. getTokenInfo.done(function(data) {
  377. if(data.region){//我添加的
  378. $("nav p span").html(cityName+"公积金查询")
  379. cityName = data.region;
  380. tips.find(function(item, index) {
  381. if (item.region === data.region) {
  382. $('.city-name').text(data.region).attr('data-code', item.regionCode);
  383. }
  384. });
  385. }
  386. if (data.returnUrl && !returnUrl) {
  387. window.sessionStorage.isTokenValid = true;
  388. returnUrl = data.returnUrl;
  389. }
  390. if (data.appName) {
  391. var agreementLink = $('.agreement-wrapper a');
  392. agreementLink.attr('href', agreementLink.attr('href') + '?appName=' + data.appName);
  393. }
  394. if (data.region && data.loginLabel && data.inputData) {
  395. // 防止每次刷新都提交任务
  396. if (!window.sessionStorage.tid) {
  397. var task = {
  398. type: 'fund',
  399. region: data.region,
  400. loginLabel: data.loginLabel,
  401. inputData: JSON.parse(data.inputData),
  402. }
  403. return submitTask(task);
  404. }
  405. }
  406. if (data.tid) {
  407. $("#tid").val(data.tid);
  408. tid = data.tid;
  409. autoInputTaskInfo();
  410. // checkTaskStatus(data.tid);
  411. }
  412. });
  413. getTokenInfo.fail(function(error) {
  414. window.sessionStorage.isTokenValid = false;
  415. enableCommitButton(false);
  416. if (error.responseJSON.code === 1020) {
  417. showDialog('timeout');
  418. } else {
  419. showMsg(error.responseJSON.error);
  420. }
  421. });
  422. }
  423. /**
  424. * [submitTask 提交查询任务]
  425. * @param {[type]} data [查询任务相关参数]
  426. */
  427. function submitTask(data) {
  428. showLoading(true);
  429. var url = BASEURL + "task?token=" + token + "&time=" + Math.round(Date.now() / 1000);
  430. // var url = "../../task?token=" + token + "&time=" + Math.round(Date.now() / 1000);
  431. var task = data || getTaskInfo();
  432. data ? null : saveTaskInfo();
  433. var posting = $.ajax({
  434. type: "POST",
  435. url: url,
  436. data: JSON.stringify(task),
  437. timeout: 30000,
  438. contentType: 'application/json;charset=utf-8'
  439. });
  440. posting.done(function(task) {
  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. process.stop(100);
  528. $("#tid").val('');
  529. showLoading(false);
  530. redirectToSucsessReturnUrl(task.tid, 'success');
  531. return;
  532. }
  533. if (task.status === "processing") {
  534. if ($('.loading-wrapper').css('display') === 'none') {
  535. showLoading(true);
  536. }
  537. setTimeout(function() {
  538. checkTaskStatus(tid);
  539. }, 1000);
  540. return;
  541. }
  542. if (task.status === "failed") {
  543. process.stop(100);
  544. tid = '';
  545. $("#tid").val('');
  546. showLoading(false);
  547. window.sessionStorage.clear();
  548. if (task.failCode === 1029) {
  549. showDialog('maintain');
  550. } else {
  551. showDialog('failed');
  552. }
  553. return;
  554. }
  555. if (task.status == "suspended") {
  556. process.stop(0);
  557. showLoading(false);
  558. enableCommitButton(false);
  559. switch (task.need) {
  560. case 'changeLoginType': // 无记录,请尝试切换登录类型
  561. case 'regionOrLogintype': // 请选择地区信息 | 请选择登录类型 | 请选择补充地区信息 | 该地区不支持公积金 | 发送的fundId或loginTypeId错误
  562. // 你不是本地用户,请选择所属地区进行登录 | 所选的城市暂不支持,请选择其它城市登录
  563. showMsg('你不是本地用户,请选择所属地区进行登录');
  564. break;
  565. case 'accountOrpassword':
  566. showMsg('账号或密码输入错误');
  567. break;
  568. case 'parameterError':
  569. showMsg('输入的信息有误');
  570. break;
  571. default:
  572. showMsg(task.need);
  573. break;
  574. }
  575. }
  576. });
  577. }
  578. /**
  579. * [showLoading 显示loading界面]
  580. * @param {Boolean} isShow [description]
  581. */
  582. function showLoading(isShow) {
  583. if (isShow) {
  584. // 防止页面刷新之后进度从0开始
  585. if (window.sessionStorage.processRate) {
  586. process.start(parseInt(window.sessionStorage.processRate));
  587. } else {
  588. process.start(0);
  589. }
  590. $('.loading-wrapper').show().siblings().hide();
  591. $('html').addClass('bg-white');
  592. } else {
  593. process.stop(0);
  594. $('html').removeClass('bg-white');
  595. $('.loading-wrapper').hide().siblings().show();
  596. }
  597. }
  598. /**
  599. * [redirectToFailedReturnUrl 跳到redirectURL]
  600. */
  601. function redirectToFailedReturnUrl(tid, result, failCode, reason) {
  602. if (returnUrl.indexOf('?') < 0) {
  603. returnUrl += "?result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason;
  604. } else {
  605. returnUrl += "&result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason;
  606. }
  607. window.sessionStorage.clear();
  608. window.location.href = returnUrl;
  609. }
  610. /**
  611. * [redirectToSucsessReturnUrl 跳到redirectURL]
  612. */
  613. function redirectToSucsessReturnUrl(tid, result) {
  614. if (returnUrl.indexOf('?') < 0) {
  615. returnUrl += "?result=" + result + "&tid=" + tid + "&token=" + token;
  616. } else {
  617. returnUrl += "&result=" + result + "&tid=" + tid + "&token=" + token;
  618. }
  619. window.sessionStorage.clear();
  620. window.location.href = returnUrl;
  621. }
  622. /**
  623. * [renderTips 渲染常见问题]
  624. * @param {[type]} region [description]
  625. */
  626. function renderTips(region) {
  627. var tipStr = "<p>常见问题</p>";
  628. var defaultTip = null;
  629. var defaultRegion = '北京';
  630. var tipContent = tips.find(function(item, index) {
  631. if (item.region === defaultRegion) {
  632. defaultTip = item;
  633. }
  634. return item.region === region;
  635. });
  636. if (!tipContent) {
  637. tipContent = defaultTip; // 默认北京
  638. }
  639. tipContent = tipContent.tip;
  640. for (var list of tipContent) {
  641. tipStr += "<p>" + list.title + "</p>";
  642. if (list.content) {
  643. for (var tip of list.content) {
  644. tipStr += "<p>" + tip + "</p>"
  645. }
  646. }
  647. }
  648. $('.tips').html(tipStr);
  649. }
  650. /**
  651. * [Process 任务进度显示]
  652. */
  653. function Process(opt) {
  654. this.ele = opt.ele;
  655. this.rate = 0;
  656. this.afterStart = opt.afterStart;
  657. this.afterStop = opt.afterStop;
  658. this.timer = null;
  659. this.step = null;
  660. this._getInterval = function() {
  661. return Math.round((Math.random() * 100) + 300);
  662. };
  663. this._getStep = function() {
  664. return Math.round(Math.random() * 3);
  665. };
  666. }
  667. Process.prototype.start = function(rate) {
  668. this.rate = rate == undefined ? this.rate : rate;
  669. let _this = this;
  670. let interval = this._getInterval();
  671. this.timer = setInterval(function() {
  672. interval = _this._getInterval();
  673. _this.step = _this._getStep();
  674. _this.afterStart && _this.afterStart.call(_this);
  675. }, interval);
  676. }
  677. Process.prototype.stop = function(rate) {
  678. this.rate = rate == undefined ? this.rate : rate;
  679. clearInterval(this.timer);
  680. this.afterStop && this.afterStop();
  681. }
  682. var process = new Process({
  683. ele: $('.process'),
  684. interval: 1000,
  685. afterStart: function() {
  686. this.rate += this.step;
  687. if (this.rate >= 97) {
  688. this.rate = 99;
  689. this.stop(this.rate);
  690. }
  691. this.ele.text(this.rate + '%');
  692. window.sessionStorage.processRate = this.rate;
  693. },
  694. afterStop: function() {
  695. this.ele.text(this.rate + '%');
  696. window.sessionStorage.processRate = this.rate;
  697. }
  698. })
  699. //忘记密码文案
  700. function cituInfoData () {
  701. $.ajax({
  702. type:"POST",
  703. url: "/api/city/listinfo",
  704. data:{
  705. 'region': qs.name
  706. },
  707. dataType:'json',
  708. success: function (res) {
  709. console.log(res)
  710. if(res.errno == 0 && res.rst && res.rst.city){
  711. var data = res.rst.city.city;
  712. if(data.pwd_info){
  713. $(".dialog-forget").find("p").html(data.pwd_info);
  714. }else{
  715. $(".dialog-forget").find("p").html(`如果您忘记密码,需前往${qs.name}公积金官网重置密码.`)
  716. }
  717. }else{
  718. showMsg(res.err)
  719. }
  720. }
  721. });
  722. }
  723. function swiper () {
  724. var swiper = new Swiper('.swiper-container', {
  725. slidesPerView: 1,
  726. spaceBetween: 0,
  727. loop: true,
  728. pagination: '.swiper-pagination',
  729. });
  730. }
  731. //贷款推荐位
  732. //function loan () {
  733. // $.ajax({
  734. // type:"POST",
  735. // url: "/api/hot/getactivitylist",
  736. // dataType:'json',
  737. // success: function (res) {
  738. // if(res.errno == 0 && res.rst && res.rst.activitylist && res.rst.activitylist.rst){
  739. // var html = `<p class="bannerTop"><span>解决日常资金周转?为您推荐优质贷款</span></p>
  740. // <div class="swiper-container">
  741. // <div class="swiper-wrapper">`;
  742. // res.rst.activitylist.rst.data.forEach(function (item, index) {
  743. // var lilv = '';
  744. // if(item.day_rate != undefined && item.day_rate && item.day_rate !=null){
  745. // lilv = item.day_rate;
  746. // }else if(item.monthly_rate != undefined && item.monthly_rate && item.monthly_rate !=null){
  747. // lilv = item.monthly_rate;
  748. // }
  749. // html += `<div class="swiper-slide">
  750. // <div class="mySwiper" data-id="${item.id}" data-name="${item.name}">
  751. // <img class="img" src="${item.icon}" />
  752. // <div class="con">
  753. // <h3>${item.name}</h3>
  754. // <p>利率 ${lilv}%</p>
  755. // <p>${item.description}</p>
  756. // </div>
  757. // <div class="button">立即查看</div>
  758. // </div>
  759. // </div>`
  760. // })
  761. // html += `</div>
  762. // <div class="swiper-pagination"></div>
  763. // </div>
  764. // <div class="data"><icon></icon>数据加密 | 官网直连 | 保险承诺</div>`
  765. // $(".loan_recommendation").html(html);
  766. // loanClick();
  767. // swiper ();
  768. // }else{
  769. // showMsg(res.rst.activitylist.err)
  770. // }
  771. // }
  772. // });
  773. //}
  774. //推广统计的接口
  775. function extension_statistics (id,name) {
  776. $.ajax({
  777. type:"POST",
  778. url: "/api/hot/getactivitylink",
  779. data:{
  780. 'id': id
  781. },
  782. dataType:'json',
  783. success: function (res) {
  784. console.log(res)
  785. if(res.errno == 0 && res.rst){
  786. var url = res.rst.link;
  787. url = encodeURIComponent(url);
  788. // window.location.href='loan.html?url=' + url
  789. }else{
  790. showMsg(res.err)
  791. }
  792. }
  793. });
  794. }
  795. function loanClick () {
  796. $(".mySwiper").click(function () {
  797. // var id = $(this).attr('data-id');
  798. // var name = $(this).attr('data-name');
  799. // extension_statistics(id,name)
  800. extension_statistics(329,"贷款")
  801. })
  802. }