From 6f56c953848bd890d3f12df622cc685d9ad68f92 Mon Sep 17 00:00:00 2001 From: "xuhe@fangjia.com" Date: Tue, 3 Apr 2018 16:05:00 +0800 Subject: [PATCH] aa --- fangija-zsyf/js/searchDistrict-add.js | 179 ++++++++++++++++++ .../js/updateVersion/searchDistrict-app.js | 176 +++++++++++++++++ 2 files changed, 355 insertions(+) create mode 100644 fangija-zsyf/js/searchDistrict-add.js create mode 100644 fangija-zsyf/js/updateVersion/searchDistrict-app.js diff --git a/fangija-zsyf/js/searchDistrict-add.js b/fangija-zsyf/js/searchDistrict-add.js new file mode 100644 index 0000000..fb6a808 --- /dev/null +++ b/fangija-zsyf/js/searchDistrict-add.js @@ -0,0 +1,179 @@ +var xhr; +var searchDistVue = new Vue({ + el: '#searchList', + data: { + searchDistricts: [] + },methods: { + openDistrictDetail:function(index) { + saveHistory({district:this.searchDistricts[index].region,name:this.searchDistricts[index].name,city:this.searchDistricts[index].city}) + $("#input_address").val(this.searchDistricts[index].name); + $("[name=region]").val(this.searchDistricts[index].region) + $("[name=name]").val(this.searchDistricts[index].name) + $("[name=cityAddress]").val(this.searchDistricts[index].city) + $("[name=address]").val(this.searchDistricts[index].address) + $.popup(".popup-about02") + } + } +}) + +$("#districtName").bind("input propertychange keyup" , function () { + var keyword = $(this).val() + if(xhr){ + xhr.abort() + } + if(keyword == ""){ + // $('.searchList #searchList').empty() + return + } + + axios.get(BASE_PATH+"/rest/districts/search", { + params: { + keywords : keyword, + cityName:$("#input_city").val(), + max:20 + } + }).then(function (response) { + + var datas = response.data.data + + $('.hotList').hide(); + $('.historyList').hide(); + if(datas == null || datas.length == 0){ + $("#notFound").show() + searchDistVue.$data.searchDistricts = [] + //$('.searchList #searchList').empty(); + }else{ + $("#notFound").hide() + var dists = []; + for(var i in datas){ + var o = datas[i] + var map={city:o.city, region:o.district, name:o.name,address:o.address}; + dists.push(map); + } + //searchDistVue.$set("searchDistricts") = dists; + searchDistVue.$data.searchDistricts=dists + $('.searchList').show(); + } + }).catch(function (error) { + alert(error) + console.log(error); + }); + +}) + +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}) + localStorage.setItem("history", JSON.stringify(newHistory)); +} + +function recover() { + //var history = $.cookie('history') + var history = localStorage.getItem('history'); + if(history == undefined || history == ''){ + return new Array() + } + return JSON.parse(history) +} +/* 弹出搜索小区页面 */ +$("body").delegate(".open-about02", "click", function () { + $("#districtName").val(""); + if($("#input_city").val()==""){ + $.toast("请选择城市") + return false; + } + $('.historyList').show(); + $("#notFound").hide(); + $('.hotList').show(); + $('.searchList').hide(); + addHotDistricts($("#input_city").val()); + addHistory(); + $.popup(".popup-about02") + $("input").blur() +}); + +//添加热门小区 +function addHotDistricts(cityParam){ + axios.get(BASE_PATH+"/rest/districts/hotDistricts", { + params: { + city: cityParam, + top:6 + } + }).then(function (response) { + var datas = response.data.data + if(datas.length>0){ + var dists = []; + for(var i in datas){ + + var o = datas[i] + var map={city:o.city, region:o.region, name:o.name}; + dists.push(map); + } + + new Vue({ + el: '#hotList', + data: { + hotDists: dists + } + }) + + } + + }).catch(function (error) { + alert(error) + console.log(error); + }); +} +var histories = []; +var historyVue = new Vue({ + el: '#districtList', + data: { + histories: histories + },methods: { + openHistoryDetail:function(index) { + $("#input_address").val(this.histories[index].name); + $("[name=region]").val(this.histories[index].region); + $("[name=name]").val(this.histories[index].name); + $("[name=cityAddress]").val(this.histories[index].city); + $.popup(".popup-about02") + } + } +}) +function addHistory(){ + var history = recover() + if(history.length>0){ + histories = [] + $(history).each(function(){ + var map={city:this.city, region:this.district, name:this.name}; + histories.push(map) + }) + historyVue.histories=histories; + + + }/*else{ + $(".historyList #districtList").empty(); + }*/ +} + +//点击清空 +$("#clearSearchHistory").click(function(){ + localStorage.removeItem('history') + historyVue.histories=[]; +}); + diff --git a/fangija-zsyf/js/updateVersion/searchDistrict-app.js b/fangija-zsyf/js/updateVersion/searchDistrict-app.js new file mode 100644 index 0000000..dab006f --- /dev/null +++ b/fangija-zsyf/js/updateVersion/searchDistrict-app.js @@ -0,0 +1,176 @@ +var xhr; +var searchDistVue = new Vue({ + el: '#searchList', + data: { + searchDistricts: [] + },methods: { + openDistrictDetail:function(index) { + saveHistory({district:this.searchDistricts[index].region,name:this.searchDistricts[index].name,city:this.searchDistricts[index].city}) + clicked(BASE_PATH+'/district/details?city='+this.searchDistricts[index].city+'®ion='+this.searchDistricts[index].region+'&name='+this.searchDistricts[index].name,true); + } + } +}) + +$("#districtName").bind("input propertychange keyup" , function () { + var keyword = $(this).val() + if(xhr){ + xhr.abort() + } + if(keyword == ""){ + // $('.searchList #searchList').empty() + return + } + + axios.get(BASE_PATH+"/rest/districts/search", { + params: { + keywords : keyword, + cityName:$("#input_city").text(), + max:20 + } + }).then(function (response) { + + var datas = response.data.data + + $('.hotList').hide(); + $('.historyList').hide(); + if(datas == null || datas.length == 0){ + $("#notFound").show() + searchDistVue.$data.searchDistricts = [] + //$('.searchList #searchList').empty(); + }else{ + + console.log(keyword +" "+datas.length); + $("#notFound").hide() + var dists = []; + for(var i in datas){ + var o = datas[i] + var map={city:o.city, region:o.district, name:o.name,address:o.address}; + dists.push(map); + } + + //searchDistVue.$set("searchDistricts") = dists; + searchDistVue.$data.searchDistricts=dists + $('.searchList').show(); + } + }).catch(function (error) { + alert(error) + console.log(error); + }); + +}) + +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}) + localStorage.setItem("history", JSON.stringify(newHistory)); +} + +function recover() { + //var history = $.cookie('history') + var history = localStorage.getItem('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; + } + $('.historyList').show(); + $("#notFound").hide(); + $('.hotList').show(); + $('.searchList').hide(); + addHotDistricts($("#input_city").text()); + addHistory(); + $.popup(".popup-about02") + $("input").blur() +}); + +//添加热门小区 +function addHotDistricts(cityParam){ + axios.get(BASE_PATH+"/rest/districts/hotDistricts", { + params: { + city: cityParam, + top:6 + } + }).then(function (response) { + var datas = response.data.data + if(datas.length>0){ + var dists = []; + for(var i in datas){ + + var o = datas[i] + var map={city:o.city, region:o.region, name:o.name}; + dists.push(map); + } + + new Vue({ + el: '#hotList', + data: { + hotDists: dists + } + }) + + } + + }).catch(function (error) { + alert(error) + console.log(error); + }); +} +var histories = []; +var historyVue = new Vue({ + el: '#districtList', + data: { + histories: histories + },methods: { + openHistoryDetail:function(index) { + clicked(BASE_PATH+'/district/details?city='+this.histories[index].city+'®ion='+this.histories[index].region+'&name='+this.histories[index].name,true); + } + } +}) +function addHistory(){ + var history = recover() + if(history.length>0){ + histories = [] + $(history).each(function(){ + var map={city:this.city, region:this.district, name:this.name}; + histories.push(map) + }) + historyVue.histories=histories; + + + }/*else{ + $(".historyList #districtList").empty(); + }*/ +} + +//点击清空 +$("#clearSearchHistory").click(function(){ + //$.cookie('history',JSON.stringify([]) ,{ expires: 7}); + localStorage.removeItem('history') + historyVue.histories=[]; + //$("#districtList").empty(); + //$.popup(".popup-about02") +}); +