97 lines
3.2 KiB
JavaScript
97 lines
3.2 KiB
JavaScript
var xhr;
|
|
$("#districtName").bind("input propertychange keyup" , function () {
|
|
var keyword = $(this).val()
|
|
if(xhr){
|
|
xhr.abort()
|
|
}
|
|
if(keyword == ""){
|
|
$('#districtList').empty()
|
|
return
|
|
}
|
|
xhr = $.ajax({
|
|
url:'../auto/district',
|
|
data:{keywords : keyword, cityName:$("#input_city").text(),max:20},
|
|
dataType:'json',
|
|
success:function (data){
|
|
$('#searchHistoryDiv').hide();
|
|
if(data.length == 0){
|
|
$("#notFound").show()
|
|
$('#districtList').empty();
|
|
}else{
|
|
$("#notFound").hide()
|
|
var html = $('<ul>')
|
|
$(data).each(function () {
|
|
var li = $('<li>').attr("data-region", this.district).attr("data-name", this.name).attr("data-addr", this.address).attr("data-cityAddress", this.city)
|
|
li.append('<a class="item-link item-content close-popup"><div class="item-inner"><div class="item-title-row"><div class="item-title">' + this.name + '<br><small>' + this.city + this.district + this.address + '</small></div></div></div></a>')
|
|
html.append(li)
|
|
})
|
|
$('#districtList').empty().html(html)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
function saveHistory(district) {
|
|
var history = recover()
|
|
var keys = []
|
|
var newHistory = []
|
|
newHistory.push(district)
|
|
keys.push(district.city + "#" + district.region + "#" + district.name)
|
|
for(var i = 0; i < history.length; i++){
|
|
var key = history[i].city + "#" +history[i].region + "#" + history[i].name
|
|
if($.inArray(key, keys) > -1){
|
|
continue
|
|
}
|
|
if(newHistory.length < 5){
|
|
keys.push(key)
|
|
newHistory.push(history[i])
|
|
}else{
|
|
break
|
|
}
|
|
}
|
|
$.cookie('history',JSON.stringify(newHistory) ,{ expires: 7})
|
|
}
|
|
|
|
function recover() {
|
|
var history = $.cookie('history')
|
|
if(history == undefined || history == ''){
|
|
return new Array()
|
|
}
|
|
return JSON.parse(history)
|
|
}
|
|
/* 弹出搜索小区页面 */
|
|
$("body").delegate(".open-about02", "click", function () {
|
|
$("#districtName").val("");
|
|
if($("#input_city").text()==""){
|
|
$.toast("请选择城市")
|
|
return false;
|
|
}
|
|
$('#searchHistoryDiv').show();
|
|
$("#notFound").hide();
|
|
addHistory();
|
|
$.popup(".popup-about02")
|
|
$("input").blur()
|
|
});
|
|
function addHistory(){
|
|
var history = recover()
|
|
if(history.length>0){
|
|
var ul = '<ul>'
|
|
$(history).each(function(){
|
|
ul += '<li data-region="'+this.district+'" data-cityAddress="'+this.city+'" data-name="'+this.name+'" data-addr="'+this.address+'"><a class="item-link item-content close-popup"><div class="item-inner"><div class="item-title-row"><div class="item-title"><font>'+this.name+'</font><br><small>'+this.city+this.district+this.address+'</small></div></div></div></a></li>';
|
|
})
|
|
ul += '</ul>'
|
|
$('#districtList').empty().html(ul)
|
|
|
|
}else{
|
|
$("#districtList").empty();
|
|
}
|
|
}
|
|
|
|
//点击清空
|
|
$("#clearSearchHistory").click(function(){
|
|
$.cookie('history',JSON.stringify([]) ,{ expires: 7});
|
|
$("#districtList").empty();
|
|
$.popup(".popup-about02")
|
|
});
|
|
|