Geen omschrijving

fund_h5_api.js 24KB

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