説明なし

choose_city.js 2.6KB

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