Commit c1579bd0 by 匡雅琴

省市组件

1 parent adedc9ff
<template> <template>
<div> <div>
<el-form ref="provinceForm" :model="provinceForm" label-width="80px" inline="true" class="province"> <el-form ref="provinceForm" :model="provinceForm" inline="true" class="province">
<el-select v-model="provinceForm.provinceName" clearable placeholder="选择省份" @change="selectProvince" class="select-padding"> <el-select :size="size" 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 v-model="provinceForm.cityName" clearable placeholder="选择您所在的市" style="width: 250px" @change="selectCity" class="select-padding"> <el-select :size="size" 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-option v-for="item in townList" :key="item.adcode" :label="item.name" :value="item.name" @click.native="selectTown(item)"></el-option>
</el-select>
</el-form> </el-form>
</div> </div>
</template> </template>
<script> <script>
let map let map
import { provinceList } from './index'
export default { export default {
name: 'Province', name: 'Province',
props: {
subdistrict: {
type: Number,
default: 2
},
defaultWidth: {
type: String,
default: '150px'
}
},
data() { data() {
return { return {
provinceList: provinceList(),
AllData: [], AllData: [],
cityList: [{ adcode: '', name: '全部' }], cityList: [{ adcode: '', name: '全部' }],
townList: [{ adcode: '', name: '全部' }],
provinceForm: { provinceForm: {
provinceName: '', // 省值 provinceName: '', // 省值
cityName: '', // 市值 cityName: '', // 市值
townName: '',
provinceCode: '', provinceCode: '',
cityCode: '' cityCode: '',
townCode: ''
} }
} }
}, },
mounted() {}, mounted() {
this.mapInit()
},
methods: { methods: {
// 省市回显
init(province, city) { init(province, city) {
this.provinceForm = { this.provinceForm = {
provinceName: province, provinceName: province,
cityName: city cityName: city
} }
this.mapInit(province, city) // this.mapInit(province, city)
if (province) {
this.AllData.map(item => {
if (item.name.indexOf(province) != -1) {
this.provinceForm.provinceName = item.name
this.cityList = item.districtList
this.provinceForm.provinceCode = item.adcode
this.cityList.map(itm => {
if (itm.name.indexOf(city) != -1) {
this.provinceForm.cityCode = itm.adcode
this.provinceForm.cityName = itm.name
}
})
}
})
}
}, },
// 选择省 // 选择省
selectProvince(val) { selectProvince(val) {
this.provinceForm.cityName = '' this.provinceForm.cityName = ''
this.cityList = val.districtList this.cityList = val.districtList
this.$emit('getProvince', val.name, val.adcode) this.$emit('selectProvince', val.name, val.adcode)
}, },
// 选择市 // 选择市
selectCity(val) { selectCity(val) {
this.$emit('getCity', val.name, val.adcode) this.provinceForm.townName = ''
this.townList = val.districtList
this.$emit('selectCity', val.name, val.adcode)
},
// 选择区
selectTown(val) {
this.$emit('selectTown', val.name, val.adcode)
}, },
mapInit(provinceName, cityName) { mapInit() {
map = new AMap.Map('district', { map = new AMap.Map('district', {
resizeEnable: true resizeEnable: true
}) })
AMap.plugin(['AMap.DistrictSearch'], () => { AMap.plugin(['AMap.DistrictSearch'], () => {
var opts = { var opts = {
subdistrict: 3, //返回下一级行政区 subdistrict: this.subdistrict, //返回下一级行政区
level: 'city', //查询的范围 level: 'city', //查询的范围
showbiz: true //查询行政级别为 市 showbiz: true //查询行政级别为 市
} }
var districtSearch = new AMap.DistrictSearch(opts) var districtSearch = new AMap.DistrictSearch(opts)
districtSearch.search('中国', (status, result) => { districtSearch.search('中国', (status, result) => {
this.AllData = result.districtList[0].districtList this.AllData = result.districtList[0].districtList
if (provinceName) { // if (provinceName) {
this.AllData.map(item => { // this.AllData.map(item => {
if (item.name.indexOf(provinceName) != -1) { // if (item.name.indexOf(provinceName) != -1) {
this.provinceForm.provinceName = item.name // this.provinceForm.provinceName = item.name
this.cityList = item.districtList // this.cityList = item.districtList
this.provinceForm.provinceCode = item.adcode // this.provinceForm.provinceCode = item.adcode
this.cityList.map(itm => { // this.cityList.map(itm => {
if (itm.name.indexOf(cityName) != -1) { // if (itm.name.indexOf(cityName) != -1) {
this.provinceForm.cityCode = itm.adcode // this.provinceForm.cityCode = itm.adcode
this.provinceForm.cityName = itm.name // this.provinceForm.cityName = itm.name
// console.log(itm.name) // }
// this.$set(this.provinceForm, 'cityName', itm.name) // })
} // }
}) // })
} // }
})
}
}) })
}) })
} }
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
<el-col :span="24"> <el-col :span="24">
<el-form-item size="small" label="商户地址" class="form-row"> <el-form-item size="small" label="商户地址" class="form-row">
<!-- 省市 --> <!-- 省市 -->
<ProvinceCity ref="provinceForm" @getProvince="getProvince" @getCity="getCity"></ProvinceCity> <ProvinceCity ref="provinceForm" @selectProvince="selectProvince" @selectCity="selectCity"></ProvinceCity>
<el-input readonly v-model="accountAddForm.merchantAddress" placeholder="请选择商户地址"></el-input> <el-input readonly 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>
...@@ -315,7 +315,7 @@ export default { ...@@ -315,7 +315,7 @@ export default {
this.$refs.provinceForm.init(province, city) this.$refs.provinceForm.init(province, city)
}, },
// 获取省 // 获取省
getProvince(provinceName, provinceCode) { selectProvince(provinceName, provinceCode) {
this.$set(this.accountAddForm, 'merchantAddress', '') this.$set(this.accountAddForm, 'merchantAddress', '')
// 强制更新 merchantAddress // 强制更新 merchantAddress
this.$forceUpdate() this.$forceUpdate()
...@@ -323,7 +323,7 @@ export default { ...@@ -323,7 +323,7 @@ export default {
this.accountAddForm.provinceCode = provinceCode this.accountAddForm.provinceCode = provinceCode
}, },
// 获取市 // 获取市
getCity(cityName, cityCode) { selectCity(cityName, cityCode) {
this.accountAddForm.cityName = cityName this.accountAddForm.cityName = cityName
this.accountAddForm.cityCode = cityCode this.accountAddForm.cityCode = cityCode
this.$set(this.accountAddForm, 'merchantAddress', '') this.$set(this.accountAddForm, 'merchantAddress', '')
...@@ -383,8 +383,6 @@ export default { ...@@ -383,8 +383,6 @@ export default {
mounted() { mounted() {
this.getUserInfo() this.getUserInfo()
// this.$refs.provinceForm.getProvinceList()
this.$refs.provinceForm.mapInit()
} }
} }
</script> </script>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<div class="information-form-box"> <div class="information-form-box">
<el-form ref="baseForm" :model="infoForm" class="account-body-form" label-width="120px"> <el-form ref="baseForm" :model="infoForm" class="account-body-form" label-width="120px">
<el-form-item size="small" label="商户地址" class="map-row"> <el-form-item size="small" label="商户地址" class="map-row">
<Province ref="provinceForm" @getProvince="getProvince" @getCity="getCity"></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>
...@@ -64,6 +64,7 @@ export default { ...@@ -64,6 +64,7 @@ export default {
}, },
data() { data() {
return { return {
subdistrict: 2,
checkedAll: false, checkedAll: false,
filterText: '', filterText: '',
dialogMapVisible: false, dialogMapVisible: false,
...@@ -138,7 +139,7 @@ export default { ...@@ -138,7 +139,7 @@ export default {
this.$refs.brandListTree.getCheckedArr = brandName this.$refs.brandListTree.getCheckedArr = brandName
} }
// 省市回显 // 省市回显
this.$refs.provinceForm.mapInit(this.infoForm.provinceName, this.infoForm.cityName) this.$refs.provinceForm.init(this.infoForm.provinceName, this.infoForm.cityName)
if (!this.infoForm.merchantBrandMain) { if (!this.infoForm.merchantBrandMain) {
this.infoForm.merchantBrandMain = [] this.infoForm.merchantBrandMain = []
} else { } else {
...@@ -173,6 +174,7 @@ export default { ...@@ -173,6 +174,7 @@ export default {
var fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent var fullAddress = this.$refs.mapForm.geocoderAddress.addressComponent
// 获取省市 // 获取省市
var provincecode = this.$refs.mapForm.geocoderAddress.adcode var provincecode = this.$refs.mapForm.geocoderAddress.adcode
console.log(fullAddress)
var province = fullAddress.province var province = fullAddress.province
var city = fullAddress.city var city = fullAddress.city
const municipalities = ['北京市', '天津市', '上海市', '重庆市'] const municipalities = ['北京市', '天津市', '上海市', '重庆市']
...@@ -200,13 +202,13 @@ export default { ...@@ -200,13 +202,13 @@ export default {
this.$refs.provinceForm.init(province, city) this.$refs.provinceForm.init(province, city)
}, },
// 获取省 // 获取省
getProvince(provinceName, provinceCode) { selectProvince(provinceName, provinceCode) {
this.infoForm.merchantAddress = '' this.infoForm.merchantAddress = ''
this.infoForm.provinceName = provinceName this.infoForm.provinceName = provinceName
this.infoForm.provinceCode = provinceCode this.infoForm.provinceCode = provinceCode
}, },
// 获取市 // 获取市
getCity(cityName, cityCode) { selectCity(cityName, cityCode) {
this.infoForm.cityName = cityName this.infoForm.cityName = cityName
this.infoForm.cityCode = cityCode this.infoForm.cityCode = cityCode
this.infoForm.merchantAddress = '' this.infoForm.merchantAddress = ''
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!