Commit 34aa19de by 匡雅琴

预发布bug解决

1 parent 219d39a7
<template> <template>
<div> <div v-if="provinceView">
<el-form ref="provinceForm" :model="provinceForm" inline="true" class="province"> <el-form ref="provinceForm" :model="provinceForm" inline="true" class="province">
<el-select :size="size" v-model="provinceForm.provinceName" clearable placeholder="选择省份" :style="{ width: defaultWidth }" @change="selectProvince" class="select-padding"> <el-select size="small" v-model="provinceForm.provinceName" clearable placeholder="选择省份" :style="{ width: defaultWidth }" @change="selectProvince" class="select-padding">
<el-option v-for="item in AllData" :key="item.adcode" :label="item.name" :value="item.name" @click.native="selectProvince(item)"></el-option> <el-option v-for="item in AllData" :key="item.adcode" :label="item.name" :value="item.name" @click.native="selectProvince(item)"></el-option>
</el-select> </el-select>
<el-select :size="size" v-model="provinceForm.cityName" clearable placeholder="选择市" :style="{ width: defaultWidth }" @change="selectCity" class="select-padding"> <el-select size="small" v-model="provinceForm.cityName" clearable placeholder="选择市" :style="{ width: defaultWidth }" @change="selectCity" class="select-padding">
<el-option v-for="item in cityList" :key="item.adcode" :label="item.name" :value="item.name" @click.native="selectCity(item)"></el-option> <el-option v-for="item in cityList" :key="item.adcode" :label="item.name" :value="item.name" @click.native="selectCity(item)"></el-option>
</el-select> </el-select>
<el-select v-if="subdistrict == 3" :size="size" v-model="provinceForm.townName" clearable placeholder="选择区" :style="{ width: defaultWidth }" @change="selectTown" class="select-padding"> <el-select v-if="subdistrict == 3" size="small" v-model="provinceForm.townName" clearable placeholder="选择区" :style="{ width: defaultWidth }" @change="selectTown" class="select-padding">
<el-option v-for="item in townList" :key="item.adcode" :label="item.name" :value="item.name" @click.native="selectTown(item)"></el-option> <el-option v-for="item in townList" :key="item.adcode" :label="item.name" :value="item.name" @click.native="selectTown(item)"></el-option>
</el-select> </el-select>
</el-form> </el-form>
...@@ -15,55 +15,121 @@ ...@@ -15,55 +15,121 @@
</template> </template>
<script> <script>
let map
export default { export default {
name: 'Province', name: 'GLProvince',
props: { props: {
// 省市级别,2--只显示省市,3--显示省市区,默认只显示省市
subdistrict: { subdistrict: {
type: Number, type: Number,
default: 2 default: 2
}, },
// 省市下拉组件宽度
defaultWidth: { defaultWidth: {
type: String, type: String,
default: '150px' default: '150px'
},
// 组件是否展示,默认展示
provinceView: {
type: Boolean,
default: true
} }
}, },
data() { data() {
return { return {
// 所有数据
AllData: [], AllData: [],
// 城市列表
cityList: [{ adcode: '', name: '全部' }], cityList: [{ adcode: '', name: '全部' }],
// 地区列表
townList: [{ adcode: '', name: '全部' }], townList: [{ adcode: '', name: '全部' }],
provinceForm: { provinceForm: {
provinceName: '', // 省值 // 省份名称
cityName: '', // 市值 provinceName: '',
// 城市名称
cityName: '',
// 地区名称
townName: '', townName: '',
// 省份代码
provinceCode: '', provinceCode: '',
// 城市代码
cityCode: '', cityCode: '',
// 地区代码
townCode: '' townCode: ''
} }
} }
}, },
mounted() { mounted() {},
this.mapInit()
},
methods: { methods: {
/*
* @params:传入的为一个key-value的对象
1、keywords --查询关键字,只支持单个关键词语搜索关键词支持:行政区名称、citycode、adcode
列如:this.provinceList({keywords: '山东省'}),这样就可以筛选出山东省下的市、区信息
2、subdistrict --设置显示下级行政区级数,0:不返回下级行政区;1:返回下一级行政区;2:返回下两级行政区;3:返回下三级行政区;
不传的话默认为2,可以在组件中穿,也可以在调用方法的时候传,如果需要展示省市组件,传值最小为2
3、page --最外层的districts最多会返回20个数据,若超过限制,请用page请求下一页数据。
例如page=2;page=3。默认page=1
4、extensions --控制行政区信息中返回行政区边界坐标点; 可选值:base、all;
base:不返回行政区边界坐标点;(默认)
all:只返回当前查询district的边界值,不返回子节点的边界值;目前不能返回乡镇/街道级别的边界值
5、filter -- 按照指定行政区划进行过滤,填入后则只返回该省/直辖市信息,需填入adcode,为了保证数据的正确,强烈建议填入此参数
6、callback -- callback值是用户定义的函数名称,此参数只在output=JSON时有效
7、output --返回数据格式类型,可选值:JSON,XML(默认JSON)
* @return:返回的是一个promise对象,如果不需要展示组件,只需要获取值,可以直接调用方法,异步获取返回值
列如:
const p = this.$refs.provinceForm.provinceList({xxxx(可传值,传值可参考上文params描述) })
p.then(r => {
// r 为返回结果
console.log(r)
})
**/
// 获取省市信息
provinceList(params = {}) {
params ? (params.subdistrict ? '' : (params.subdistrict = this.subdistrict)) : (params.subdistrict = this.subdistrict)
let data = ''
for (let key in params) {
console.log(params[key])
data += '&' + key + '=' + params[key]
}
let path = `https://restapi.amap.com/v3/config/district?key=d22348363c34c266f772ae9b635eef2a`
path = path + data
const pro = fetch(path).then(res => {
return res.json()
})
if (this.provinceView) {
pro.then(r => {
this.AllData = r.districts[0].districts
})
}
return pro
},
// 省市回显 // 省市回显
init(province, city) { init(province, city, town) {
this.provinceForm = { this.provinceForm = {
provinceName: province, provinceName: province,
cityName: city cityName: city,
townName: town
} }
// this.mapInit(province, city)
if (province) { if (province) {
this.AllData.map(item => { this.AllData.map(item => {
if (item.name.indexOf(province) != -1) { if (item.name.indexOf(province) != -1) {
this.provinceForm.provinceName = item.name this.provinceForm.provinceName = item.name
this.cityList = item.districtList this.cityList = item.districts
this.provinceForm.provinceCode = item.adcode this.provinceForm.provinceCode = item.adcode
this.cityList.map(itm => { this.cityList.map(itm => {
if (itm.name.indexOf(city) != -1) { if (itm.name.indexOf(city) != -1) {
this.provinceForm.cityCode = itm.adcode this.provinceForm.cityCode = itm.adcode
this.provinceForm.cityName = itm.name this.provinceForm.cityName = itm.name
this.townList = itm.districts
if (town) {
this.townList.map(itmx => {
if (itmx.name.indexOf(town) != -1) {
this.provinceForm.townCode = itmx.adcode
this.provinceForm.townName = itmx.name
}
})
}
} }
}) })
} }
...@@ -73,49 +139,19 @@ export default { ...@@ -73,49 +139,19 @@ export default {
// 选择省 // 选择省
selectProvince(val) { selectProvince(val) {
this.provinceForm.cityName = '' this.provinceForm.cityName = ''
this.cityList = val.districtList this.provinceForm.townName = ''
this.cityList = val.districts
this.$emit('selectProvince', val.name, val.adcode) this.$emit('selectProvince', val.name, val.adcode)
}, },
// 选择市 // 选择市
selectCity(val) { selectCity(val) {
this.provinceForm.townName = '' this.provinceForm.townName = ''
this.townList = val.districtList this.townList = val.districts
this.$emit('selectCity', val.name, val.adcode) this.$emit('selectCity', val.name, val.adcode)
}, },
// 选择区 // 选择区
selectTown(val) { selectTown(val) {
this.$emit('selectTown', val.name, val.adcode) this.$emit('selectTown', val.name, val.adcode)
},
mapInit() {
map = new AMap.Map('district', {
resizeEnable: true
})
AMap.plugin(['AMap.DistrictSearch'], () => {
var opts = {
subdistrict: this.subdistrict, //返回下一级行政区
level: 'city', //查询的范围
showbiz: true //查询行政级别为 市
}
var districtSearch = new AMap.DistrictSearch(opts)
districtSearch.search('中国', (status, result) => {
this.AllData = result.districtList[0].districtList
// if (provinceName) {
// this.AllData.map(item => {
// if (item.name.indexOf(provinceName) != -1) {
// this.provinceForm.provinceName = item.name
// this.cityList = item.districtList
// this.provinceForm.provinceCode = item.adcode
// this.cityList.map(itm => {
// if (itm.name.indexOf(cityName) != -1) {
// this.provinceForm.cityCode = itm.adcode
// this.provinceForm.cityName = itm.name
// }
// })
// }
// })
// }
})
})
} }
} }
} }
......
...@@ -213,7 +213,8 @@ export default { ...@@ -213,7 +213,8 @@ export default {
provinceName: '', provinceName: '',
cityCode: '', cityCode: '',
cityName: '', cityName: '',
isFirstBrand: false isFirstBrand: false,
addressData: {}
} }
}, },
watch: { watch: {
...@@ -296,11 +297,28 @@ export default { ...@@ -296,11 +297,28 @@ export default {
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 = this.$refs.mapForm.geocoderAddress.addressComponent var fullAddress = ''
var provincecode = ''
if (this.$refs.mapForm.geocoderAddress.addressComponent) {
fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent
provincecode = this.$refs.mapForm.geocoderAddress.adcode
this.addressData.fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent
this.addressData.provincecode = this.$refs.mapForm.geocoderAddress.adcode
} else {
fullAddress = this.addressData.fullAddress
provincecode = this.addressData.provincecode
}
// 获取省市 // 获取省市
var provincecode = this.$refs.mapForm.geocoderAddress.adcode var province = ''
var province = fullAddress.province var city = ''
var city = fullAddress.city ? fullAddress.city : fullAddress.district if (fullAddress) {
province = fullAddress.province
city = fullAddress.city ? fullAddress.city : fullAddress.district
} else {
province = this.accountAddForm.provinceName
city = this.accountAddForm.cityName
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) {
...@@ -398,6 +416,7 @@ export default { ...@@ -398,6 +416,7 @@ export default {
}, },
mounted() { mounted() {
this.$refs.provinceForm.provinceList()
this.getUserInfo() this.getUserInfo()
} }
} }
......
...@@ -96,10 +96,12 @@ export default { ...@@ -96,10 +96,12 @@ export default {
isFirstBrand: false, isFirstBrand: false,
baseFormRules: { baseFormRules: {
residentPhone: [{ validator: validatePhoneTwo, trigger: 'blur' }] residentPhone: [{ validator: validatePhoneTwo, trigger: 'blur' }]
} },
addressData: {}
} }
}, },
mounted() { mounted() {
this.$refs.provinceForm.provinceList()
this.getUserInfo() this.getUserInfo()
}, },
methods: { methods: {
...@@ -180,18 +182,34 @@ export default { ...@@ -180,18 +182,34 @@ export default {
let lnglat = this.$refs.mapForm.lnglat let lnglat = this.$refs.mapForm.lnglat
this.infoForm.lat = lnglat.lat this.infoForm.lat = lnglat.lat
this.infoForm.lng = lnglat.lng this.infoForm.lng = lnglat.lng
var fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent var fullAddress = ''
var provincecode = ''
if (this.$refs.mapForm.geocoderAddress.addressComponent) {
fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent
provincecode = this.$refs.mapForm.geocoderAddress.adcode
this.addressData.fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent
this.addressData.provincecode = this.$refs.mapForm.geocoderAddress.adcode
} else {
fullAddress = this.addressData.fullAddress
provincecode = this.addressData.provincecode
}
// 获取省市 // 获取省市
var provincecode = this.$refs.mapForm.geocoderAddress.adcode var province = ''
var province = fullAddress.province var city = ''
var city = fullAddress.city ? fullAddress.city : fullAddress.district if (fullAddress) {
province = fullAddress.province
city = fullAddress.city ? fullAddress.city : fullAddress.district
} else {
province = this.infoForm.provinceName
city = this.infoForm.cityName
provincecode = this.infoForm.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)
console.log(provincecode)
provincecode == 5001 ? (city = city.slice(0, 2) + '城区') : (city = city.slice(0, 2) + '郊县') provincecode == 5001 ? (city = city.slice(0, 2) + '城区') : (city = city.slice(0, 2) + '郊县')
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!