|
|
@ -11,7 +11,9 @@ Page({ |
|
|
total:1, |
|
|
total:1, |
|
|
list:[], |
|
|
list:[], |
|
|
keywords:"", |
|
|
keywords:"", |
|
|
area_id:null |
|
|
area_id:null, |
|
|
|
|
|
location:null, |
|
|
|
|
|
isDistanceSort:false |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -23,7 +25,59 @@ Page({ |
|
|
area_id:options.area_id |
|
|
area_id:options.area_id |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
this.initLocation().then(res=>{ |
|
|
this.getList() |
|
|
this.getList() |
|
|
|
|
|
}).catch(err=>{ |
|
|
|
|
|
this.getList() |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
changeSort:function(){ |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
isDistanceSort:!this.data.isDistanceSort, |
|
|
|
|
|
list:[], |
|
|
|
|
|
total:1 |
|
|
|
|
|
}) |
|
|
|
|
|
if(this.data.isDistanceSort && !this.data.location){ |
|
|
|
|
|
// 如果是距离排序并且没有开启定位的话
|
|
|
|
|
|
this.initLocation().then(res=>{ |
|
|
|
|
|
this.getList() |
|
|
|
|
|
}).catch(err=>{ |
|
|
|
|
|
this.getList() |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
this.getList() |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
initLocation:function(){ |
|
|
|
|
|
let that = this; |
|
|
|
|
|
if(this.data.location){ |
|
|
|
|
|
return new Promise((resolve,reject)=>{ |
|
|
|
|
|
resolve() |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
return new Promise((resolve,reject)=>{ |
|
|
|
|
|
wx.getLocation({ |
|
|
|
|
|
type:"glc02", |
|
|
|
|
|
success:function(e){ |
|
|
|
|
|
that.setData({ |
|
|
|
|
|
location:{ |
|
|
|
|
|
lon:e.longitude, |
|
|
|
|
|
lat:e.latitude |
|
|
|
|
|
}, |
|
|
|
|
|
isDistanceSort:true |
|
|
|
|
|
}) |
|
|
|
|
|
resolve() |
|
|
|
|
|
}, |
|
|
|
|
|
fail:function(err){ |
|
|
|
|
|
// wx.showToast({
|
|
|
|
|
|
// title: '请开启定位后重试',
|
|
|
|
|
|
// icon:'none'
|
|
|
|
|
|
// })
|
|
|
|
|
|
reject() |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
}, |
|
|
}, |
|
|
search:function(e){ |
|
|
search:function(e){ |
|
|
this.setData(e.detail); |
|
|
this.setData(e.detail); |
|
|
@ -46,10 +100,19 @@ Page({ |
|
|
sort:"weight", |
|
|
sort:"weight", |
|
|
tag_id:this.data.type, |
|
|
tag_id:this.data.type, |
|
|
title:this.data.keywords, |
|
|
title:this.data.keywords, |
|
|
area_id:this.data.area_id |
|
|
area_id:this.data.area_id, |
|
|
|
|
|
lon:this.data.location?this.data.location.lon:null, |
|
|
|
|
|
lat:this.data.location?this.data.location.lat:null, |
|
|
|
|
|
sort:this.data.isDistanceSort?'distance':null, |
|
|
|
|
|
order:this.data.isDistanceSort?'asc':null |
|
|
}).then(res=>{ |
|
|
}).then(res=>{ |
|
|
res.data.list.map(item=>{ |
|
|
res.data.list.map(item=>{ |
|
|
console.log(item.third_supplier_type) |
|
|
if(item.distance>=1000){ |
|
|
|
|
|
item.distance = (item.distance/1000).toFixed(2)+"km"; |
|
|
|
|
|
} |
|
|
|
|
|
else if(item.distance){ |
|
|
|
|
|
item.distance = item.distance+'m'; |
|
|
|
|
|
} |
|
|
item.display_tags = (item.display_tags?item.display_tags.split(","):[]).splice(0,2); |
|
|
item.display_tags = (item.display_tags?item.display_tags.split(","):[]).splice(0,2); |
|
|
}) |
|
|
}) |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
|