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

373 lines
10 KiB

4 years ago
<template>
<div>
<div>
<el-form :inline="true"
:model="dataForm"
:rules="dataRule"
:disabled="formType === 'detail'"
class="form">
<el-form-item label="所属小区"
label-width="150px"
style="display: block">
<span>{{ agencyObj.agencyName }}{{ agencyObj.gridName }}{{ agencyObj.label }}</span>
</el-form-item>
<el-form-item label="楼栋名称"
prop="buildingName"
label-width="150px"
style="display: block">
<el-input class="item_width_1"
maxlength="50"
show-word-limit
placeholder="请输入楼栋名称"
v-model="dataForm.buildingName">
</el-input>
</el-form-item>
<el-form-item label="楼栋类型"
prop="type"
label-width="150px"
style="display: block">
4 years ago
<el-radio-group v-model="buildType">
4 years ago
<el-radio :label="'1'">商品房</el-radio>
<el-radio :label="'2'">自建房</el-radio>
<el-radio :label="'3'">别墅</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="排序"
prop="sort"
label-width="150px">
<el-input-number v-model="dataForm.sort"
label="排序"></el-input-number>
</el-form-item>
<el-form-item label="单元数"
prop="totalUnitNum"
label-width="150px">
<el-input-number v-model="dataForm.totalUnitNum"
:min="1"
label="单元数"></el-input-number>
</el-form-item>
<el-form-item label="层数"
prop="totalFloorNum"
label-width="150px">
<el-input-number v-model="dataForm.totalFloorNum"
:min="1"
label="层数"></el-input-number>
</el-form-item>
<el-form-item label="户数"
prop="totalHouseNum"
label-width="150px">
<el-input-number v-model="dataForm.totalHouseNum"
:min="1"
label="户数"></el-input-number>
</el-form-item>
<el-form-item label="位置坐标"
prop="longitude"
label-width="150px"
style="display: block">
<el-input class="item_width_3"
maxlength="50"
placeholder="请输入关键字"
v-model="keyWords">
</el-input>
<el-button style="margin-left: 10px"
type="primary"
size="small"
@click="handleSearchMap">查询</el-button>
<div id="app"
class="div_map"></div>
<div style="margin-top: 10px">
<span>经度</span>
<el-input class="item_width_3"
maxlength="50"
placeholder="请输入经度"
v-model="dataForm.longitude">
</el-input>
<span style="margin-left: 20px">纬度</span>
<el-input class="item_width_3"
maxlength="50"
placeholder="请输入纬度"
v-model="dataForm.latitude">
</el-input>
</div>
</el-form-item>
</el-form>
</div>
<div class="div_btn">
<el-button @click="handleCancle"> </el-button>
<el-button v-if="formType != 'detail'"
type="primary"
@click="handleComfirm"> </el-button>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { Loading } from 'element-ui' // 引入Loading服务
import { requestPost } from '@/js/dai/request'
var map
var search
var markers
var infoWindowList
let loading // 加载动画
export default {
data () {
return {
formType: 'add', //表单操作类型 add新增,edit编辑,detail详情
buildingId: '', //楼栋ID
4 years ago
buildType: "1",
4 years ago
dataForm: {
agencyId: '', // 所属组织ID
agencyName: '',
gridId: '', //所属网格ID
neighborHoodId: '',//所属小区id
buildingName: '',//房屋名称
sort: 0,//排序
totalUnitNum: 0,//单元数
totalFloorNum: 0,//层数
totalHouseNum: 0,//户数
4 years ago
type: '',//房屋类型
4 years ago
location: '', //坐标位置
longitude: '', //经度
latitude: '' //纬度
},
keyWords: '',
agencyObj: {},
}
},
components: {},
mounted () {
this.initMap()
},
methods: {
async initForm (type, row, agencyObj) {
this.agencyObj = agencyObj
this.dataForm.agencyId = agencyObj.agencyId
this.dataForm.gridId = agencyObj.gridId
this.dataForm.neighborHoodId = agencyObj.id
map.setCenter(new TMap.LatLng(agencyObj.latitude, agencyObj.longitude))
this.formType = type
if (row) {
this.buildingId = row.buildingId
this.dataForm = row
4 years ago
this.buildType = row.buildingTypeKey
4 years ago
}
4 years ago
console.log(row)
4 years ago
},
async handleComfirm () {
let url = ''
if (this.formType === 'add') {
url = '/gov/org/building/buildingadd'
} else {
url = '/gov/org/building/buildingupdate'
this.dataForm.buildingId = this.buildingId
}
4 years ago
this.dataForm.type = this.buildType
4 years ago
const { data, code, msg } = await requestPost(url, this.dataForm)
if (code === 0) {
this.$message({
type: 'success',
message: '操作成功'
4 years ago
})
this.resetData()
this.$emit('dialogOk')
} else {
this.$message.error(msg)
}
},
handleCancle () {
this.resetData()
this.$emit('dialogCancle')
},
// 地图初始化函数,本例取名为init,开发者可根据实际情况定义
initMap () {
// 定义地图中心点坐标
var center = new window.TMap.LatLng(36.0722275, 120.38945519)
// 定义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)
// 监听地图平移结束
map.on('panend', () => {
this.handleMoveCenter()
})
this.handleMoveCenter()
},
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.dataForm.latitude = lat
this.dataForm.longitude = lng
} else {
this.$message.error('未检索到相关位置坐标')
}
})
},
handleMoveCenter () {
//修改地图中心点
const center = map.getCenter()
const lat = center.getLat()
const lng = center.getLng()
this.dataForm.latitude = lat
this.dataForm.longitude = lng
this.setMarker(lat, lng)
},
resetData () {
this.buildingId = '' //楼栋ID
this.dataForm = {
agencyId: '', // 所属组织ID
agencyName: '',
gridId: '', //所属网格ID
neighborHoodId: '',//所属小区id
buildingName: '',//房屋名称
sort: 0,//排序
totalUnitNum: 0,//单元数
totalFloorNum: 0,//层数
totalHouseNum: 0,//户数
type: '1',//房屋类型
location: '', //坐标位置
longitude: '', //经度
latitude: '' //纬度
}
},
// 开启加载动画
startLoading () {
loading = Loading.service({
lock: true, // 是否锁定
text: '正在加载……', // 加载中需要显示的文字
background: 'rgba(0,0,0,.7)' // 背景颜色
})
},
// 结束加载动画
endLoading () {
// clearTimeout(timer);
if (loading) {
loading.close()
}
}
},
computed: {
dataRule () {
return {
buildingName: [
{ required: true, message: '楼栋名称不能为空', trigger: 'blur' },
{
min: 1,
max: 50,
message: '小区名称长度在 1 到 50个字符',
trigger: 'blur'
}
],
agencyId: [
{ required: true, message: '所属组织不能为空', trigger: 'blur' }
],
gridId: [
{ required: true, message: '所属网格不能为空', trigger: 'blur' }
],
longitude: [
{ required: true, message: '坐标不能为空', trigger: 'blur' }
]
}
},
},
props: {}
}
</script>
<style scoped>
.item_width_1 {
width: 500px;
}
.item_width_2 {
width: 400px;
}
.item_width_3 {
margin-left: 10px;
width: 200px;
}
.div_map {
margin-top: 10px;
}
.div_btn {
display: flex;
justify-content: flex-end;
}
.el-tabs {
margin: 0 20px;
}
.el-upload__tip {
color: rgb(155, 155, 155);
margin: 0;
}
.form {
margin-top: 30px;
}
</style>