|
|
|
// pages/reserve/search.js\
|
|
|
|
const map_key='SDEBZ-I74W4-QLGUX-XXYXU-HIR23-3QFBJ'
|
|
|
|
// 引入SDK核心类
|
|
|
|
var QQMapWX = require('../../utils/qqmap-wx-jssdk');
|
|
|
|
// 实例化API核心类
|
|
|
|
var qqmapsdk = new QQMapWX({
|
|
|
|
key:map_key // 必填
|
|
|
|
});
|
|
|
|
import util from '../../utils/util';
|
|
|
|
import App from '../../utils/api';
|
|
|
|
import PubSub from '../../utils/PubSub'
|
|
|
|
// pages/reserve/home.js
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
history:[],
|
|
|
|
suggestion:[],
|
|
|
|
hasSellerMore:false,
|
|
|
|
keyword:'',
|
|
|
|
sellerSplit:-1,
|
|
|
|
navHeight:100,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.selectComponent('#getpos').getPos();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -41,11 +26,6 @@ Page({ |
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow: function () {
|
|
|
|
PubSub.emit('custom-tab-bar')
|
|
|
|
this.getHistory();
|
|
|
|
this.setData({
|
|
|
|
navHeight:this.selectComponent('#nav').getHeight()
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
...
|
...
|
@@ -62,266 +42,43 @@ Page({ |
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
getHistory(){
|
|
|
|
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:mks
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
//在Page({})中使用下列代码
|
|
|
|
//数据回填方法
|
|
|
|
backfill: function (e) {
|
|
|
|
var id = e.currentTarget.id;
|
|
|
|
for (var i = 0; i < this.data.suggestion.length; i++) {
|
|
|
|
if (i == id) {
|
|
|
|
console.log('backfill,this.data.suggestion[i]:',this.data.suggestion[i])
|
|
|
|
// let pages = getCurrentPages();
|
|
|
|
// let p = pages[pages.length - 2];
|
|
|
|
// p.setSuggestion(this.data.suggestion[i])
|
|
|
|
//util.cache('suggestion',this.data.suggestion[i]);
|
|
|
|
this.setData({
|
|
|
|
backfill: this.data.suggestion[i].title
|
|
|
|
});
|
|
|
|
this.setSuggestion({fun:'setSuggestion',suggestion:this.data.suggestion[i]})
|
|
|
|
wx.navigateBack();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
inputVal:'',
|
|
|
|
//触发关键词输入提示事件
|
|
|
|
getsuggest: function (e) {
|
|
|
|
//调用关键词提示接口
|
|
|
|
this.inputVal=e.detail.value;
|
|
|
|
if(this.inputVal.length<1){
|
|
|
|
return this.setData({
|
|
|
|
suggestion: [],
|
|
|
|
keyword:''
|
|
|
|
})
|
|
|
|
}
|
|
|
|
let prarms={
|
|
|
|
keyword:this.inputVal,
|
|
|
|
region:this.location.city||'',
|
|
|
|
region_fix:0,
|
|
|
|
page_size:20,
|
|
|
|
page_index:1,
|
|
|
|
key:map_key,
|
|
|
|
}
|
|
|
|
if(this.location.latitude){
|
|
|
|
prarms.location=this.location.latitude+','+this.location.longitude
|
|
|
|
}
|
|
|
|
App.Customer.KeywordTips(prarms).then(res=>{
|
|
|
|
if(this.inputVal.length<1){
|
|
|
|
return this.setData({
|
|
|
|
suggestion: []
|
|
|
|
})
|
|
|
|
}
|
|
|
|
var sug = [],hasSellerMore=false,sellerSplit=-1
|
|
|
|
try{
|
|
|
|
res.data=res.data.data
|
|
|
|
if(res.data instanceof Array){
|
|
|
|
for (var i = 0; i < res.data.length; i++) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch(e){}
|
|
|
|
this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
|
|
|
|
suggestion: sug,
|
|
|
|
hasSellerMore:hasSellerMore,
|
|
|
|
keyword:this.inputVal,
|
|
|
|
sellerSplit:sellerSplit,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
},
|
|
|
|
nearby_search: function () {
|
|
|
|
App.Customer.SearchMap({
|
|
|
|
boundary:'region('+this.location.city+',1)',
|
|
|
|
//boundary:'nearby('+this.location.latitude+','+this.location.longitude+',1000,1)',
|
|
|
|
location:this.location.latitude+','+this.location.longitude,
|
|
|
|
keyword:this.inputVal,
|
|
|
|
page_size:20,
|
|
|
|
page_index:1,
|
|
|
|
orderby:'_distance',
|
|
|
|
key:map_key,
|
|
|
|
}).then(res=>{
|
|
|
|
var mks = []
|
|
|
|
for (var i = 0; i < res.data.length; i++) {
|
|
|
|
mks.push({ // 获取返回结果,放到mks数组中
|
|
|
|
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,
|
|
|
|
category:res.data[i].category,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
|
|
|
|
suggestion:mks,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
},
|
|
|
|
location:'',
|
|
|
|
onpos(e){
|
|
|
|
console.log(e);
|
|
|
|
this.location=e.detail
|
|
|
|
this.GetRecommendSellerLists()
|
|
|
|
this.getCity()
|
|
|
|
},
|
|
|
|
getCity(){
|
|
|
|
qqmapsdk.reverseGeocoder({
|
|
|
|
location:this.location,
|
|
|
|
success:(res)=>{
|
|
|
|
this.location['city']='';
|
|
|
|
if(res.status==0){
|
|
|
|
this.location['city']=res.result.ad_info.city
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
gotoList(){
|
|
|
|
wx.navigateTo({
|
|
|
|
url:util.http_build_query({
|
|
|
|
lat:this.location.latitude,
|
|
|
|
lng:this.location.longitude,
|
|
|
|
keyword:this.inputVal,
|
|
|
|
multiIndex:0,
|
|
|
|
},'./indexList')
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
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.setSuggestion({fun:'setSuggestion',suggestion:item})
|
|
|
|
this.setData({
|
|
|
|
backfill: item.title
|
|
|
|
});
|
|
|
|
wx.navigateBack();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
wx.navigateTo({
|
|
|
|
url:util.http_build_query({
|
|
|
|
id:item.id,
|
|
|
|
activeTab:'reserve',
|
|
|
|
},'./detail')
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
return{
|
|
|
|
title:'请客订包间,就上周到安排'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
historyEmpty(){
|
|
|
|
App.Customer.DelHistorySearch().then(()=>{
|
|
|
|
App.Customer.GetHistorySearch({},'clear')
|
|
|
|
this.setData({
|
|
|
|
history:[]
|
|
|
|
})
|
|
|
|
})
|
|
|
|
dispalySearchHow(){
|
|
|
|
this.selectComponent('#search-how').show();
|
|
|
|
},
|
|
|
|
clearKeyword(){
|
|
|
|
howEvent(e){
|
|
|
|
console.log('howEvent',e.detail)
|
|
|
|
//this.eventChannel.emit('findSellerData',e.detail)
|
|
|
|
this.findSellerData=e.detail
|
|
|
|
this.setData({
|
|
|
|
keyword:'',
|
|
|
|
suggestion:[],
|
|
|
|
})
|
|
|
|
},
|
|
|
|
GetRecommendSellerLists(){
|
|
|
|
if(!this.location.latitude) return;
|
|
|
|
let param={}
|
|
|
|
param={
|
|
|
|
lat:this.location.latitude,
|
|
|
|
lng:this.location.longitude
|
|
|
|
}
|
|
|
|
App.Customer.GetRecommendSellerLists(param).then(res=>{
|
|
|
|
this.setData({
|
|
|
|
rsl:res.data
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
hasGoto:false,
|
|
|
|
bindtransition(e){
|
|
|
|
console.log(e)
|
|
|
|
if('change'==e.type){
|
|
|
|
this.hasGoto=false
|
|
|
|
}
|
|
|
|
if('animationfinish'==e.type){
|
|
|
|
if(this.hasGoto && (e.detail.current+1)==this.data.rsl.length){
|
|
|
|
wx.switchTab({
|
|
|
|
url: '/pages/reserve/index'
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}else{
|
|
|
|
this.hasGoto=true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
gotoSellerDetail(e){
|
|
|
|
let url='/pages/reserve/detail?id='+e.currentTarget.id
|
|
|
|
wx.navigateTo({
|
|
|
|
url:url,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
sbtrEvent(e){
|
|
|
|
console.log(e);
|
|
|
|
if(e.detail.act=='oncall'){
|
|
|
|
this.selectComponent('#as').show(e.detail.seller);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setSuggestion(data){//只通知前页变更数据
|
|
|
|
/*
|
|
|
|
let pages = getCurrentPages();
|
|
|
|
let p = pages[pages.length - 2];
|
|
|
|
if(p.route=='pages/reserve/index'){
|
|
|
|
PubSub.emit('searchParam',data)
|
|
|
|
}else{
|
|
|
|
PubSub.emit('searchParamList',data)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
let suggestion=data.suggestion
|
|
|
|
wx.navigateTo({
|
|
|
|
url:util.http_build_query({
|
|
|
|
hasSuggestion:1,
|
|
|
|
keyword:suggestion.title,
|
|
|
|
lat:suggestion.latitude,
|
|
|
|
lng:suggestion.longitude,
|
|
|
|
centre_pos:`${suggestion.latitude},${suggestion.longitude}`,
|
|
|
|
multiIndex:0,
|
|
|
|
},'/pages/reserve/indexList')
|
|
|
|
findSellerData:e.detail
|
|
|
|
})
|
|
|
|
//setTimeout(()=>{this.getList();},0)
|
|
|
|
this.selectComponent('#search-how').hide();
|
|
|
|
},
|
|
|
|
locationEvent(e){
|
|
|
|
console.log('locationEvent',e.detail)
|
|
|
|
}
|
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|