Commit a2a4a6c6 by 匡雅琴

省市接口替换

1 parent 5fd271f2
......@@ -2,25 +2,25 @@
<div>
<el-form ref="provinceForm" :model="provinceForm" label-width="80px" inline="true" class="province">
<el-select v-model="provinceForm.provinceName" placeholder="选择省份" @change="selectProvince" class="select-padding">
<el-option v-for="item in AllData" :key="item.provinceCode" :label="item.provinceName" :value="item.provinceName" @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 v-model="provinceForm.cityName" placeholder="选择您所在的市" style="width: 250px" @change="selectCity" class="select-padding">
<el-option v-for="item in cityList" :key="item.cityCode" :label="item.cityName" :value="item.cityName" @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-form>
</div>
</template>
<script>
let map
import { provinceList } from './index'
export default {
name: 'Province',
// props: ['provinceName', 'cityName'],
data() {
return {
provinceList: provinceList(),
AllData: [],
cityList: [{ cityCode: '', cityName: '请先选择省' }],
cityList: [{ adcode: '', name: '请先选择省' }],
provinceForm: {
provinceName: '', // 省值
cityName: '', // 市值
......@@ -29,55 +29,55 @@ export default {
}
}
},
// inject: ['provinceEditAccount'],
mounted() {
// 初始化
// this.getProvinceList()
// console.log(this.provinceEditAccount, '====')
// console.log(JSON.stringify(this.provinceEditAccount.cityName))
// if (this.provinceEditAccount) {
// this.init(this.provinceEditAccount.provinceName, this.provinceEditAccount.cityName)
// console.log(this.provinceEditAccount.provinceName, this.provinceEditAccount.cityName)
// }
},
mounted() {},
methods: {
init(province, city) {
this.provinceForm = {
provinceName: province,
cityName: city
}
this.getProvinceList(province, city)
this.mapInit(province, city)
},
// 选择省
selectProvince(val) {
this.provinceForm.cityName = ''
this.cityList = val.districtList
this.$emit('getProvince', val.name, val.adcode)
},
// 选择市
selectCity(val) {
this.$emit('getCity', val.name, val.adcode)
},
async getProvinceList(provinceName, cityName) {
const { provinceInfoList: provinceList } = await this.provinceList
this.AllData = provinceList
// this.$set(this, 'AllData', provinceList)
// if (this.provinceEditAccount) {
// this.init(this.provinceEditAccount.provinceName, this.provinceEditAccount.cityName)
// }
mapInit(provinceName, cityName) {
map = new AMap.Map('district', {
resizeEnable: true
})
AMap.plugin(['AMap.DistrictSearch'], () => {
var opts = {
subdistrict: 2, //返回下一级行政区
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.provinceName.indexOf(provinceName) != -1) {
this.cityList = item.cityInfoList
this.provinceForm.provinceCode = item.provinceCode
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 (cityName == itm.cityName) {
this.provinceForm.cityCode = itm.cityCode
if (itm.name.indexOf(cityName) != -1) {
this.provinceForm.cityCode = itm.adcode
this.provinceForm.cityName = itm.name
}
})
}
})
}
},
// 选择省
selectProvince(val) {
this.provinceForm.cityName = ''
this.cityList = val.cityInfoList
this.$emit('getProvince', val.provinceName, val.provinceCode)
},
// 选择市
selectCity(val) {
this.$emit('getCity', val.cityName, val.cityCode)
}
}
}
......
......@@ -271,26 +271,20 @@ export default {
return data.label.indexOf(value) !== -1
},
getAddress() {
console.log(this.$refs.mapForm.geocoderAddress)
if (!this.$refs.mapForm.address) {
this.$message.error('请选择地址')
return
}
this.accountAddForm.merchantAddress = this.$refs.mapForm.address
var address = this.accountAddForm.merchantAddress
let lnglat = this.$refs.mapForm.lnglat
this.accountAddForm.lat = lnglat.lat
this.accountAddForm.lng = lnglat.lng
var fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent
// 获取省市
var provinceIdx = fullAddress.province
var cityIdx = fullAddress.city
var province = provinceIdx.slice(0, 2)
var city = cityIdx.slice(0, 2)
var province = fullAddress.province
var city = fullAddress.city
// 判断省市是否匹配
if (this.accountAddForm.provinceName) {
this.accountAddForm.provinceName = this.accountAddForm.provinceName.slice(0, 2)
this.accountAddForm.cityName = this.accountAddForm.cityName.slice(0, 2)
if (this.accountAddForm.provinceName !== province || this.accountAddForm.cityName !== city) {
this.$message.error('您选择的地址错误,请重新选择')
this.accountAddForm.merchantAddress = ''
......@@ -377,7 +371,8 @@ export default {
mounted() {
this.getUserInfo()
this.$refs.provinceForm.getProvinceList()
// this.$refs.provinceForm.getProvinceList()
this.$refs.provinceForm.mapInit()
}
}
</script>
......
......@@ -159,20 +159,15 @@ export default {
return
}
this.infoForm.merchantAddress = this.$refs.mapForm.address
var address = this.infoForm.merchantAddress
let lnglat = this.$refs.mapForm.lnglat
this.infoForm.lat = lnglat.lat
this.infoForm.lng = lnglat.lng
var fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent
// 获取省市
var provinceIdx = fullAddress.province
var cityIdx = fullAddress.city
var province = provinceIdx.slice(0, 2)
var city = cityIdx.slice(0, 2)
var province = fullAddress.province
var city = fullAddress.city
// 判断省市是否匹配
if (this.infoForm.provinceName) {
this.infoForm.provinceName = this.infoForm.provinceName.slice(0, 2)
this.infoForm.cityName = this.infoForm.cityName.slice(0, 2)
if (this.infoForm.provinceName !== province || this.infoForm.cityName !== city) {
this.$message.error('您选择的地址错误,请重新选择')
this.infoForm.merchantAddress = ''
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!