Files
dvcp_v2_wxcp_app/src/saas/AppCountryAlbum/ChooseAddess.vue

386 lines
8.5 KiB
Vue
Raw Normal View History

2022-03-08 17:02:42 +08:00
<template>
<div class="Attendance-address">
2022-03-09 13:48:22 +08:00
<AiTMap
:map.sync="map"
:lib.sync="lib"
:ops="ops"
:libraries="['service', 'tools']">
</AiTMap>
2022-03-08 17:02:42 +08:00
<u-popup v-model="isShow" :closeable="false" border-radius="32" height="70%" mode="bottom">
<div class="wrapper">
<div class="top">
<span @click="isShow = false">取消</span>
<span>确定</span>
</div>
<div class="address-search">
<div class="address-search__wrapper">
<image src="./images/search.png" />
2022-03-09 13:48:22 +08:00
<input placeholder-style="color: #98A6B6" placeholder="搜索地点" v-model="address" @input="onChange">
2022-03-08 17:02:42 +08:00
</div>
</div>
2022-03-09 13:48:22 +08:00
<scroll-view scroll-y scroll-into-view="address-item1">
<div class="address-item" :id="'address-item' + index" v-for="(item, index) in addressList" :key="index" @click="chooseAddress(index)">
2022-03-08 17:02:42 +08:00
<div class="left">
2022-03-09 13:48:22 +08:00
<h2>{{ item.title }}</h2>
<p>{{ item._distance >= 0 ? item._distance + 'm内' : '未知' }} | {{ item.address }}</p>
2022-03-08 17:02:42 +08:00
</div>
<div class="right" :class="[currIndex === index ? 'active' : '']"></div>
</div>
</scroll-view>
<div class="address-btn">
<span>打卡有效范围</span>
<div class="right" @click="isShowScope = true">
2022-03-09 13:48:22 +08:00
<i>{{ distance[chooseIndex] }}</i>
2022-03-08 17:02:42 +08:00
<image src="./images/w-right.png" />
</div>
</div>
</div>
</u-popup>
<u-popup v-model="isShowScope" :closeable="false" :z-index="11111" border-radius="16" mode="bottom">
<div class="ActionSheet">
<div class="ActionSheet-list">
2022-03-09 13:48:22 +08:00
<div
@click="chooseDistance(index)"
v-for="(item, index) in distance"
:key="index"
:class="[chooseIndex === index ? 'active' : '']">
{{ item }}
</div>
2022-03-08 17:02:42 +08:00
</div>
<div class="cancel-btn" @click="isShowScope = false">取消</div>
</div>
</u-popup>
</div>
</template>
<script>
2022-03-09 13:48:22 +08:00
import { mapState } from 'vuex'
2022-03-08 17:02:42 +08:00
export default {
name: 'ChooseAddess',
appName: '选择打卡点',
data () {
return {
latitude: '',
longitude: '',
isShow: false,
address: '',
currIndex: 0,
2022-03-09 13:48:22 +08:00
chooseIndex: 0,
isShowScope: false,
map: null,
ops: {},
lib: null,
map: null,
latLng: null,
distance: ['100米', '200米', '300米', '400米', '500米'],
addressList: [],
page: 1,
marker: null,
timeout: null
2022-03-08 17:02:42 +08:00
}
},
2022-03-09 13:48:22 +08:00
watch: {
map (v) {
if (v) {
this.init()
}
}
},
computed: {
...mapState(['user',])
},
2022-03-08 17:02:42 +08:00
onLoad () {
uni.getLocation({
type: 'wgs84',
success: res => {
this.longitude = res.longitude
this.latitude = res.latitude
}
})
},
methods: {
2022-03-09 13:48:22 +08:00
chooseDistance (index) {
this.chooseIndex = index
this.isShowScope = false
},
init () {
this.map.setZoom(19)
this.addMarker(this.map.getCenter())
this.map.on('click', e => {
this.addressList = []
this.latLng = e.latLng
this.isShow = true
this.addMarker(e.latLng)
this.getAddress()
})
},
chooseAddress (index) {
this.addMarker(this.addressList[index].location)
this.currIndex = index
},
addMarker (position) {
if (this.marker) {
this.marker.setMap(null)
this.marker = null
}
this.marker = new this.lib.MultiMarker({
id: 'marker-layer',
map: this.map,
styles: {
marker: new this.lib.MarkerStyle({
width: 30,
height: 45,
anchor: { x: 10, y: 30 }
}),
},
geometries: [{
id: 'marker',
styleId: 'marker',
position: position,
properties: {
title: 'marker'
}
}]
})
this.easeTo(position)
},
easeTo (position) {
this.map.easeTo({
center: position,
zoom: 17
},
{ duration: 500 })
},
onChange () {
if (this.timeout) {
clearTimeout(this.timeout)
}
this.timeout = setTimeout(() => {
this.currIndex = -1
new this.lib.service.Suggestion({
pageSize: 20
}).getSuggestions({
keyword: this.address
}).then(res => {
this.addressList = []
if (res.data.length) {
this.addressList = res.data
}
})
}, 500)
},
getAddress () {
this.currIndex = 0
new this.lib.service.Search({
pageSize: 20
}).explore({
center: this.latLng,
radius: 2000,
orderBy: '_distance'
}).then(res => {
this.addressList = []
if (res.data.length) {
this.addressList = res.data
}
})
2022-03-08 17:02:42 +08:00
}
}
}
</script>
<style lang="scss" scoped>
.Attendance-address {
width: 100%;
height: 100vh;
.ActionSheet {
background: #F5F6F6;
.ActionSheet-list {
margin-bottom: 8px;
background: #fff;
div {
height: 112px;
line-height: 112px;
text-align: center;
color: #333333;
font-size: 32px;
border-bottom: 1px solid #D8DDE6;
&.active {
color: #1365DD;
font-weight: 600;
}
2022-03-09 13:48:22 +08:00
&:active {
background: #eee;
}
2022-03-08 17:02:42 +08:00
&:last-child {
border: none;
}
}
}
.cancel-btn {
height: 112px;
line-height: 112px;
color: #333;
font-size: 32px;
text-align: center;
font-weight: 600;
background: #fff;
2022-03-09 13:48:22 +08:00
&:active {
background: #eee;
}
2022-03-08 17:02:42 +08:00
}
}
* {
box-sizing: border-box;
line-height: 1;
font-style: normal;
}
.wrapper {
height: 100%;
overflow: hidden;
scroll-view {
height: calc(100% - 308px);
padding: 0 32px;
.address-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 32px 0;
border-bottom: 1px solid #EEEEEE;
&:last-child {
border: none;
}
2022-03-09 13:48:22 +08:00
.left {
flex: 1;
margin-right: 20px;
}
2022-03-08 17:02:42 +08:00
.right {
2022-03-09 13:48:22 +08:00
flex-shrink: 1;
2022-03-08 17:02:42 +08:00
width: 32px;
height: 32px;
border-radius: 50%;
border: 4px solid #CCCCCC;
transition: all ease 0.3s;
&.active {
border: 10px solid #1365DD;
}
}
h2 {
margin-bottom: 20px;
color: #222222;
font-weight: 600;
font-size: 34px;
}
p {
2022-03-09 13:48:22 +08:00
line-height: 1.2;
2022-03-08 17:02:42 +08:00
color: #999999;
font-size: 28px;
}
}
}
.address-search {
display: flex;
align-items: center;
height: 100px;
padding: 0 32px;
.address-search__wrapper {
display: flex;
align-items: center;
width: 100%;
height: 72px;
padding: 0 32px;
background: #F6F7F9;
border-radius: 36px;
image {
width: 48px;
height: 48px;
}
input {
flex: 1;
font-size: 26px;
color: #333;
}
}
}
.address-btn {
display: flex;
align-items: center;
justify-content: space-between;
height: 112px;
line-height: 112px;
padding: 0 32px;
text-align: center;
color: #FFFFFF;
font-size: 32px;
background: #1365DD;
image {
width: 32px;
height: 32px;
margin-left: 4px;
}
.right {
display: flex;
align-items: center;
}
}
.top {
display: flex;
align-items: center;
justify-content: space-between;
height: 96px;
padding: 0 32px;
font-size: 32px;
color: #999;
font-weight: 600;
span:last-child {
color: #222;
}
}
}
map {
width: 100%;
height: 100%;
}
}
</style>