|
|
@@ -9,11 +9,11 @@
|
|
|
id="map"
|
|
|
:style="{ height: mapHeight }"
|
|
|
:markers="markers"
|
|
|
- :latitude="center.latitude"
|
|
|
- :longitude="center.longitude"
|
|
|
:scale="zoom"
|
|
|
+ :show-location="true"
|
|
|
@markertap="markerTap"
|
|
|
@labeltap="markerTap"
|
|
|
+ @regionchange="regionChange"
|
|
|
>
|
|
|
<div class="menus">
|
|
|
<div class="item">
|
|
|
@@ -26,8 +26,10 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
<img class="map-picker" src="/native/images/icon_picker.png" />
|
|
|
- <div class="btn-locate" @click="locate">
|
|
|
- <van-icon name="aim" />
|
|
|
+ <div class="btn-locate-wrapper" @click="locate">
|
|
|
+ <div class="btn-locate">
|
|
|
+ <van-icon name="aim" />
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</map>
|
|
|
<div class="content-container">
|
|
|
@@ -42,10 +44,10 @@
|
|
|
<van-tab title="选我预约" :name="1"></van-tab>
|
|
|
</van-tabs>
|
|
|
<div class="tab-page" :style="{ height: '180px' }">
|
|
|
- <div class="row">
|
|
|
+ <div class="row" @click="search">
|
|
|
<div class="name">
|
|
|
<div class="indicator"></div>
|
|
|
- <div class="name-content">鸡鸣寺</div>
|
|
|
+ <div class="name-content">{{ statusLabel }}</div>
|
|
|
<van-icon name="arrow" />
|
|
|
</div>
|
|
|
<!-- <div class="tip">点击可手动选择更换景区</div> -->
|
|
|
@@ -55,7 +57,7 @@
|
|
|
<div class="name-content">预约时间 6月17日 19:00</div>
|
|
|
<van-icon name="arrow" />
|
|
|
</div>
|
|
|
- <div class="row time">营业时间:09:00-18:00</div>
|
|
|
+ <div class="row time" v-if="openTime">{{ openTime.time }}</div>
|
|
|
<div class="nums">
|
|
|
可借眼镜:
|
|
|
<span class="num" style="margin-right:15px">1副</span>
|
|
|
@@ -91,15 +93,13 @@
|
|
|
|
|
|
<script>
|
|
|
import { mapState } from 'vuex';
|
|
|
+import { getDay } from 'date-fns';
|
|
|
export default {
|
|
|
name: 'home',
|
|
|
data() {
|
|
|
return {
|
|
|
mapHeight: '500px',
|
|
|
- center: {
|
|
|
- latitude: 32.00335,
|
|
|
- longitude: 118.73145
|
|
|
- },
|
|
|
+ mapCtx: null,
|
|
|
zoom: 13,
|
|
|
tab: 0,
|
|
|
locationStatus: 'loading',
|
|
|
@@ -107,28 +107,16 @@ export default {
|
|
|
showGetUserInfoDialog: false,
|
|
|
showLocationDialog: false,
|
|
|
myLocation: null,
|
|
|
- scenics: []
|
|
|
+ scenics: [],
|
|
|
+ currentScenic: null,
|
|
|
+ getScenicFlag: false,
|
|
|
+ status: 'loading'
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
...mapState(['safeAreaTop', 'safeAreaBottom']),
|
|
|
markers() {
|
|
|
let markers = [];
|
|
|
- if (this.myLocation) {
|
|
|
- markers.push({
|
|
|
- latitude: this.myLocation.latitude,
|
|
|
- longitude: this.myLocation.longitude,
|
|
|
- id: 'location',
|
|
|
- iconPath: '/native/images/icon_location.png',
|
|
|
- width: 34,
|
|
|
- height: 34,
|
|
|
- anchor: {
|
|
|
- x: 0.5,
|
|
|
- y: 0.5
|
|
|
- },
|
|
|
- rotate: this.myLocation.rotate
|
|
|
- });
|
|
|
- }
|
|
|
this.scenics.forEach(i => {
|
|
|
markers.push({
|
|
|
id: i.id,
|
|
|
@@ -137,6 +125,7 @@ export default {
|
|
|
iconPath: '/native/images/icon_dot.png',
|
|
|
width: 10,
|
|
|
height: 10,
|
|
|
+ anchor: { x: 0.5, y: 0.5 },
|
|
|
label: {
|
|
|
content: i.name,
|
|
|
color: '#07c160',
|
|
|
@@ -150,8 +139,28 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
- console.log(markers);
|
|
|
return markers;
|
|
|
+ },
|
|
|
+ statusLabel() {
|
|
|
+ switch (this.status) {
|
|
|
+ case 'success':
|
|
|
+ return this.currentScenic.name;
|
|
|
+ case 'loading':
|
|
|
+ return '正在获取附近的景区...';
|
|
|
+ case 'fail':
|
|
|
+ return '获取附近景区失败,请手动选择';
|
|
|
+ default:
|
|
|
+ return '获取附近景区失败,请手动选择';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ openTime() {
|
|
|
+ if (!this.currentScenic) return null;
|
|
|
+ const weekDay = getDay(new Date());
|
|
|
+ let i = this.currentScenic.openTime.find(i => i.weekDay === weekDay);
|
|
|
+ return {
|
|
|
+ open: i.open,
|
|
|
+ time: i.open ? `营业时间:${i.startTime} - ${i.endTime}` : '今日停业'
|
|
|
+ };
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
@@ -159,19 +168,11 @@ export default {
|
|
|
this.mapHeight = sysInfo.windowHeight - this.safeAreaBottom - 128 - 180 + 'px';
|
|
|
},
|
|
|
onShow() {
|
|
|
- this.locate();
|
|
|
- wx.startCompass();
|
|
|
- wx.onCompassChange(res => {
|
|
|
- if (this.myLocation) {
|
|
|
- this.myLocation = {
|
|
|
- ...this.myLocation,
|
|
|
- rotate: res.direction
|
|
|
- };
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- onHide() {
|
|
|
- wx.stopCompass();
|
|
|
+ console.log('onshow');
|
|
|
+ if (this.status !== 'success') {
|
|
|
+ this.locate();
|
|
|
+ }
|
|
|
+ this.mapCtx = wx.createMapContext('map', this);
|
|
|
},
|
|
|
methods: {
|
|
|
onTabChange(e) {
|
|
|
@@ -203,22 +204,34 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
locate() {
|
|
|
- console.log('locate');
|
|
|
+ wx.showLoading({
|
|
|
+ title: '定位中'
|
|
|
+ });
|
|
|
+ this.status = 'loading';
|
|
|
wx.getLocation({
|
|
|
+ type: 'gcj02',
|
|
|
success: res => {
|
|
|
- this.center = {
|
|
|
- latitude: res.latitude,
|
|
|
- longitude: res.longitude
|
|
|
- };
|
|
|
+ wx.hideLoading();
|
|
|
+ // this.center = {
|
|
|
+ // latitude: res.latitude,
|
|
|
+ // longitude: res.longitude
|
|
|
+ // };
|
|
|
this.myLocation = {
|
|
|
latitude: res.latitude,
|
|
|
- longitude: res.longitude,
|
|
|
- rotate: 0
|
|
|
+ longitude: res.longitude
|
|
|
};
|
|
|
this.getScenics(res.latitude, res.longitude);
|
|
|
+ if (this.mapCtx) {
|
|
|
+ this.mapCtx.moveToLocation({
|
|
|
+ latitude: res.latitude,
|
|
|
+ longitude: res.longitude
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
fail: e => {
|
|
|
console.log(e);
|
|
|
+ this.status = 'fail';
|
|
|
+ wx.hideLoading();
|
|
|
if (/auth deny/.test(e.errMsg)) {
|
|
|
this.showLocationDialog = true;
|
|
|
}
|
|
|
@@ -228,6 +241,16 @@ export default {
|
|
|
getScenics(latitude, longitude) {
|
|
|
this.$http.get('/scenic/nearby', { latitude, longitude }).then(res => {
|
|
|
this.scenics = res;
|
|
|
+ if (res[0]) {
|
|
|
+ this.status = 'success';
|
|
|
+ this.currentScenic = res[0];
|
|
|
+ this.mapCtx.moveToLocation({
|
|
|
+ latitude: res[0].latitude,
|
|
|
+ longitude: res[0].longitude
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.status = 'fail';
|
|
|
+ }
|
|
|
});
|
|
|
},
|
|
|
markerTap(e) {
|
|
|
@@ -235,6 +258,32 @@ export default {
|
|
|
icon: 'none',
|
|
|
title: e.detail.markerId + ''
|
|
|
});
|
|
|
+ },
|
|
|
+ regionChange(e) {
|
|
|
+ if (e.type === 'end' && e.causedBy === 'drag') {
|
|
|
+ this.mapCtx.getCenterLocation({
|
|
|
+ success: res => {
|
|
|
+ this.status = 'loading';
|
|
|
+ this.getScenics(res.latitude, res.longitude);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ search() {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/search',
|
|
|
+ events: {
|
|
|
+ choose: data => {
|
|
|
+ console.log(data);
|
|
|
+ console.log(this.currentScenic);
|
|
|
+ this.currentScenic = data;
|
|
|
+ this.status = 'success';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ success: res => {
|
|
|
+ res.eventChannel.emit('location', this.myLocation);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
@@ -280,20 +329,24 @@ export default {
|
|
|
bottom: 34px;
|
|
|
margin: auto;
|
|
|
}
|
|
|
-.btn-locate {
|
|
|
- color: @text2;
|
|
|
- font-size: 18px;
|
|
|
- width: 30px;
|
|
|
- height: 30px;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- justify-content: center;
|
|
|
+.btn-locate-wrapper {
|
|
|
position: absolute;
|
|
|
- right: 15px;
|
|
|
- bottom: 15px;
|
|
|
- background: white;
|
|
|
- border-radius: 4px;
|
|
|
+ right: 0;
|
|
|
+ bottom: 0;
|
|
|
+ padding: 15px;
|
|
|
+ .btn-locate {
|
|
|
+ color: @text2;
|
|
|
+ font-size: 18px;
|
|
|
+ width: 30px;
|
|
|
+ height: 30px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ background: white;
|
|
|
+ border-radius: 4px;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
.content-container {
|
|
|
background: white;
|
|
|
.flex-col();
|