暫無描述

choose_city2.js 2.5KB

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