diff --git a/pages/info/postProductInfo/index.js b/pages/info/postProductInfo/index.js index 9a6252c..8b164be 100644 --- a/pages/info/postProductInfo/index.js +++ b/pages/info/postProductInfo/index.js @@ -28,7 +28,6 @@ Page({ onLoad: function (options) { let rect = wx.getMenuButtonBoundingClientRect(); let height = (rect.top - device.statusBarHeight) * 2 + rect.height + device.statusBarHeight; - console.log(height) this.setData({ top:height, id:options.id @@ -123,7 +122,6 @@ Page({ let that = this,height = this.data.top; let topHeight = height; wx.createSelectorQuery().select('#menus').boundingClientRect(function(rect){ - console.log(rect.top,topHeight) if(rect.top<=topHeight){ // 此时应该把menus固定在顶部 that.setData({ diff --git a/pages/list/hotel/index.js b/pages/list/hotel/index.js index 7a1da73..96e3c8b 100644 --- a/pages/list/hotel/index.js +++ b/pages/list/hotel/index.js @@ -11,7 +11,9 @@ Page({ total:1, list:[], keywords:"", - area_id:null + area_id:null, + location:null, + isDistanceSort:false }, /** @@ -23,7 +25,59 @@ Page({ area_id:options.area_id }) } - this.getList() + this.initLocation().then(res=>{ + 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){ this.setData(e.detail); @@ -46,10 +100,19 @@ Page({ sort:"weight", tag_id:this.data.type, 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=>{ 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); }) this.setData({ diff --git a/pages/list/hotel/index.wxml b/pages/list/hotel/index.wxml index abd735a..b4f9455 100644 --- a/pages/list/hotel/index.wxml +++ b/pages/list/hotel/index.wxml @@ -10,6 +10,9 @@ 经济连锁 特色民宿 + + 距离排序 + @@ -18,8 +21,11 @@ {{item.title}} + {{item.address}} 距您直线距离{{item.distance}} + {{item.address}} - {{item}} + + {{item.price?item.price/100:0}} diff --git a/pages/list/hotel/index.wxss b/pages/list/hotel/index.wxss index 921dc51..9a69d41 100644 --- a/pages/list/hotel/index.wxss +++ b/pages/list/hotel/index.wxss @@ -25,7 +25,6 @@ } .hotel-item { width: 700rpx; - height: 463rpx; background: #FFFFFF; box-shadow: -1rpx 1rpx 16rpx 0rpx rgba(6, 0, 1, 0.1); border-radius: 13rpx; @@ -105,4 +104,23 @@ display: block; left: 165rpx; top: 42rpx; +} +.sort-btn { + font-size: 28rpx; + color: #0B898E; + text-align: right; + margin: 0 30rpx; +} +.sort-btn view { + display: inline-block; +} +.address { + font-size: 28rpx; + color: #333; + margin-top: 10rpx; + font-weight: 500; +} +.address text { + color: #0B898E; + } \ No newline at end of file