Geen omschrijving

choice_city.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. var token = '';
  2. var path = '';
  3. var qs = parseQueryString(window.location.href);
  4. var cityList = [];
  5. if (qs.token) {
  6. token = qs.token;
  7. }
  8. if(qs.path){
  9. path = qs.path;
  10. }
  11. //自动唤起键盘
  12. $(".search input").trigger("click").focus()
  13. //返回上一页
  14. $("nav #back").click(function () {
  15. window.history.go(-1)
  16. })
  17. function deleteSearch () {
  18. $(".search input").val("")
  19. $(".container ul").html("")
  20. }
  21. /**
  22. * [getLoginInfo 获取城市登录信息]
  23. */
  24. function getLoginInfo() {
  25. var regionCode = $('.city-name').attr('data-code');
  26. $.ajax({
  27. type: "GET",
  28. url: BASEURL + '/city_list?type=fund&sort=true&token=' + token + '&time=' + Math.round(Date.now() / 1000),
  29. contentType: 'application/json;charset=utf-8',
  30. success: function(data) {
  31. cityList = data;
  32. return renderLoginInfo(cityList);
  33. },
  34. error: function(err) {
  35. return showMsg('获取城市信息失败:' + JSON.parse(err.responseText).error);
  36. }
  37. });
  38. }
  39. /**
  40. * [renderLoginInfo 渲染城市登录信息]
  41. * @param {[type]} cityInfo [城市登录信息]
  42. */
  43. function renderLoginInfo(cityInfo) {
  44. var bind_name = 'input';
  45. if (navigator.userAgent.indexOf("MSIE") != -1){
  46. bind_name = 'propertychange';
  47. }
  48. $(".search input").bind(bind_name, function(){
  49. var searchName = $(".search input").val().trim();
  50. var html = '';
  51. if(searchName != ""){
  52. $(".search em").css("display","block")
  53. for(key in cityInfo){
  54. if(key != "hot"){
  55. cityInfo[key].forEach(function (item,index) {
  56. if(item.region.indexOf(searchName) != -1){
  57. html += `<li data-code=${item.regionCode}>${item.region}</li>`
  58. }else if(item.pinyin.indexOf(searchName) != -1){
  59. html += `<li data-code=${item.regionCode}>${item.region}</li>`
  60. }
  61. })
  62. }
  63. }
  64. if(html != ""){
  65. $(".container ul").html(html)
  66. }else{
  67. html += `<li class="searchActive">无结果</li>`;
  68. $(".container ul").html(html)
  69. }
  70. }else{
  71. $(".search em").css("display","none")
  72. $(".container ul").html(html)
  73. }
  74. })
  75. $(".container ul").on("click", function(e) {
  76. var target = e.target;
  77. if ($(target).is("li")) {
  78. if($(target).attr("class") != "searchActive"){
  79. var city = $(target).text().trim();
  80. var code = $(target).attr('data-code');
  81. if(path == "choose_city02"){
  82. var choose_city02_data = {
  83. name: city,
  84. code: code
  85. }
  86. window.webkit.messageHandlers.CityLocationMessageHandler.postMessage(choose_city02_data);
  87. }else{
  88. if (document.referrer.indexOf('&name=') === -1) {
  89. window.location.href = './fund_h5_api.html?token=' + token + '&name=' + city + '&code=' + code;
  90. } else {
  91. window.location.href = document.referrer.replace(/&name=[^&]+&code=[^&]+/, '&name=' + city + '&code=' + code);
  92. }
  93. }
  94. }
  95. }
  96. });
  97. }
  98. /**
  99. * [showMsg 提示各种错误信息,3s后消失]
  100. */
  101. function showMsg(msg) {
  102. var msgBox = $('.alert-info');
  103. msgBox.children('p').text(msg);
  104. msgBox.show();
  105. setTimeout(function() {
  106. msgBox.hide();
  107. }, 3000);
  108. }
  109. $().ready(function () {
  110. getLoginInfo()
  111. })