提交 cd99c127 authored 作者: 王鹏飞's avatar 王鹏飞

对接高德地图

上级 0a6d469d
<template> <template>
<app-card> <app-card>
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px"> <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="70px" :hide-required-asterisk="true">
<el-form-item label="客户电话" prop="shop_tel"> <el-form-item label="客户电话" prop="shop_tel">
<el-radio-group v-model="telRadio" @change="radioChange"> <el-radio-group v-model="telRadio" @change="radioChange">
<el-radio :label="1">普通座机号</el-radio> <el-radio :label="1">普通座机号</el-radio>
...@@ -14,18 +14,20 @@ ...@@ -14,18 +14,20 @@
</el-form-item> </el-form-item>
<el-form-item label="详细地址" prop="shop_address"> <el-form-item label="详细地址" prop="shop_address">
<el-input v-model="ruleForm.shop_address"> <el-input v-model="ruleForm.shop_address">
<!-- <template #append> <template #append>
<el-button @click="mapSearch">搜索地图</el-button> <el-button @click="mapSearch">搜索地图</el-button>
</template> --> </template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<!-- <div class="map"> <div class="map">
<div id="map-container"></div> <div id="map-container"></div>
<div id="map-panel"></div> <div id="map-panel"></div>
</div> --> </div>
<el-form-item> <div class="form-footer">
<el-button type="primary" @click="onSubmit">保存</el-button> <div class="inner">
</el-form-item> <el-button type="primary" @click="onSubmit">保存</el-button>
</div>
</div>
</el-form> </el-form>
</app-card> </app-card>
</template> </template>
...@@ -79,6 +81,7 @@ export default { ...@@ -79,6 +81,7 @@ export default {
} else { } else {
this.telRadio = 2 this.telRadio = 2
} }
this.$nextTick(this.initMap)
} }
} }
}, },
...@@ -102,11 +105,24 @@ export default { ...@@ -102,11 +105,24 @@ export default {
}) })
}, },
initMap() { initMap() {
if (this.map) {
return
}
const position = JSON.parse(this.ruleForm.shop_pos)
this.map = new window.AMap.Map('map-container', { this.map = new window.AMap.Map('map-container', {
resizeEnable: true, resizeEnable: true,
zoom: 18, zoom: 16,
center: [116.24582, 40.222615] center: position
})
new window.AMap.Marker({ map: this.map, position })
const infoWindow = new window.AMap.InfoWindow({
content: this.ruleForm.shop_address,
offset: new window.AMap.Pixel(0, -30)
}) })
infoWindow.open(this.map, position)
window.AMap.plugin(['AMap.PlaceSearch'], () => { window.AMap.plugin(['AMap.PlaceSearch'], () => {
// 构造地点查询类 // 构造地点查询类
this.placeSearch = new window.AMap.PlaceSearch({ this.placeSearch = new window.AMap.PlaceSearch({
...@@ -119,7 +135,7 @@ export default { ...@@ -119,7 +135,7 @@ export default {
this.placeSearch.on('selectChanged', e => { this.placeSearch.on('selectChanged', e => {
const data = e.selected.data const data = e.selected.data
this.ruleForm.shop_address = data.cityname + data.adname + data.name this.ruleForm.shop_address = data.cityname + data.adname + data.name
this.ruleForm.shop_pos = JSON.stringify(data.location.pos) this.ruleForm.shop_pos = JSON.stringify([data.location.lng, data.location.lat])
console.log(data) console.log(data)
}) })
}) })
...@@ -129,11 +145,9 @@ export default { ...@@ -129,11 +145,9 @@ export default {
this.placeSearch.search(this.ruleForm.shop_address) this.placeSearch.search(this.ruleForm.shop_address)
} }
}, },
mounted() {
// this.initMap()
},
destroyed() { destroyed() {
this.map && this.map.destroy() this.map && this.map.destroy()
this.map = null
} }
} }
</script> </script>
...@@ -158,4 +172,17 @@ export default { ...@@ -158,4 +172,17 @@ export default {
right: 10px; right: 10px;
width: 280px; width: 280px;
} }
.form-footer {
position: sticky;
bottom: 0;
z-index: 118;
border-top: 0.5px solid rgba(0, 0, 0, 0.05);
background-color: rgba(255, 255, 255, 0.95);
.inner {
height: 80px;
display: flex;
justify-content: center;
align-items: center;
}
}
</style> </style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论