No Description

choice_city.js 3.6KB

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