No Description

fund_h5_api.js 23KB

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