Myth 5 years ago
parent
commit
2027dedc0d
  1. 2
      pages/info/postProductInfo/index.js
  2. 71
      pages/list/hotel/index.js
  3. 8
      pages/list/hotel/index.wxml
  4. 20
      pages/list/hotel/index.wxss

2
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({

71
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({

8
pages/list/hotel/index.wxml

@ -10,6 +10,9 @@
<view class="hotel-type{{type==7?' active':''}}" bindtap="changeType" data-type="7">经济连锁</view>
<view class="hotel-type{{type==8?' active':''}}" bindtap="changeType" data-type="8">特色民宿</view>
</view>
<view class="sort-btn" style="{{isDistanceSort?'':'color:#333'}}">
<view bindtap="changeSort">距离排序</view>
</view>
<view bindtap="gotoDetail" data-item="{{item}}" url="/pages/info/hotelProductInfo/index?id={{item.id}}" class="hotel-item" wx:for="{{list}}">
<image mode="aspectFill" class="headimg" src="{{item.headimg}}"></image>
<view class="top-bg" wx:if="{{index<3}}">
@ -18,8 +21,11 @@
</view>
<view class="infos">
<view class="textOver">{{item.title}}</view>
<view class="address" wx:if="{{item.distance}}">{{item.address}} 距您直线距离<text>{{item.distance}}</text></view>
<view class="address" wx:else>{{item.address}}</view>
<view class="tags textOver">
<view class="tag" wx:for="{{item.display_tags}}">{{item}}</view>
<view></view>
<!-- <view class="tag" wx:for="{{item.display_tags}}">{{item}}</view> -->
<view class="price"><text>¥</text><text>{{item.price?item.price/100:0}}</text><text>起</text></view>
</view>
</view>

20
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;
@ -106,3 +105,22 @@
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;
}
Loading…
Cancel
Save