老产品前端代码
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.

271 lines
7.0 KiB

<template>
<div>
<div class="dialog-h-content scroll-h">
<el-form ref="ref_form"
:inline="true"
:model="formData"
class="form">
<el-form-item label="场所名称:"
prop="name"
label-width="150px"
style="display: block">
3 years ago
<span>{{formData.name}}</span>
</el-form-item>
<el-form-item label="场所类别:"
prop="categoryName"
label-width="150px"
style="display: block">
3 years ago
<span>{{formData.categoryName}}</span>
</el-form-item>
<el-form-item label="占地面积:"
prop="areaCovered"
label-width="150px"
style="display: block">
3 years ago
<span>{{formData.areaCovered+' '}}</span>平方公里
</el-form-item>
<el-form-item label="容纳人数:"
prop="capacity"
label-width="150px"
style="display: block">
3 years ago
<span>{{formData.capacity+' '}}</span>
</el-form-item>
3 years ago
<el-form-item label="负责人:"
prop="principal"
label-width="150px"
style="display: block">
3 years ago
<span>{{formData.principal?formData.principal:'无'}}</span>
3 years ago
</el-form-item>
<el-form-item label="联系电话:"
prop="mobile"
label-width="150px"
style="display: block">
3 years ago
<span>{{formData.mobile?formData.mobile:'无'}}</span>
3 years ago
</el-form-item>
<el-form-item label="地址:"
style="display: block"
prop="address"
label-width="150px">
3 years ago
<div class="item_width_1">
<span>{{formData.address}}</span>
3 years ago
<div id="app"
class="div_map"></div>
</div>
</el-form-item>
3 years ago
</el-form>
</div>
<div class="div_btn">
<el-button size="small"
@click="handleCancle"> </el-button>
</div>
</div>
</template>
<script>
import { Loading } from 'element-ui' // 引入Loading服务
var map
var search
var markers
var infoWindowList
var geocoder // 新建一个正逆地址解析类
let loading // 加载动画
export default {
data () {
return {
formData: {},
}
},
components: {},
async mounted () {
3 years ago
await this.initMap()
},
methods: {
handleCancle () {
this.$emit('diaClose')
},
async initForm (row) {
this.startLoading()
this.formData = { ...row }
map.setCenter(new TMap.LatLng(this.formData.latitude, this.formData.longitude))
this.setMarker(this.formData.latitude, this.formData.longitude)
this.endLoading()
},
// 地图初始化函数,本例取名为init,开发者可根据实际情况定义
initMap () {
// 定义地图中心点坐标
3 years ago
let { latitude, longitude } = this.$store.state.user;
3 years ago
console.log('lat' + latitude + ',lon' + longitude)
3 years ago
if (!latitude || latitude == "" || latitude == "0") {
latitude = 39.9088810666821;
longitude = 116.39743841556731;
}
// 定义地图中心点坐标
var center = new window.TMap.LatLng(latitude, longitude);
// 定义map变量,调用 TMap.Map() 构造函数创建地图
map = new window.TMap.Map(document.getElementById('app'), {
center: center, // 设置地图中心点坐标
zoom: 17.2, // 设置地图缩放级别
pitch: 43.5, // 设置俯仰角
rotation: 45 // 设置地图旋转角度
})
search = new window.TMap.service.Search({ pageSize: 10 })
// 新建一个地点搜索类
markers = new TMap.MultiMarker({
map: map,
geometries: []
})
infoWindowList = Array(10)
geocoder = new TMap.service.Geocoder(); // 新建一个正逆地址解析类
// 监听地图平移结束
map.on('panend', () => {
this.handleMoveCenter()
})
this.handleMoveCenter()
this.convert()
},
setMarker (lat, lng) {
markers.setGeometries([])
markers.add([
{
id: '4',
styleId: 'marker',
position: new TMap.LatLng(lat, lng),
properties: {
title: 'marker4'
}
}
])
},
handleSearchMap () {
infoWindowList.forEach((infoWindow) => {
infoWindow.close()
})
infoWindowList.length = 0
markers.setGeometries([])
// 在地图显示范围内以给定的关键字搜索地点
search
.searchRectangle({
keyword: this.keyWords,
bounds: map.getBounds()
})
.then((result) => {
let { data } = result
if (Array.isArray(data) && data.length > 0) {
const {
location: { lat, lng }
} = data[0]
map.setCenter(new TMap.LatLng(lat, lng))
this.setMarker(lat, lng)
this.formData.latitude = lat
this.formData.longitude = lng
this.convert()
} else {
this.$message.error('未检索到相关位置坐标')
}
})
},
handleMoveCenter () {
//修改地图中心点
const center = map.getCenter()
const lat = center.getLat()
const lng = center.getLng()
this.formData.latitude = lat
this.formData.longitude = lng
this.setMarker(lat, lng)
this.convert(lat, lng)
},
convert (lat, lng) {
markers.setGeometries([]);
// var input = document.getElementById('location').value.split(',');
let location
if (lat && lng) {
location = new TMap.LatLng(lat, lng);
} else {
location = new TMap.LatLng(this.formData.latitude, this.formData.longitude);
}
// map.setCenter(location);
markers.updateGeometries([
{
id: 'main', // 点标注数据数组
position: location,
},
]);
geocoder
.getAddress({ location: location }) // 将给定的坐标位置转换为地址
.then((result) => {
// this.formData.address = result.result.address
// 显示搜索到的地址
});
},
// 开启加载动画
startLoading () {
loading = Loading.service({
lock: true, // 是否锁定
text: '正在加载……', // 加载中需要显示的文字
background: 'rgba(0,0,0,.7)' // 背景颜色
})
},
// 结束加载动画
endLoading () {
// clearTimeout(timer);
if (loading) {
loading.close()
}
}
},
computed: {
},
props: {
}
}
</script>
<style lang="scss" scoped >
@import "@/assets/scss/modules/visual/communityManageForm.scss";
</style>
<style scoped>
.detail_span {
width: 500px;
font-weight: bold;
text-align: left;
margin: 0 0;
font-size: 16px;
}
.form {
margin-top: 30px;
}
</style>