您好,欢迎访问陈氏家族网 |注册 下载手机客户端
检测中…

手动选择

搜索城市

`; document.body.appendChild(modal); // 确保DOM渲染完成后再更新(使用setTimeout确保DOM已渲染) setTimeout(function() { // 如果还没有定位信息,立即请求 if (!homeCurrentLocation || !homeCurrentLocation.city_id) { // 如果已经在定位中,不要重复调用 if (homeIPLocating) { console.log('弹窗打开:IP定位正在进行中,等待结果'); updateHomeLocationInfoFields(); applyHomeSubstationStatus(null, '检测中…'); return; } console.log('弹窗打开:没有定位信息,开始请求'); updateHomeLocationInfoFields(); // 先显示"检测中…" applyHomeSubstationStatus(null, '检测中…'); requestCityByIP(); return; } console.log('弹窗打开:已有定位信息', homeCurrentLocation); // 立即更新定位信息字段 updateHomeLocationInfoFields(); // 显示分站状态 if (homeSubstationStatusCache) { console.log('弹窗打开:使用缓存的分站状态'); applyHomeSubstationStatus(homeSubstationStatusCache); } else if (homeCurrentLocation.city_id > 0) { console.log('弹窗打开:请求分站状态'); homeSubstationStatusMessage = '检测中…'; applyHomeSubstationStatus(null, homeSubstationStatusMessage); fetchHomeSubstationStatus(homeCurrentLocation.city_id); } else { applyHomeSubstationStatus(null, '城市ID无效'); } }, 10); // 加载数据 loadPcSelectorData(); // 点击遮罩关闭 modal.addEventListener('click', function(e) { if (e.target === modal) { hidePcCitySelector(); } }); // 搜索框回车事件 document.getElementById('pc-city-search').addEventListener('keypress', function(e) { if (e.which === 13) { searchPcCities(); } }); }; // 加载PC端选择器数据 function loadPcSelectorData() { loadPcProvinces(); loadPcHotCities(); } function loadPcProvinces() { $.getJSON('/index.php?g=Home&m=LocationApi&a=getProvinceList', function(result){ if (result && result.success) { var select = $('#pc-province-select'); if (select.length) { var html = ''; $.each(result.data, function(_, province){ html += ''; }); select.html(html).off('change.pc').on('change.pc', function(){ loadPcCitiesByProvince(this.value); }); } } }); } function loadPcCitiesByProvince(provinceId) { var citySelect = $('#pc-city-select'); if (!provinceId) { citySelect.html(''); return; } $.getJSON('/index.php?g=Home&m=LocationApi&a=getCitiesByProvince&province_id=' + provinceId, function(result){ var html = ''; if (result && result.success) { $.each(result.data, function(_, city){ html += ''; }); } citySelect.html(html); }).fail(function(){ citySelect.html(''); }); } // 加载PC端热门城市 function loadPcHotCities() { $.getJSON('/index.php?g=Home&m=LocationApi&a=getCityList', function(result){ if (result && result.success) { var container = $('#pc-hot-cities'); if (container.length) { var html = ''; $.each(result.data.slice(0, 18), function(_, city){ html += '
' + city.city_name + '
'; }); container.html(html).off('click.hot').on('click.hot', '.pc-hot-city', function(){ selectPcCity($(this).data('id'), $(this).data('name')); }); } } }); } // 搜索PC端城市 function searchPcCities() { var keyword = $('#pc-city-search').val().trim(); var container = $('#pc-search-results'); var list = container.find('.pc-search-list'); if (!keyword) { list.empty(); container.hide(); return; } $.getJSON('/index.php?g=Home&m=LocationApi&a=searchCity&keyword=' + encodeURIComponent(keyword), function(result){ var html = ''; if (result && result.success && result.data && result.data.length) { $.each(result.data, function(_, city){ html += '
' + city.city_name + ' - ' + city.province_name + '
'; }); } else { html = '
未找到匹配的城市
'; } list.html(html).off('click.search').on('click.search', '.pc-search-item', function(){ selectPcCity($(this).data('id'), $(this).data('name')); }); container.show(); }); } // 选择PC端城市 function selectPcCity(cityId, cityName) { if (!cityId) return; $.post('/index.php?g=Home&m=LocationApi&a=setManualCity', { city_id: cityId }, function(result){ if (result && result.success && result.data) { updateCityDisplay(result.data, 'manual'); hidePcCitySelector(); alert('已切换到' + (result.data.city_name || cityName)); setTimeout(function(){ window.location.reload(); }, 800); } else { alert('城市切换失败:' + (result ? result.message : '未知错误')); } }, 'json').fail(function(){ alert('城市切换失败,请重试'); }); } function confirmPcCitySelection() { var citySelect = $('#pc-city-select'); if (!citySelect.length || !citySelect.val()) { alert('请选择城市'); return; } var cityName = citySelect.find('option:selected').text(); selectPcCity(citySelect.val(), cityName); } window.hidePcCitySelector = function() { $('#pc-city-selector').remove(); };
我要发布信息
  • 本地生活信息
copyright 2013-2113 www.chenshiwang.cn All Rights Reserved 陈氏家族网版权所有
皖ICP备2021016109号-1