You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.9 KiB

3 years ago
<template>
<div>
<avue-map v-model="map" placeholder="请选择地图"></avue-map>
2 years ago
<template v-if="typeof resultFormat === 'string'">
<el-input size="small" :prop="value" @input="e => $emit('input',e)"></el-input>
</template>
<template v-else-if="resultFormat instanceof Array">
<div class="loc-editor">
<el-input :placeholder="item" v-for="(item, index) in resultFormat" size="small" :value="map[item]" @input="e => inputHandle(e,item)">
</el-input>
</div>
</template>
<template v-else>
<el-input :placeholder="key" v-for="(value, key) of resultFormat" size="small" :value="map[key]" @input="e => inputHandle(e,key)">
</el-input>
</template>
3 years ago
</div>
</template>
<script>
export default {
props: {
value: [String, Object, Array, Number, Boolean],
resultFormat: {
type: [String, Object, Array],
3 years ago
default: () => ['longitude','latitude'] //latitude纬度longitude经度,formattedAddress地址
3 years ago
}
},
data() {
return {
map: {},
}
},
2 years ago
methods: {
inputHandle (e, key) {
this.map[key] = e;
this.map = Object.assign({}, this.map)
}
},
3 years ago
computed: {},
watch: {
map(newVal) {
if(!newVal) return
3 years ago
let info = {
...newVal,
2 years ago
latitude: newVal.location?.lat || newVal.latitude,
longitude: newVal.location?.lng || newVal.longitude,
3 years ago
}
3 years ago
let res = ''
if(typeof this.resultFormat === 'string') {
3 years ago
res = info[this.resultFormat]
3 years ago
}
if(this.resultFormat instanceof Array) {
3 years ago
res = this.resultFormat.map(i => info[i])?.toString()
3 years ago
}
if(typeof this.resultFormat === 'object' && (!this.resultFormat instanceof Array)) {
let obj = {}
for(let key in this.resultFormat) {
3 years ago
obj[key] = info[this.resultFormat[key]]
3 years ago
}
res = obj;
}
2 years ago
console.log(res)
3 years ago
this.$emit('input', res)
},
2 years ago
value: {
handler: function(newVal) {
if (newVal) {
if(typeof this.resultFormat === 'string') {
this.map[this.resultFormat] = newVal
}
if(this.resultFormat instanceof Array && newVal) {
let valArr = newVal.split(',')
this.resultFormat.forEach((i,index) => {
this.map[i] = Number(valArr[index])
})
}
if(typeof this.resultFormat === 'object' && (!this.resultFormat instanceof Array)) {
for(let key in this.resultFormat) {
this.map[key] = newVal[key]
}
}
3 years ago
2 years ago
this.map = Object.assign(this.map, {})
this.$forceUpdate()
2 years ago
}
},
immediate: true
3 years ago
}
}
}
</script>
<style scoped lang="scss">
2 years ago
.loc-editor {
display: flex;
margin-top: 4px;
& > ::v-deep.el-input {
margin-left: 4px;
}
& > ::v-deep.el-input:first-child {
margin-left: 0;
}
}
3 years ago
</style>