Commit a66f5279 by 匡雅琴

弹框更换

1 parent 9acc6e01
......@@ -20,22 +20,24 @@
</el-input>
</el-form-item>
</el-form>
<el-dialog :visible.sync="dialogMapVisible" width="60%">
<GLDialog :visible.sync="dialogMapVisible" :mode="'big'" bigTitle="选择地址">
<map-view ref="mapForm" :mapHeight="mapHeight"></map-view>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="dialogMapVisible = false">取 消</el-button>
<el-button size="small" type="primary" @click="getAddress">确 定</el-button>
</span>
</el-dialog>
</GLDialog>
</div>
</template>
<script>
import mapView from './mapView.vue'
import GLDialog from '@/packages/GLDialog/src/GLDialog'
export default {
name: 'GLProvince',
components: {
mapView
mapView,
GLDialog
},
props: {
// 是否一行展示
......@@ -198,7 +200,7 @@ export default {
}
},
selectProvince(val) {
this.provinceForm.provinceName = val.name
this.provinceForm.provinceName = val ? val.name : ''
this.provinceForm.fullAddress = ''
this.provinceForm.cityName = ''
this.provinceForm.townName = ''
......@@ -212,7 +214,7 @@ export default {
},
selectCity(val) {
this.provinceForm.cityName = val.name
this.provinceForm.cityName = val ? val.name : ''
this.provinceForm.fullAddress = ''
this.provinceForm.townName = ''
if (val) {
......@@ -225,7 +227,7 @@ export default {
},
selectTown(val) {
this.provinceForm.townName = val.name
this.provinceForm.townName = val ? val.name : ''
this.provinceForm.fullAddress = ''
// 选择区
this.$emit('selectTown', val)
......@@ -250,12 +252,22 @@ export default {
return
}
this.provinceForm.fullAddress = this.$refs.mapForm.address
// 获取选择经纬度
let lnglat = this.$refs.mapForm.lnglat
this.provinceForm.lat = lnglat.lat
this.provinceForm.lng = lnglat.lng
var mapData = this.$refs.mapForm.geocoderAddress
// 赋值省市区名称和code
const { city, citycode, province, district, towncode } = mapData.addressComponent
this.provinceForm.provinceName = province
this.provinceForm.cityName = city
this.provinceForm.townName = district
this.provinceForm.provincecode = mapData.adcode
this.provinceForm.citycode = citycode
this.provinceForm.towncode = towncode
var fullAddress = ''
var provincecode = ''
// 为防止打开地图弹框不选择地址点确定按钮无法正确判断地址选择是否正确产生的报错,设置this.addressData.fullAddress来保存上次选择的地址
if (mapData.addressComponent) {
fullAddress = mapData.addressComponent
provincecode = mapData.adcode
......@@ -266,39 +278,41 @@ export default {
provincecode = this.addressData.provincecode
}
// 获取省市
var province = ''
var city = ''
var provincename = ''
var cityname = ''
var town = ''
province = fullAddress.province
city = fullAddress.city ? fullAddress.city : fullAddress.district
provincename = fullAddress.province
cityname = fullAddress.city ? fullAddress.city : fullAddress.district
town = fullAddress.district
// 直辖市需额外判断
const municipalities = ['北京市', '天津市', '上海市', '重庆市']
var municipality = municipalities.find(item => item == province)
var municipality = municipalities.find(item => item == provincename)
if (municipality) {
city = city.slice(0, 2) + '城区'
cityname = cityname.slice(0, 2) + '城区'
if (municipality === '重庆市') {
provincecode = provincecode.slice(0, 4)
provincecode == 5001 ? (city = city.slice(0, 2) + '城区') : (city = city.slice(0, 2) + '郊县')
provincecode == 5001 ? (cityname = cityname.slice(0, 2) + '城区') : (cityname = cityname.slice(0, 2) + '郊县')
// 重新赋值城市名
this.provinceForm.cityName = cityname
}
}
// 判断省市是否匹配
// 如果只展示省市
if (this.provinceForm.provinceName && !this.provinceForm.townName) {
if (this.provinceForm.provinceName !== province || this.provinceForm.cityName !== city) {
if (this.provinceForm.provinceName !== provincename || this.provinceForm.cityName !== cityname) {
this.$message.error('您选择的地址错误,请重新选择')
return
}
}
// 如果展示省市区
if (this.provinceForm.provinceName && this.provinceForm.townName) {
if (this.provinceForm.provinceName !== province || this.provinceForm.cityName !== city || this.provinceForm.townName !== town) {
if (this.provinceForm.provinceName !== provincename || this.provinceForm.cityName !== cityname || this.provinceForm.townName !== town) {
this.$message.error('您选择的地址错误,请重新选择')
return
}
}
this.dialogMapVisible = false
this.subdistrict == 2 ? this.init(province, city) : this.init(province, city, town)
// this.subdistrict == 2 ? this.init(province, city) : this.init(province, city, town)
// console.log(this.provinceForm.lat, 'provinceForm')
// 通过地图选择省市区
this.$emit('selectAddressByMap', this.provinceForm)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!