;(function($){ var date = new Date(); var day = [date.getFullYear(), date.getMonth()+1, date.getDate()].join(''); var data = { "热门城市": { "热门城市": [ { "name": "滁州", "pinyin": "chuzhou", "jianpin": "CZ", "id": 40, "longitude": "118.33455097738", "latitude": "32.2613163166" }, { "name": "马鞍山", "pinyin": "maanshan", "jianpin": "MAS", "id": 46, "longitude": "118.51343159137", "latitude": "31.676774312087" }, { "name": "芜湖", "pinyin": "wuhu", "jianpin": "WH", "id": 49, "longitude": "118.43950958846", "latitude": "31.358522633769" }, { "name": "北京", "pinyin": "beijing", "jianpin": "BJ", "id": 52, "longitude": "116.41400898991", "latitude": "39.909889042261" }, { "name": "福州", "pinyin": "fuzhou", "jianpin": "FZ", "id": 53, "longitude": "119.30292109336", "latitude": "26.080029827495" }, { "name": "厦门", "pinyin": "xiamen", "jianpin": "SM", "id": 60, "longitude": "118.09576941887", "latitude": "24.485350152487" }, { "name": "兰州", "pinyin": "lanzhou", "jianpin": "LZ", "id": 62, "longitude": "103.84077990818", "latitude": "36.067158964679" }, { "name": "广州", "pinyin": "guangzhou", "jianpin": "GZ", "id": 76, "longitude": "113.27095203326", "latitude": "23.134881587274" }, { "name": "深圳", "pinyin": "shenzhen", "jianpin": "SZ", "id": 77, "longitude": "114.06438666378", "latitude": "22.549870128595" }, { "name": "东莞", "pinyin": "dongguan", "jianpin": "DG", "id": 79, "longitude": "113.75837841227", "latitude": "23.026366089175" }, { "name": "佛山", "pinyin": "foshan", "jianpin": "FS", "id": 80, "longitude": "113.12792121913", "latitude": "23.02762843133" }, { "name": "清远", "pinyin": "qingyuan", "jianpin": "QY", "id": 87, "longitude": "113.06257345047", "latitude": "23.687544261472" }, { "name": "南宁", "pinyin": "nanning", "jianpin": "NN", "id": 97, "longitude": "108.37309226198", "latitude": "22.822692589982" }, { "name": "桂林", "pinyin": "guilin", "jianpin": "GL", "id": 98, "longitude": "110.18647205125", "latitude": "25.240308683359" }, { "name": "柳州", "pinyin": "liuzhou", "jianpin": "LZ", "id": 107, "longitude": "109.43518753266", "latitude": "24.332023662303" }, { "name": "贵阳", "pinyin": "guiyang", "jianpin": "GY", "id": 111, "longitude": "106.63657651326", "latitude": "26.653934849609" }, { "name": "海口", "pinyin": "haikou", "jianpin": "HK", "id": 120, "longitude": "110.20475621633", "latitude": "20.050550152912" }, { "name": "三亚", "pinyin": "sanya", "jianpin": "SY", "id": 121, "longitude": "109.51821479411", "latitude": "18.259400989577" }, { "name": "石家庄", "pinyin": "shijiazhuang", "jianpin": "SJZ", "id": 138, "longitude": "114.52126244918", "latitude": "38.048312580145" }, { "name": "郑州", "pinyin": "zhengzhou", "jianpin": "ZZ", "id": 149, "longitude": "113.63190945235", "latitude": "34.752367844704" }, { "name": "武汉", "pinyin": "wuhan", "jianpin": "WH", "id": 180, "longitude": "114.31188771541", "latitude": "30.59950576133" }, { "name": "宜昌", "pinyin": "yichang", "jianpin": "YC", "id": 195, "longitude": "111.29289434571", "latitude": "30.698123535118" }, { "name": "恩施", "pinyin": "enshi", "jianpin": "ES", "id": 196, "longitude": "109.48611464938", "latitude": "30.300837723602" }, { "name": "长沙", "pinyin": "changsha", "jianpin": "CS", "id": 197, "longitude": "112.9840000000", "latitude": "28.1981330000" }, { "name": "长春", "pinyin": "changchun", "jianpin": "ZC", "id": 211, "longitude": "125.3299127338", "latitude": "43.8234901838" }, { "name": "吉林", "pinyin": "jilin", "jianpin": "JL", "id": 212, "longitude": "125.3321012405", "latitude": "43.903297321401" }, { "name": "南京", "pinyin": "nanjing", "jianpin": "NJ", "id": 220, "longitude": "118.8032602297", "latitude": "32.06521452163" }, { "name": "苏州", "pinyin": "suzhou", "jianpin": "SZ", "id": 221, "longitude": "120.59231479697", "latitude": "31.303139288449" }, { "name": "无锡", "pinyin": "wuxi", "jianpin": "WX", "id": 222, "longitude": "120.31832467714", "latitude": "31.497459740393" }, { "name": "常州", "pinyin": "changzhou", "jianpin": "CZ", "id": 223, "longitude": "119.98057041974", "latitude": "31.817147201467" }, { "name": "淮安", "pinyin": "huaian", "jianpin": "HA", "id": 224, "longitude": "119.11961792343", "latitude": "33.557330479264" }, { "name": "泰州", "pinyin": "taizhou", "jianpin": "TZ", "id": 228, "longitude": "119.92936751944", "latitude": "32.461760217421" }, { "name": "徐州", "pinyin": "xuzhou", "jianpin": "XZ", "id": 229, "longitude": "117.29054913081", "latitude": "34.212003462231" }, { "name": "扬州", "pinyin": "yangzhou", "jianpin": "YZ", "id": 231, "longitude": "119.41952048323", "latitude": "32.399931440921" }, { "name": "南昌", "pinyin": "nanchang", "jianpin": "NC", "id": 233, "longitude": "115.86460940502", "latitude": "28.68923730347" }, { "name": "沈阳", "pinyin": "shenyang", "jianpin": "SY", "id": 244, "longitude": "123.47160598452", "latitude": "41.683015674477" }, { "name": "大连", "pinyin": "dalian", "jianpin": "DL", "id": 245, "longitude": "121.62121686486", "latitude": "38.920431693692" }, { "name": "呼和浩特", "pinyin": "huhehaote", "jianpin": "HHHT", "id": 258, "longitude": "111.75648004336", "latitude": "40.848350434159" }, { "name": "包头", "pinyin": "baotou", "jianpin": "BT", "id": 261, "longitude": "109.95998290287", "latitude": "40.627217599847" }, { "name": "济南", "pinyin": "jinan", "jianpin": "JN", "id": 283, "longitude": "117.12669946477", "latitude": "36.656845988343" }, { "name": "青岛", "pinyin": "qingdao", "jianpin": "QD", "id": 284, "longitude": "120.389168761", "latitude": "36.072997005064" }, { "name": "潍坊", "pinyin": "weifang", "jianpin": "WF", "id": 296, "longitude": "119.16836971762", "latitude": "36.712609725246" }, { "name": "太原", "pinyin": "taiyuan", "jianpin": "TY", "id": 300, "longitude": "112.55548386894", "latitude": "37.876311354522" }, { "name": "西安", "pinyin": "xian", "jianpin": "XA", "id": 311, "longitude": "108.94630318582", "latitude": "34.347408573377" }, { "name": "宝鸡", "pinyin": "baoji", "jianpin": "BJ", "id": 313, "longitude": "107.24416660315", "latitude": "34.369371877544" }, { "name": "渭南", "pinyin": "weinan", "jianpin": "WN", "id": 317, "longitude": "109.47760480506", "latitude": "34.526464078659" }, { "name": "咸阳", "pinyin": "xianyang", "jianpin": "XY", "id": 318, "longitude": "108.71571334807", "latitude": "34.335592252772" }, { "name": "上海", "pinyin": "shanghai", "jianpin": "SH", "id": 321, "longitude": "121.48012477894", "latitude": "31.236436468353" }, { "name": "成都", "pinyin": "chengdu", "jianpin": "CD", "id": 322, "longitude": "104.07332829354", "latitude": "30.578846410852" }, { "name": "拉萨", "pinyin": "lasa", "jianpin": "LS", "id": 344, "longitude": "91.178646531585", "latitude": "29.658306578024" }, { "name": "昌都", "pinyin": "changdu", "jianpin": "CD", "id": 346, "longitude": "97.178530828549", "latitude": "31.146938534234" }, { "name": "林芝", "pinyin": "linzhi", "jianpin": "LZ", "id": 347, "longitude": "94.367930881886", "latitude": "29.655285461081" }, { "name": "日喀则", "pinyin": "rikaze", "jianpin": "RKZ", "id": 349, "longitude": "88.887053496743", "latitude": "29.272999180688" }, { "name": "山南", "pinyin": "shannan", "jianpin": "SN", "id": 350, "longitude": "91.779663223748", "latitude": "29.243096769018" }, { "name": "昆明", "pinyin": "kunming", "jianpin": "KM", "id": 367, "longitude": "102.83944374228", "latitude": "24.885803565909" }, { "name": "杭州", "pinyin": "hangzhou", "jianpin": "HZ", "id": 383, "longitude": "120.21628112272", "latitude": "30.252922254307" }, { "name": "金华", "pinyin": "jinhua", "jianpin": "JH", "id": 386, "longitude": "119.65379284323", "latitude": "29.084870280508" }, { "name": "宁波", "pinyin": "ningbo", "jianpin": "NB", "id": 388, "longitude": "121.62891301244", "latitude": "29.866336916566" }, { "name": "绍兴", "pinyin": "shaoxing", "jianpin": "SX", "id": 389, "longitude": "120.58689111765", "latitude": "30.036000358853" }, { "name": "重庆", "pinyin": "chongqing", "jianpin": "ZQ", "id": 394, "longitude": "106.55820825964", "latitude": "29.56855527991" }, { "name": "合肥", "pinyin": "hefei", "jianpin": "HF", "id": 3401, "longitude": "117.23377686516", "latitude": "31.826310555924" } ] } }; var extData = ; // 新增东南亚地区 var style = '.pop_city_box {position: absolute;top: 0;left: 0;z-index: 9998;display: none;padding: 10px;width: 25px;border: 1px solid #ccc;border-radius: 2px;background: #fff;box-shadow: 0 5px 15px -5px rgba(0,0,0,.5);color: #404040;text-align: left;font-size: 13px;font-family: Microsoft YaHei}.pop_city_head {padding-bottom: 5px}.pop_city_head span {display: inline-block;width: 55px;text-align: center;cursor: pointer}.pop_city_head span:first-child {margin-right: 10px;text-align: left}.pop_city_head span.on {color: #f90;font-weight: 700}.pop_city_body_content {display: block;display: none}.pop_city_body_content:first-child {display: block}.pop_city_body_content p {margin: 0;line-height: 1.6em}.pop_city_body_content p strong {display: block;font-weight: 700;line-height: 1.8em}.pop_city_body_content p strong.special {display: inline-block;margin-right: 14px}.pop_city_body_content p span {display: inline-block;width: 85px;line-height: 1.8em;cursor: pointer}.pop_city_body_content p span:hover {font-weight: 700}.pop_city_box {padding: 12px 2px 10px 20px;width: 600px;border: none;border-radius: 0;box-shadow: 0 0 16px 2px rgba(0,0,0,.2)}.pop_city_title {margin-right: 18px;height: 32px;border-bottom: 1px solid #eee}.pop_city_title span {position: relative;float: left;margin-left: 32px;padding: 5px 0;color: #666;font-weight: 500;font-size: 14px;line-height: 20px;cursor: pointer;}.pop_city_title span:first-child {margin-right: 0;margin-left: 0}.pop_city_title span.active {color: #207bee;font-weight: 700}.pop_city_title span.active:after {content: "";position: absolute;left: 0;bottom: -2px;width: 100%;height: 2px;background: #207bee;}.pop_city_title .tips {position: absolute;right: -28px;top: 0;padding: 0 3px;font-size: 10px;line-height: 14px;color: #fff;background: #ffb300;border-radius: 2px;}.pop_city_head {padding: 12px 0 6px 0;}.pop_city_head span {float: left;width: auto;margin-left: 12px;padding: 0 4px;font-size: 13px;color: #666;font-weight: normal;line-height: 20px;border-radius: 2px;}.pop_city_head span:first-child {margin: 0;}.pop_city_head span.on {font-weight: normal;color: #fff;background: #207bee;}.pop_city_body {padding: 10px 0 0 0}.pop_city_body_content p {position: relative;padding-left: 38px;line-height: 20px}.pop_city_body_content p strong {position: absolute;top: 0;left: 0;color: #ffb300;font-weight: 700;font-size: 14px;line-height: 22px}.pop_city_body_content p span {overflow: hidden;margin: 0 2px 10px 0;width: 85px;vertical-align: top;text-overflow: ellipsis;white-space: nowrap;font-size: 14px;line-height: 20px}.pop_city_body_content p span:hover {color: #207bee;font-weight: 400}.pop_city_body .pop_city_body_content:first-child p {padding-left: 0}.pop_city_body .pop_city_body_content:first-child span {width: 80px}.pop_city_body .pop_city_body_content:first-child strong.special {position: relative;margin-right: 2px;width: 88px;vertical-align: top;font-weight: 400;font-size: 14px;line-height: 20px}/*20181023 edit pop_city*/.pop_city_body .pop_city_body_content:first-child p {padding-left: 56px;}.pop_city_body .pop_city_body_content:first-child p strong {line-height: 20px;}.foreign-country .pop_city_body_content p, .foreign-country .pop_city_body_content:first-child p {padding-left: 96px;}.pop_city_body .pop_city_body_content p span:last-child {width: auto;}.pop_city_head { display: none; }'; var cityList = { '国内城市': data }; // 新加type=no_overseas,没有海外城市 var cityListNoOverseas = { '国内城市': JSON.parse(JSON.stringify(data)) } for (var key in extData) { cityList[key] = extData[key]; } // 没有国内所需要删除的城市名称数组 var noOverseas = ['香港','澳门','台湾']; window.cityListData = [ {label: "国内城市", value: 1, children: JSON.parse(JSON.stringify(data))}, {label: "海外城市", value: 2, children: JSON.parse(JSON.stringify(extData))} ]; // 构建弹层DOM function build_dom(attr, callback, $that, type) { if(type === 'no_overseas'){ if(cityListNoOverseas['国内城市']['热门城市'] && cityListNoOverseas['国内城市']['热门城市']['港澳台']){ delete cityListNoOverseas['国内城市']['热门城市']['港澳台'] } // 遍历删除国内所需要删除的城市名称数组 for(let key in cityListNoOverseas['国内城市']){ for(let tagName in cityListNoOverseas['国内城市'][key]){ for(let i = 0; i < cityListNoOverseas['国内城市'][key][tagName].length; i++){ if(noOverseas.indexOf(cityListNoOverseas['国内城市'][key][tagName][i].name) !== -1){ cityListNoOverseas['国内城市'][key][tagName].splice(i, 1) } } } } } var jdom_id = '#'+attr.id, $find = $(jdom_id); var item_click_callback = function(event){ var $span = $(this), item = $span.data(); event.stopPropagation(); if (typeof callback == 'function') callback(item.id, item, $that); $that.text(item.name).val(item.name); $that.data('city_name', item.name); if (item.url) { $that.data('url', item.url); } if (item.id) { $that.data('city_id', item.id); } return $(jdom_id).hide() && false; }; if ($find.get(0)) { $find.find('.pop_city_body_content p span') // 第二次绑定 .unbind('click').click(item_click_callback); return $find; } /*var $style = $(''); var $dom = $('
').attr(attr).attr('class', 'pop_city_box'); var $title = $('
').attr('class', 'pop_city_title clearfix'); var $main = $('
').attr('class', 'pop_city_main'); // 渲染每一栏目dom结构, 例如 A: [{xx: xx}] var contentItemEach = function(data){ var $content = $('
').attr('class', 'pop_city_body_content'); $.each(data, function(letter, list){ var $block = $('

'); $block.append($('').text(letter)); $.each(list, function(i, data){ var $span = $('').text(data.name).data(data); $span.on('click', item_click_callback); $block.append($span); }); $content.append($block); }); return $content; }; // 如果是海外城市使用cityListNoOverseas // 如果再有新的定制,考虑把后面的抽出去 $.each((type === 'no_overseas' ? cityListNoOverseas : cityList), function(key, data) { var $countryItem = $('

').attr('class', 'pop_city_item'); var $head = $('
').attr('class', 'pop_city_head clearfix'); // 字母分类 var $body = $('
').attr('class', 'pop_city_body'); var $tabHtml = (key === '东南亚地区') ? key + 'NEW' : key; // 加个tips var $tab = $('').html($tabHtml); // 国家分类 $title.append($tab); if (key === '国内城市') { $.each(data, function(head, item){ var $head_span = $('').text(head); $head.append($head_span); $body.append(contentItemEach(item)); $countryItem.append($head).append($body); // letter tab click $head_span.on('click', function(event){ event.stopPropagation(); var $curr = $(this), index = $curr.index(); var $find = $curr.parents('.pop_city_item').find('.pop_city_body_content'); // var $find = $curr.parents(jdom_id).find('.pop_city_body_content'); $curr.addClass('on').siblings('.on').removeClass('on'); $find.hide().eq(index).show(); return false; }); }); } else { $body.append(contentItemEach(data)); $body.addClass('foreign-country'); $countryItem.append($body); } $main.append($countryItem); $tab.on('click', function(event) { event.stopPropagation(); var $curr = $(this), index = $curr.index(); var $targetDom = $curr.parents(jdom_id).find('.pop_city_item'); $curr.addClass('active').siblings('.active').removeClass('active'); $targetDom.hide().eq(index).show(); return false; }) }); $dom.append($title).append($main); // 默认选中第一个 Tab var $firstCountryTab = $dom.find('.pop_city_title span').first(); var $firstLetterTab = $dom.find('.pop_city_head > span').first(); $firstCountryTab.trigger('click'); $firstLetterTab.trigger('click'); // 热门城市 // var $firstBody = $dom.find('.pop_city_body_content').first(); // var $firstStrong = $firstBody.find('strong').first(); // // 默认处理 // if ($firstStrong.text() == '热门城市') { // // 隐藏第一个标题 // $firstStrong.hide(); // // 最后一个标题加特殊样式 // $firstBody.find('strong').last().addClass('special'); // } $('body').append($style).append($dom); return $dom.hide(); } $.fn.extend({ popCity: function(args, type=null) { var $objs = this; var dom_id = 'pop_city_dialog'+day; // 海外城市独立domId if (type === 'no_overseas') { dom_id += 'no_overseas' } var option = {}; $(document.body).click(function(){ $('#'+dom_id).hide(); // 点击其他处关闭城市弹层 }); if (typeof args == 'function') { option = $.extend(option, {callback:args}); } if (typeof args == 'object') { option = $.extend(option, args); } return $objs.each(function(){ var $curr = $(this); $curr.on('click', function(event){ $('#hgg_selectbox').hide(); if (option.befor_run) option.befor_run(); event.stopPropagation(); var $handle = $(this), pos = $handle.offset(); var plus_height = $handle.height(); if (typeof $handle.outerHeight() == 'number') { plus_height = $handle.outerHeight(); } if (typeof plus_height == 'number') { pos.top += parseInt(plus_height); } var $target = build_dom({id: dom_id}, option.callback, $curr, type); if (pos.left + $target.outerWidth() > $(window).width()) { pos.left = pos.left - (pos.left + $target.outerWidth() - $(window).width()); } $target.css(pos); var headerPosition = $('.hgg-header-box').css('position'); var $headerLocalLink = $handle.parent().hasClass('local-city-link'); var $topDom = $('body').find('.hgg-header-box'); var DomHeight = $topDom.position(); var topDomHeight = DomHeight ? DomHeight.top : 0; var location = window.location.pathname; var locationVenue = location.indexOf('/venue') == 0; var fixedTop = locationVenue ? 40 : topDomHeight + 43; // 弹出窗带城市选择 -- 规定弹出窗必须带有dialog-has-popcity且固定 var $dialogShowPopCity = $curr.parents('.layui-layer'); var dialogzIndex = $dialogShowPopCity.css('z-index'); var dialogPositionTop = $curr.position(); if ($headerLocalLink) { $target.css({ zIndex: '10001', top: fixedTop }) headerPosition == 'static' ? $target.css('position', 'absolute') : $target.css('position', 'fixed'); } else if ($handle.parents('div').hasClass('quick-order')) { // 一键下单 var isFixed = $('.hgg-header-box').hasClass('scroll-to-fixed-fixed'); var top = isFixed ? $('.hgg-header-box').height() + 30 : $('.hgg-header-box').offset().top + $('.hgg-header-box').height() + 30; $target.css({ zIndex: '10001', top: top, position: 'fixed' }) } else if ($dialogShowPopCity.hasClass('dialog-has-popcity')) { $target.css({ position: 'fixed', zIndex: dialogzIndex + '1', }) } else if ($handle.hasClass("history_city_name")) { var top = $(window).height()/2*1 - 130; $target.css({ zIndex: '100001', position: 'fixed', top: top, }) } else { $target.css({ zIndex: '9998', position: 'absolute' }) } if (option.after_run) option.after_run($target, $(this)); $target.show(); return false; }); return this; }); } }); })(jQuery);