No Description

fund_h5_api.js 23KB

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