Commit a66f5279 by 匡雅琴

弹框更换

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