|
...
|
...
|
@@ -8,8 +8,6 @@ var qqmapsdk = new QQMapWX({ |
|
|
|
});
|
|
|
|
import util from '../../utils/util';
|
|
|
|
import App from '../../utils/api';
|
|
|
|
const {regeneratorRuntime} = global
|
|
|
|
const search_history_cache_key='SEARCH_HISTORY_CACHE_KEY';
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -18,13 +16,15 @@ Page({ |
|
|
|
data: {
|
|
|
|
history:[],
|
|
|
|
suggestion:[],
|
|
|
|
hasSellerMore:false,
|
|
|
|
keyword:'',
|
|
|
|
sellerSplit:-1,
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.getHistory();
|
|
|
|
this.getPos()
|
|
|
|
},
|
|
|
|
|
|
...
|
...
|
@@ -39,7 +39,7 @@ Page({ |
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow: function () {
|
|
|
|
|
|
|
|
this.getHistory();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -56,26 +56,23 @@ Page({ |
|
|
|
|
|
|
|
},
|
|
|
|
getHistory(){
|
|
|
|
let ca=util.cache(search_history_cache_key);
|
|
|
|
if(ca){
|
|
|
|
App.Customer.GetHistorySearch().then(res=>{
|
|
|
|
let mks=[]
|
|
|
|
res.data.forEach(h=>{
|
|
|
|
mks.push({ // 获取返回结果,放到mks数组中
|
|
|
|
title: h.name,
|
|
|
|
id: h.sid,
|
|
|
|
addr: '',
|
|
|
|
city: '',
|
|
|
|
district: 0,
|
|
|
|
latitude: h.latitude,
|
|
|
|
longitude: h.longitude,
|
|
|
|
type:h.type==1?-1:h.type,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
this.setData({
|
|
|
|
history:ca
|
|
|
|
history:mks
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setHistory(item){
|
|
|
|
let newca=[item];
|
|
|
|
let ca=this.data.history;
|
|
|
|
let maxL=20;
|
|
|
|
for(let i=0;i<ca.length;i++){
|
|
|
|
if(ca[i].id!=item.id){
|
|
|
|
newca.push(ca[i]);
|
|
|
|
}
|
|
|
|
if(newca.length>maxL) break;
|
|
|
|
}
|
|
|
|
util.cache(search_history_cache_key,newca);
|
|
|
|
this.setData({
|
|
|
|
history:newca,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
//在Page({})中使用下列代码
|
|
...
|
...
|
@@ -85,7 +82,6 @@ Page({ |
|
|
|
for (var i = 0; i < this.data.suggestion.length; i++) {
|
|
|
|
if (i == id) {
|
|
|
|
console.log('backfill,this.data.suggestion[i]:',this.data.suggestion[i])
|
|
|
|
this.setHistory(this.data.suggestion[i])
|
|
|
|
let pages = getCurrentPages();
|
|
|
|
let p = pages[pages.length - 2];
|
|
|
|
p.setSuggestion(this.data.suggestion[i])
|
|
...
|
...
|
@@ -97,24 +93,9 @@ Page({ |
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
backHistoryFill: function (e) {
|
|
|
|
var i = util.attr(e,'index');
|
|
|
|
let item=this.data.history[i];
|
|
|
|
console.log(item)
|
|
|
|
this.setHistory(item)
|
|
|
|
this.setData({
|
|
|
|
backfill: item.title
|
|
|
|
});
|
|
|
|
|
|
|
|
let pages = getCurrentPages();
|
|
|
|
let p = pages[pages.length - 2];
|
|
|
|
p.setSuggestion(item)
|
|
|
|
wx.navigateBack();
|
|
|
|
},
|
|
|
|
inputVal:'',
|
|
|
|
//触发关键词输入提示事件
|
|
|
|
getsuggest: function (e) {
|
|
|
|
var _this = this;
|
|
|
|
//调用关键词提示接口
|
|
|
|
this.inputVal=e.detail.value;
|
|
|
|
if(e.detail.value.length<1){
|
|
...
|
...
|
@@ -132,21 +113,27 @@ Page({ |
|
|
|
key:map_key,
|
|
|
|
}).then(res=>{
|
|
|
|
res.data=res.data.data
|
|
|
|
var sug = [];
|
|
|
|
var sug = [],hasSellerMore=false,sellerSplit=-1
|
|
|
|
for (var i = 0; i < res.data.length; i++) {
|
|
|
|
sug.push({ // 获取返回结果,放到sug数组中
|
|
|
|
title: res.data[i].title,
|
|
|
|
id: res.data[i].id,
|
|
|
|
addr: res.data[i].address,
|
|
|
|
city: res.data[i].city,
|
|
|
|
district: res.data[i].district,
|
|
|
|
latitude: res.data[i].location.lat,
|
|
|
|
longitude: res.data[i].location.lng,
|
|
|
|
type:res.data[i].type,
|
|
|
|
});
|
|
|
|
if(i==2 && res.data[i].type==-1){
|
|
|
|
hasSellerMore=true
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if((i==1 || i==2) && res.data[i-1].type==-1 && res.data[i].type!=-1){
|
|
|
|
sellerSplit=i-1
|
|
|
|
}
|
|
|
|
let item=res.data[i]
|
|
|
|
item.latitude=item.location.lat
|
|
|
|
item.longitude=item.location.lng
|
|
|
|
item.addr=item.address
|
|
|
|
item.titles=item.title.match(new RegExp('(.*)('+this.inputVal+')(.*)'))
|
|
|
|
sug.push(item);
|
|
|
|
}
|
|
|
|
_this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
|
|
|
|
suggestion: sug
|
|
|
|
this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
|
|
|
|
suggestion: sug,
|
|
|
|
hasSellerMore:hasSellerMore,
|
|
|
|
keyword:this.inputVal,
|
|
|
|
sellerSplit:sellerSplit,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
},
|
|
...
|
...
|
@@ -161,7 +148,6 @@ Page({ |
|
|
|
orderby:'_distance',
|
|
|
|
key:map_key,
|
|
|
|
}).then(res=>{
|
|
|
|
res.data=res.data.data
|
|
|
|
var mks = []
|
|
|
|
for (var i = 0; i < res.data.length; i++) {
|
|
|
|
mks.push({ // 获取返回结果,放到mks数组中
|
|
...
|
...
|
@@ -173,6 +159,7 @@ Page({ |
|
|
|
latitude: res.data[i].location.lat,
|
|
|
|
longitude: res.data[i].location.lng,
|
|
|
|
type:res.data[i].type,
|
|
|
|
category:res.data[i].category,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
|
|
...
|
...
|
@@ -227,5 +214,51 @@ Page({ |
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
gotoList(){
|
|
|
|
wx.navigateTo({
|
|
|
|
url:util.http_build_query({
|
|
|
|
lat:this.location.latitude,
|
|
|
|
lng:this.location.longitude,
|
|
|
|
keyword:this.inputVal,
|
|
|
|
multiIndex:0,
|
|
|
|
},'./indexList')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
searchItemClick(e){
|
|
|
|
//console.log('searchItemClick',e)
|
|
|
|
let item=e.detail.data
|
|
|
|
if(e.detail.act=='detail'){
|
|
|
|
if(item.type==-1){
|
|
|
|
wx.navigateTo({
|
|
|
|
url:util.http_build_query({
|
|
|
|
id:item.id,
|
|
|
|
},'./detail')
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
let pages = getCurrentPages();
|
|
|
|
let p = pages[pages.length - 2];
|
|
|
|
p.setSuggestion(item)
|
|
|
|
this.setData({
|
|
|
|
backfill: item.title
|
|
|
|
});
|
|
|
|
wx.navigateBack();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
wx.navigateTo({
|
|
|
|
url:util.http_build_query({
|
|
|
|
id:item.id,
|
|
|
|
activeTab:'reserve',
|
|
|
|
},'./detail')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
historyEmpty(){
|
|
|
|
App.Customer.DelHistorySearch().then(()=>{
|
|
|
|
App.Customer.GetHistorySearch({},'clear')
|
|
|
|
this.setData({
|
|
|
|
history:[]
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|