Commit 45f754c6 by luyt

fix:省市组件方法,文档调整

1 parent bf2d2546
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
...@@ -897,8 +897,6 @@ export default { ...@@ -897,8 +897,6 @@ export default {
// } // }
// ] // ]
}, 3000) }, 3000)
// 测试省市组件
this.$refs.provinceForm2.provinceList()
}, },
methods: { methods: {
subscribe(child) { subscribe(child) {
...@@ -923,14 +921,14 @@ export default { ...@@ -923,14 +921,14 @@ export default {
console.log('row: ', row) console.log('row: ', row)
}, },
// 测试省市方法 // 测试省市方法
selectProvince(provinceName, provinceCode) { selectProvince(val) {
console.log(provinceName, provinceCode) console.log(val)
}, },
selectCity(cityName, cityCode) { selectCity(val) {
console.log(cityName, cityCode) console.log(val)
}, },
selectTown(townName, townCode) { selectTown(val) {
console.log(townName, townCode) console.log(val)
} }
} }
} }
......
...@@ -15,16 +15,16 @@ ...@@ -15,16 +15,16 @@
}, },
methods:{ methods:{
// 获取选择的省份名称和code // 获取选择的省份名称和code
selectProvince(provinceName, provinceCode) { selectProvince(val) {
console.log(provinceName, provinceCode) console.log(val)
}, },
// 获取选择的城市名称和code // 获取选择的城市名称和code
selectCity(cityName, cityCode) { selectCity(val) {
console.log(cityName, cityCode) console.log(val)
}, },
// 获取选择的地区名称和code // 获取选择的地区名称和code
selectTown(townName, townCode) { selectTown(val) {
console.log(townName, townCode) console.log(val)
}, },
toggleShow(num){ toggleShow(num){
// console.log(123) // console.log(123)
...@@ -49,18 +49,30 @@ ...@@ -49,18 +49,30 @@
export default { export default {
data() { data() {
return { return {
subdistrict: 3 subdistrict: 3,
provinceData: []
} }
}, },
mounted() {
// 测试省市组件
// 当不需要展示组件,只需要获取值时,可直接调用方法,方法返回为promise,需要用.then()方法获取值
// this.$refs.provinceForm2.provinceList().then(r => {
// this.provinceData = r.districts[0].districts
// console.log(this.provinceData)
// })
},
methods: { methods: {
selectProvince(provinceName, provinceCode) { // 选择省 provinceName-省名称 provinceCode-省代码
console.log(provinceName, provinceCode) selectProvince(val) {
console.log(val)
}, },
selectCity(cityName, cityCode) { // 选择市 cityName-市名称 cityCode-市代码
console.log(cityName, cityCode) selectCity(val) {
console.log(val)
}, },
selectTown(townName, townCode) { // 选择区 townName-区名称 townCode-区代码
console.log(townName, townCode) selectTown(val) {
console.log(val)
} }
}, },
......
<template> <template>
<div v-if="provinceView"> <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="small" v-model="provinceForm.provinceName" clearable placeholder="选择省份" :style="{ width: defaultWidth }" class="select-padding"> <el-select size="small" v-model="provinceForm.provinceName" clearable placeholder="选择省份" :style="{ width: defaultWidth }" @clear="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="small" v-model="provinceForm.cityName" clearable placeholder="选择市" :style="{ width: defaultWidth }" class="select-padding"> <el-select size="small" v-model="provinceForm.cityName" clearable placeholder="选择市" :style="{ width: defaultWidth }" @clear="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="small" v-model="provinceForm.townName" clearable placeholder="选择区" :style="{ width: defaultWidth }" class="select-padding"> <el-select v-if="subdistrict == 3" size="small" v-model="provinceForm.townName" clearable placeholder="选择区" :style="{ width: defaultWidth }" @clear="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>
...@@ -60,7 +60,9 @@ export default { ...@@ -60,7 +60,9 @@ export default {
} }
}, },
mounted() { mounted() {
this.provinceList() if (this.provinceView) {
this.provinceList()
}
}, },
methods: { methods: {
/* /*
...@@ -142,25 +144,32 @@ export default { ...@@ -142,25 +144,32 @@ export default {
}) })
} }
}, },
selectProvince(val) { selectProvince(val) {
this.provinceForm.cityName = '' this.provinceForm.cityName = ''
this.provinceForm.townName = '' this.provinceForm.townName = ''
this.cityList = val.districts if (val) {
this.cityList = val.districts
}else{
val=''
}
// 选择省 // 选择省
this.$emit('selectProvince', val.name, val.adcode) this.$emit('selectProvince', val)
}, },
selectCity(val) { selectCity(val) {
this.provinceForm.townName = '' this.provinceForm.townName = ''
this.townList = val.districts if (val) {
this.townList = val.districts
}else{
val=''
}
// 选择市 // 选择市
this.$emit('selectCity', val.name, val.adcode) this.$emit('selectCity', val)
}, },
selectTown(val) { selectTown(val) {
// 选择区 // 选择区
this.$emit('selectTown', val.name, val.adcode) this.$emit('selectTown', val)
} }
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!