Keine Beschreibung

choice_city.js 3.4KB

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