Нет описания

choose_city.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. var qs = parseQueryString(window.location.href);
  2. // var hostUrl = '../..';
  3. var hostUrl = 'https://api.xindedata.com/v1';
  4. var returnUrl = qs.returnUrl;
  5. var token = qs.token;
  6. checkToken();
  7. if (qs.name) {
  8. $('.current-city span').text(qs.name).attr('data-code', qs.code);
  9. }
  10. $('#back').click(function() {
  11. if (document.referrer.includes('fund_h5_api.html')) {
  12. window.location.href = document.referrer;
  13. } else {
  14. redirectToFailedReturnUrl('', 'failed', 1020, '退出公积金查询页');
  15. }
  16. });
  17. $('.current-city').click(function() {
  18. var cityName = qs.name || $('.current-city span').text();
  19. var cityCode = qs.code || $('.current-city span').attr('data-code');
  20. if (document.referrer.includes('&name=')) {
  21. window.location.href = document.referrer.replace(/&name=[^&]+&code=[^&]+/, '&name=' + cityName + '&code=' + cityCode);
  22. } else {
  23. window.location.href = './fund_h5_api.html?token=' + token + '&name=' + cityName + '&code=' + cityCode;
  24. }
  25. })
  26. function redirectToFailedReturnUrl(tid, result, failCode, reason) {
  27. var linkString = returnUrl.includes('?') ? '&' : '?';
  28. returnUrl += linkString + "result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason;
  29. window.location.href = returnUrl;
  30. }
  31. function showMsg(msg) {
  32. var msgBox = $('.alert-info');
  33. msgBox.children('p').text(msg);
  34. msgBox.show();
  35. setTimeout(function() {
  36. msgBox.hide();
  37. }, 30000);
  38. }
  39. function checkToken() {
  40. var getTokenInfo = $.ajax({
  41. type: 'GET',
  42. url: hostUrl + '/token?token=' + token + "&time=" + Math.round(Date.now() / 1000),
  43. timeout: 30000,
  44. contentType: 'application/json;charset=utf-8'
  45. });
  46. getTokenInfo.done(function(data) {
  47. if (data.returnUrl && !returnUrl) {
  48. returnUrl = data.returnUrl;
  49. }
  50. if (data.tid && data.region && data.loginLabel && data.inputData) {
  51. window.location.href = './fund_h5_api.html?token=' + token + "&time=" + Math.round(Date.now() / 1000);
  52. return;
  53. }
  54. $('body').show();
  55. getCityListAndRender();
  56. });
  57. getTokenInfo.fail(function(err) {
  58. $('body').show();
  59. showMsg('token校验失败:' + JSON.stringify(err.responseJSON.error));
  60. });
  61. }
  62. function getCityListAndRender() {
  63. $.ajax({
  64. type: "GET",
  65. url: hostUrl + '/city_list?type=fund&sort=true&token=' + token + '&time=' + Math.round(Date.now() / 1000),
  66. contentType: 'application/json;charset=utf-8',
  67. success: function(data) {
  68. return $(".city-list").CityPicker(data);
  69. },
  70. error: function(err) {
  71. return showMsg('获取城市列表失败:' + JSON.stringify(err.responseJSON.error));
  72. }
  73. });
  74. }