Aucune description

choose_city.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. var qs = parseQueryString(window.location.href);
  2. // var hostUrl = '../..';
  3. var hostUrl = BASEURL;
  4. var returnUrl = qs.returnUrl;
  5. var token = qs.token;
  6. var addressName = '';
  7. var local_city = localStorage.getItem("city");
  8. if(local_city){
  9. //已经定位
  10. }else{
  11. //还未定位
  12. getAddress();
  13. }
  14. checkToken();
  15. $('#back').click(function() {
  16. // window.webkit.messageHandlers.PopRootMessageHandler.postMessage({name:"1"});
  17. if (document.referrer.includes('fund_h5_api.html')) {
  18. window.location.href = document.referrer;
  19. } else {
  20. redirectToFailedReturnUrl('', 'failed', 1020, '退出公积金查询页');
  21. }
  22. });
  23. $('.current-city').click(function() {
  24. var flag = false;
  25. var cityName = $('.current-city span').text();
  26. var cityCode = $('.current-city span').attr('data-code');
  27. tips.find(function(item, index) {
  28. if(item.region == $('.current-city span').text()){
  29. flag = true;
  30. if (document.referrer.includes('&name=')) {
  31. window.location.href = document.referrer.replace(/&name=[^&]+&code=[^&]+/, '&name=' + cityName + '&code=' + cityCode);
  32. } else {
  33. window.location.href = './fund_h5_api.html?token=' + token + '&name=' + cityName + '&code=' + cityCode;
  34. }
  35. // window.location.href = './fund_h5_api.html?token=' + token + '&name=' + cityName + '&code=' + cityCode;
  36. }
  37. })
  38. if(!flag){
  39. window.location.href="no_open_city.html?cityName=" + $('.current-city span').text();
  40. }
  41. // if (document.referrer.includes('&name=')) {
  42. // window.location.href = document.referrer.replace(/&name=[^&]+&code=[^&]+/, '&name=' + cityName + '&code=' + cityCode);
  43. // }
  44. })
  45. //function redirectToFailedReturnUrl(tid, result, failCode, reason) {
  46. // var linkString = returnUrl.includes('?') ? '&' : '?';
  47. // returnUrl += linkString + "result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason;
  48. // window.location.href = returnUrl;
  49. //}
  50. function redirectToFailedReturnUrl(tid, result, failCode, reason) {
  51. if (returnUrl.indexOf('?') < 0) {
  52. returnUrl += "?result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason;
  53. } else {
  54. returnUrl += "&result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason;
  55. }
  56. window.sessionStorage.clear();
  57. window.location.href = returnUrl;
  58. }
  59. function showMsg(msg) {
  60. var msgBox = $('.alert-info');
  61. msgBox.children('p').text(msg);
  62. msgBox.show();
  63. setTimeout(function() {
  64. msgBox.hide();
  65. }, 30000);
  66. }
  67. function checkToken() {
  68. var getTokenInfo = $.ajax({
  69. type: 'GET',
  70. url: hostUrl + '/token?token=' + token + "&time=" + Math.round(Date.now() / 1000),
  71. timeout: 30000,
  72. contentType: 'application/json;charset=utf-8'
  73. });
  74. getTokenInfo.done(function(data) {
  75. if (data.returnUrl && !returnUrl) {
  76. returnUrl = data.returnUrl;
  77. }
  78. if (data.tid && data.region && data.loginLabel && data.inputData) {
  79. window.location.href = './fund_h5_api.html?token=' + token + "&time=" + Math.round(Date.now() / 1000);
  80. return;
  81. }
  82. $('body').show();
  83. getCityListAndRender();
  84. });
  85. getTokenInfo.fail(function(err) {
  86. $('body').show();
  87. showMsg('token校验失败:' + JSON.stringify(err.responseJSON.error));
  88. });
  89. }
  90. function getCityListAndRender() {
  91. $.ajax({
  92. type: "GET",
  93. url: hostUrl + '/city_list?type=fund&sort=true&token=' + token + '&time=' + Math.round(Date.now() / 1000),
  94. contentType: 'application/json;charset=utf-8',
  95. success: function(data) {
  96. return $(".city-list").CityPicker(data);
  97. },
  98. error: function(err) {
  99. return showMsg('获取城市列表失败:' + JSON.stringify(err.responseJSON.error));
  100. }
  101. });
  102. }
  103. //自动获取地址
  104. function getAddress () {
  105. var code = '';
  106. var map = new BMap.Map("allmap");
  107. var point = new BMap.Point(116.331398,39.897445);
  108. map.centerAndZoom(point,12);
  109. var geolocation = new BMap.Geolocation();
  110. // 开启SDK辅助定位
  111. geolocation.enableSDKLocation();
  112. geolocation.getCurrentPosition(function(r){
  113. if(this.getStatus() == BMAP_STATUS_SUCCESS){
  114. var mk = new BMap.Marker(r.point);
  115. map.addOverlay(mk);
  116. map.panTo(r.point);
  117. // alert('您的位置:'+r.point.lng+','+r.point.lat);
  118. // alert(r.address.city)
  119. addressName = r.address.city;
  120. localStorage.setItem("city",addressName);
  121. }
  122. else {
  123. // alert('failed'+this.getStatus());
  124. }
  125. //页面首次定位渲染
  126. if (addressName.indexOf("市") != -1) {
  127. addressName = addressName.replace('市', '');
  128. console.log(addressName)
  129. tips.find(function(item, index) {
  130. if(item.region == addressName){
  131. $('.current-city span').text(addressName).attr('data-code', item.regionCode);
  132. }
  133. })
  134. }
  135. });
  136. }