Commit 16889dcc by 匡雅琴

省市组件更换

1 parent 7a6632c6
<template>
<div class="map-box" :style="{ height: mapHeight + 'px' }">
<div id="container" style="width: 100%; height: 100%"></div>
<div class="map-address">{{ address }}</div>
<div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%">
<el-input placeholder="请输入关键字" v-model="input" class="input-with-select">
<el-button slot="append" icon="el-icon-search" @click="searchAddress"></el-button>
</el-input>
</div>
</div>
</template>
<script>
let map, marker, placeSearch
export default {
name: 'map',
props: {
mapHeight: {
type: Number,
default: 300
}
},
data() {
return {
input: '',
address: '',
lnglat: [],
geocoderAddress: {}
}
},
methods: {
mapInit() {
map = new AMap.Map('container', {
resizeEnable: true,
zoom: 20
})
AMap.plugin(['AMap.PlaceSearch'], function() {
//构造地点查询类
placeSearch = new AMap.PlaceSearch({
pageSize: 8, // 单页显示结果条数
pageIndex: 1, // 页码
citylimit: false, //是否强制限制在设置的城市内搜索
// panel: "panel", // 结果列表将在此容器中进行展示。
autoFitView: true, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
renderStyle: 'default'
})
})
// 添加列表点选监听事件
map.on('click', this.getAddress)
},
searchAddress() {
let _this = this
placeSearch.search(this.input, function(status, result) {
if (status === 'complete' && result.poiList.pois.length) {
let lnglat = result.poiList.pois[0].location
_this.getAddress(lnglat)
}
})
},
addMarker(lnglat) {
let position
if (lnglat.lng) {
position = [lnglat.lng, lnglat.lat]
} else {
position = lnglat
}
marker = new AMap.Marker({
icon: new AMap.Icon({
image: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
size: new AMap.Size(27, 34), //图标大小
imageSize: new AMap.Size(27, 34)
}),
position: position,
offset: new AMap.Pixel(-10, -10)
})
map.add(marker)
map.setFitView()
},
getAddress(e) {
let self = this
let lnglat
if (e.type == 'click') {
lnglat = e.lnglat
} else {
let { lng, lat } = e
lnglat = [lng, lat]
}
if (marker) {
marker.setMap(null)
marker = null
}
self.addMarker(lnglat)
AMap.plugin('AMap.Geocoder', () => {
const geocoder = new AMap.Geocoder()
geocoder.getAddress(lnglat, (status, result) => {
self.lnglat = lnglat
self.address = result.regeocode.formattedAddress
geocoder.getLocation(self.address, (status, result) => {
if (status === 'complete' && result.info === 'OK') {
this.geocoderAddress = result.geocodes[0]
}
})
})
})
},
selectAddress(e) {
//这里获得点选地点的经纬度
this.getAddress()
}
},
mounted() {
this.mapInit()
}
}
</script>
<style scoped lang="scss">
.map-box {
position: relative;
width: 100%;
}
#container {
position: absolute;
height: 100%;
}
#panel {
position: absolute;
max-height: 90%;
overflow-y: auto;
top: 80px;
right: 10px;
width: 280px;
}
.map-address {
position: absolute;
line-height: 20px;
bottom: -30px;
}
</style>
...@@ -46,12 +46,12 @@ ...@@ -46,12 +46,12 @@
</el-row> --> </el-row> -->
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<el-form-item size="small" label="商户地址" class="form-row"> <ProvinceCity ref="provinceForm" :subdistrict="subdistrict" @selectProvince="selectProvince" @selectCity="selectCity" :detailAddressLabel="detailAddressLabel" @selectAddressByMap="selectAddressByMap"></ProvinceCity>
<!-- 省市 --> <!-- <el-form-item size="small" label="商户地址" class="form-row">
<ProvinceCity ref="provinceForm" @selectProvince="selectProvince" @selectCity="selectCity"></ProvinceCity> <ProvinceCity ref="provinceForm" @selectProvince="selectProvince" @selectCity="selectCity"></ProvinceCity>
<el-input readonly style="flex:1" v-model="accountAddForm.merchantAddress" placeholder="请选择商户地址"></el-input> <el-input readonly style="flex:1" v-model="accountAddForm.merchantAddress" placeholder="请选择商户地址"></el-input>
<el-button type="primary" class="form-btn" @click="hanleSelectMap">选择地址</el-button> <el-button type="primary" class="form-btn" @click="hanleSelectMap">选择地址</el-button>
</el-form-item> </el-form-item> -->
</el-col> </el-col>
</el-row> </el-row>
<!-- <el-row> <!-- <el-row>
...@@ -131,26 +131,26 @@ ...@@ -131,26 +131,26 @@
</el-col> </el-col>
</el-row> </el-row>
</el-form> </el-form>
<GLDialog :visible.sync="dialogMapVisible" title="选择地图"> <!-- <GLDialog :visible.sync="dialogMapVisible" title="选择地图">
<map-view ref="mapForm" :mapHeight="450"></map-view> <map-view ref="mapForm" :mapHeight="450"></map-view>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dialogMapVisible = false">取 消</el-button> <el-button @click="dialogMapVisible = false">取 消</el-button>
<el-button type="primary" @click="getAddress">确 定</el-button> <el-button type="primary" @click="getAddress">确 定</el-button>
</span> </span>
</GLDialog> </GLDialog> -->
</div> </div>
</template> </template>
<script> <script>
import util from '@/utils/util' import util from '@/utils/util'
import mapView from '@/components/mapView/index' // import mapView from '@/components/mapView/index'
import SelectBrand from '../../baseInfo/selectBrand.vue' import SelectBrand from '../../baseInfo/selectBrand.vue'
import ProvinceCity from '@/components/province-city/index.vue' import ProvinceCity from '@/components/province-city/index.vue'
export default { export default {
name: 'base', name: 'base',
components: { components: {
ProvinceCity, ProvinceCity,
mapView, // mapView,
SelectBrand SelectBrand
}, },
props: { props: {
...@@ -192,6 +192,8 @@ export default { ...@@ -192,6 +192,8 @@ export default {
} }
} }
return { return {
subdistrict: 2,
detailAddressLabel: ' ',
imgIndex: '', imgIndex: '',
filterText: '', filterText: '',
defaultProps: { defaultProps: {
...@@ -287,80 +289,82 @@ export default { ...@@ -287,80 +289,82 @@ export default {
if (!value) return true if (!value) return true
return data.label.indexOf(value) !== -1 return data.label.indexOf(value) !== -1
}, },
getAddress() { // getAddress() {
if (!this.$refs.mapForm.address) { // if (!this.$refs.mapForm.address) {
this.$message.error('请选择地址') // this.$message.error('请选择地址')
return // return
} // }
this.accountAddForm.merchantAddress = this.$refs.mapForm.address // this.accountAddForm.merchantAddress = this.$refs.mapForm.address
let lnglat = this.$refs.mapForm.lnglat // let lnglat = this.$refs.mapForm.lnglat
this.accountAddForm.lat = lnglat.lat // this.accountAddForm.lat = lnglat.lat
this.accountAddForm.lng = lnglat.lng // this.accountAddForm.lng = lnglat.lng
var fullAddress = '' // var fullAddress = ''
var provincecode = '' // var provincecode = ''
if (this.$refs.mapForm.geocoderAddress.addressComponent) { // if (this.$refs.mapForm.geocoderAddress.addressComponent) {
fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent // fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent
provincecode = this.$refs.mapForm.geocoderAddress.adcode // provincecode = this.$refs.mapForm.geocoderAddress.adcode
this.addressData.fullAddress = fullAddress // this.addressData.fullAddress = fullAddress
this.addressData.provincecode = provincecode // this.addressData.provincecode = provincecode
} else { // } else {
fullAddress = this.addressData.fullAddress // fullAddress = this.addressData.fullAddress
provincecode = this.addressData.provincecode // provincecode = this.addressData.provincecode
} // }
// 获取省市 // // 获取省市
var province = '' // var province = ''
var city = '' // var city = ''
if (fullAddress) { // if (fullAddress) {
province = fullAddress.province // province = fullAddress.province
city = fullAddress.city ? fullAddress.city : fullAddress.district // city = fullAddress.city ? fullAddress.city : fullAddress.district
} else { // } else {
province = this.accountAddForm.provinceName // province = this.accountAddForm.provinceName
city = this.accountAddForm.cityName // city = this.accountAddForm.cityName
provincecode = this.accountAddForm.cityCode // provincecode = this.accountAddForm.cityCode
} // }
const municipalities = ['北京市', '天津市', '上海市', '重庆市'] // const municipalities = ['北京市', '天津市', '上海市', '重庆市']
var municipality = municipalities.find(item => item == province) // var municipality = municipalities.find(item => item == province)
if (municipality) { // if (municipality) {
city = city.slice(0, 2) + '城区' // city = city.slice(0, 2) + '城区'
if (municipality === '重庆市') { // if (municipality === '重庆市') {
provincecode = provincecode.slice(0, 4) // provincecode = provincecode.slice(0, 4)
provincecode == 5001 ? (city = city.slice(0, 2) + '城区') : (city = city.slice(0, 2) + '郊县') // provincecode == 5001 ? (city = city.slice(0, 2) + '城区') : (city = city.slice(0, 2) + '郊县')
} // }
} // }
// 判断省市是否匹配 // // 判断省市是否匹配
if (this.accountAddForm.provinceName) { // if (this.accountAddForm.provinceName) {
if (this.accountAddForm.provinceName !== province && this.accountAddForm.cityName !== city) { // if (this.accountAddForm.provinceName !== province && this.accountAddForm.cityName !== city) {
this.$message.error('您选择的地址错误,请重新选择') // this.$message.error('您选择的地址错误,请重新选择')
this.accountAddForm.merchantAddress = '' // this.accountAddForm.merchantAddress = ''
return // return
} // }
} // }
this.dialogMapVisible = false // this.dialogMapVisible = false
this.accountAddForm.provinceName = province // this.accountAddForm.provinceName = province
this.accountAddForm.cityName = city // this.accountAddForm.cityName = city
this.$refs.provinceForm.init(province, city) // this.$refs.provinceForm.init(province, city)
const { provinceCode, cityCode } = this.$refs.provinceForm.provinceForm // const { provinceCode, cityCode } = this.$refs.provinceForm.provinceForm
this.accountAddForm.provinceCode = provinceCode // this.accountAddForm.provinceCode = provinceCode
this.accountAddForm.cityCode = cityCode // this.accountAddForm.cityCode = cityCode
}, // },
// 当直接点击选择地址时,获取省市ID // 当直接点击选择地址时,获取省市ID
init(province, city) { init(province, city) {
this.$refs.provinceForm.init(province, city) this.$refs.provinceForm.init(province, city)
}, },
// 获取省 // 获取省
selectProvince(provinceName, provinceCode) { selectProvince(val) {
console.log(val)
this.$set(this.accountAddForm, 'merchantAddress', '') this.$set(this.accountAddForm, 'merchantAddress', '')
// 强制更新 merchantAddress // 强制更新 merchantAddress
this.$forceUpdate() this.$forceUpdate()
this.accountAddForm.cityName = '' this.accountAddForm.cityName = ''
this.accountAddForm.provinceName = provinceName this.accountAddForm.provinceName = val.name
this.accountAddForm.provinceCode = provinceCode this.accountAddForm.provinceCode = val.adcode
}, },
// 获取市 // 获取市
selectCity(cityName, cityCode) { selectCity(val) {
if (cityName) { console.log(val)
this.accountAddForm.cityName = cityName if (val.name) {
this.accountAddForm.cityCode = cityCode this.accountAddForm.cityName = val.name
this.accountAddForm.cityCode = val.adcode
} else { } else {
this.accountAddForm.cityName = '' this.accountAddForm.cityName = ''
this.accountAddForm.cityCode = '' this.accountAddForm.cityCode = ''
...@@ -368,6 +372,16 @@ export default { ...@@ -368,6 +372,16 @@ export default {
this.$set(this.accountAddForm, 'merchantAddress', '') this.$set(this.accountAddForm, 'merchantAddress', '')
this.$forceUpdate() this.$forceUpdate()
}, },
// 通过地图选择省市和详细地址
selectAddressByMap(val) {
console.log(val)
const { provinceName, cityName, fullAddress, lat, lng } = val
this.accountAddForm.merchantAddress = fullAddress
this.accountAddForm.provinceName = provinceName
this.accountAddForm.cityName = cityName
this.accountAddForm.lat = lat
this.accountAddForm.lng = lng
},
delImg(index) { delImg(index) {
this.accountAddForm.merchantFiles.splice(index, 1) this.accountAddForm.merchantFiles.splice(index, 1)
}, },
......
...@@ -434,7 +434,14 @@ export default { ...@@ -434,7 +434,14 @@ export default {
merchantBrandMain merchantBrandMain
}) })
// 省市回显 // 省市回显
this.$refs.baseInfoForm.init(this.accountAddForm.provinceName, this.accountAddForm.cityName) var provinceData = {
province: this.accountAddForm.provinceName,
city: this.accountAddForm.cityName,
fullAddress: this.accountAddForm.merchantAddress,
lng: this.accountAddForm.lng,
lat: this.accountAddForm.lat
}
this.$refs.baseInfoForm.init(provinceData)
if (!this.accountAddForm.merchantBrandMain) { if (!this.accountAddForm.merchantBrandMain) {
this.accountAddForm.merchantBrandMain = [] this.accountAddForm.merchantBrandMain = []
} else { } else {
......
...@@ -11,12 +11,13 @@ ...@@ -11,12 +11,13 @@
<div class="main-information"> <div class="main-information">
<div class="information-title">修改企业信息</div> <div class="information-title">修改企业信息</div>
<div class="information-form-box"> <div class="information-form-box">
<el-form ref="baseForm" :model="infoForm" class="account-body-form" label-width="120px" :rules="baseFormRules"> <el-form ref="baseForm" :model="infoForm" class="account-body-form" label-width="154px" :rules="baseFormRules">
<el-form-item size="small" label="商户地址:" class="map-row"> <Province ref="provinceForm" :subdistrict="subdistrict" @selectProvince="selectProvince" @selectCity="selectCity" :detailAddressLabel="detailAddressLabel"></Province>
<!-- <el-form-item size="small" label="商户地址:" class="map-row">
<Province ref="provinceForm" :subdistrict="subdistrict" @selectProvince="selectProvince" @selectCity="selectCity"></Province> <Province ref="provinceForm" :subdistrict="subdistrict" @selectProvince="selectProvince" @selectCity="selectCity"></Province>
<el-input class="input-width" v-model="infoForm.merchantAddress" placeholder="请选择商户地址" readonly="readonly"></el-input> <el-input class="input-width" v-model="infoForm.merchantAddress" placeholder="请选择商户地址" readonly="readonly"></el-input>
<el-button @click="hanleSelectMap" type="primary">选择地址</el-button> <el-button @click="hanleSelectMap" type="primary">选择地址</el-button>
</el-form-item> </el-form-item> -->
<el-form-item size="small" label="经营业务类型:"> <el-form-item size="small" label="经营业务类型:">
<el-checkbox-group v-model="infoForm.businessType"> <el-checkbox-group v-model="infoForm.businessType">
<el-checkbox :label="item.dictValue" v-for="item in businessType" :key="item.dictValue" :disabled="item.dictValue <= 6">{{ item.dictLabel }}</el-checkbox> <el-checkbox :label="item.dictValue" v-for="item in businessType" :key="item.dictValue" :disabled="item.dictValue <= 6">{{ item.dictLabel }}</el-checkbox>
...@@ -83,6 +84,7 @@ export default { ...@@ -83,6 +84,7 @@ export default {
} }
return { return {
subdistrict: 2, subdistrict: 2,
detailAddressLabel: ' ',
checkedAll: false, checkedAll: false,
filterText: '', filterText: '',
dialogMapVisible: false, dialogMapVisible: false,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!