task#6524 获取定位城市,时间默认当前
This commit is contained in:
@ -21,7 +21,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { searchFun } from '@/utils/map'
|
import { searchFun, getLocal, getAddress } from '@/utils/map'
|
||||||
export default {
|
export default {
|
||||||
name: "addressMap",
|
name: "addressMap",
|
||||||
data() {
|
data() {
|
||||||
@ -31,6 +31,7 @@
|
|||||||
activeIndex: '',
|
activeIndex: '',
|
||||||
map: '',
|
map: '',
|
||||||
marker: null,
|
marker: null,
|
||||||
|
cityCode: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -43,16 +44,22 @@
|
|||||||
await this.initMap()
|
await this.initMap()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initMap() { // 初始化地图
|
async initMap() { // 初始化地图
|
||||||
this.map = new AMap.Map('mapId', {
|
this.map = new AMap.Map('mapId', {
|
||||||
viewMode: '2D', // 默认使用 2D 模式
|
viewMode: '2D', // 默认使用 2D 模式
|
||||||
zoom:11, //初始化地图层级
|
zoom:11, //初始化地图层级
|
||||||
})
|
})
|
||||||
|
let res = await getLocal(this.map);
|
||||||
|
let lnglat = new AMap.LngLat(res?.lng, res?.lat);
|
||||||
|
let location = await getAddress(this.map, lnglat)
|
||||||
|
this.cityCode = location?.regeocode.addressComponent.adcode
|
||||||
|
//location?.regeocode?.addressComponent?.city || location?.regeocode?.addressComponent?.province
|
||||||
|
console.log('location', location);
|
||||||
},
|
},
|
||||||
async searchHandler() {
|
async searchHandler() {
|
||||||
this.activeIndex = null
|
this.activeIndex = null
|
||||||
if( this.keyword ) {
|
if( this.keyword ) {
|
||||||
this.addressList = await searchFun(this.map, '', this.keyword)
|
this.addressList = await searchFun(this.map, this.cityCode, this.keyword,)
|
||||||
this.addressList = this.addressList.filter(item => !!item.location)
|
this.addressList = this.addressList.filter(item => !!item.location)
|
||||||
} else {
|
} else {
|
||||||
this.addressList = []
|
this.addressList = []
|
||||||
|
@ -116,6 +116,7 @@
|
|||||||
v-if="showDatetime"
|
v-if="showDatetime"
|
||||||
v-model="appointTime"
|
v-model="appointTime"
|
||||||
type="datetime"
|
type="datetime"
|
||||||
|
:min-date="minDate"
|
||||||
@confirm="onConfirm"
|
@confirm="onConfirm"
|
||||||
@cancel="showDatetime = false"
|
@cancel="showDatetime = false"
|
||||||
/>
|
/>
|
||||||
@ -140,6 +141,7 @@
|
|||||||
remark: '',
|
remark: '',
|
||||||
showDatetime: false,
|
showDatetime: false,
|
||||||
appointTime: '',
|
appointTime: '',
|
||||||
|
minDate: new Date(),
|
||||||
address: '',
|
address: '',
|
||||||
lat: '',
|
lat: '',
|
||||||
lng: '',
|
lng: '',
|
||||||
|
Reference in New Issue
Block a user