Commit bf2d2546 by luyt

fix:省市组件调整

1 parent 13fd6a83
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
<!-- <content> --> <!-- <content> -->
<!-- <GLProvince ref="provinceForm1" @selectProvince="selectProvince" @selectCity="selectCity"></GLProvince> --> <GLProvince ref="provinceForm1" @selectProvince="selectProvince" @selectCity="selectCity"></GLProvince>
<GLProvince ref="provinceForm2" :subdistrict="subdistrict" @selectProvince="selectProvince" @selectCity="selectCity" @selectTown="selectTown"></GLProvince> <GLProvince ref="provinceForm2" :subdistrict="subdistrict" @selectProvince="selectProvince" @selectCity="selectCity" @selectTown="selectTown"></GLProvince>
<el-button type="warning" @click="toggleShow(1)">显示代码</el-button>
```js {mixin:true} ```js {mixin:true}
{ {
data() { data() {
...@@ -25,23 +26,12 @@ ...@@ -25,23 +26,12 @@
selectTown(townName, townCode) { selectTown(townName, townCode) {
console.log(townName, townCode) console.log(townName, townCode)
}, },
}, toggleShow(num){
mounted() { // console.log(123)
console.log(this) this['demo' + num] = !this['demo' + num]
// 获取省市信息(可传值,具体看index.vue文件介绍)
// this.$refs.provinceForm1.provinceList
setTimeout(() => {
this.$refs.provinceForm2.provinceList
})
// 省市区回显
// this.$refs.provinceForm.init(provinceName, cityName, townName)
// 如果不需要展示组件,只需要获取数据的话,返回的是promise对象(可传值,具体看index.vue文件介绍)
// const p = this.$refs.provinceForm.provinceList()
// p.then(r => {
// console.log(r)
// })
} }
}
} }
``` ```
...@@ -73,15 +63,7 @@ ...@@ -73,15 +63,7 @@
console.log(townName, townCode) console.log(townName, townCode)
} }
}, },
mounted() {
this.$refs.provinceForm1.provinceList()
this.$refs.provinceForm2.provinceList()
// this.$refs.provinceForm.init(provinceName, cityName, townName)
// const p = this.$refs.provinceForm.provinceList()
// p.then(r => {
// console.log(r)
// })
}
} }
</script> </script>
``` ```
......
<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 }" @change="selectProvince" class="select-padding"> <el-select size="small" v-model="provinceForm.provinceName" clearable placeholder="选择省份" :style="{ width: defaultWidth }" 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 }" @change="selectCity" class="select-padding"> <el-select size="small" v-model="provinceForm.cityName" clearable placeholder="选择市" :style="{ width: defaultWidth }" 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 }" @change="selectTown" class="select-padding"> <el-select v-if="subdistrict == 3" size="small" v-model="provinceForm.townName" clearable placeholder="选择区" :style="{ width: defaultWidth }" 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>
...@@ -18,9 +18,10 @@ ...@@ -18,9 +18,10 @@
export default { export default {
name: 'GLProvince', name: 'GLProvince',
props: { props: {
// 省市级别,2--只显示省市,3--显示省市区,默认只显示省市 // 省市级别,2--只显示省市,3--显示省市区
subdistrict: { subdistrict: {
type: Number, type: Number,
// `2-只显示省市`
default: 2 default: 2
}, },
// 省市下拉组件宽度 // 省市下拉组件宽度
...@@ -58,7 +59,9 @@ export default { ...@@ -58,7 +59,9 @@ export default {
} }
} }
}, },
mounted() {}, mounted() {
this.provinceList()
},
methods: { methods: {
/* /*
* @params:传入的为一个key-value的对象 * @params:传入的为一个key-value的对象
...@@ -85,8 +88,10 @@ export default { ...@@ -85,8 +88,10 @@ export default {
}) })
**/ **/
// 获取省市信息 // 获取省市信息
provinceList(params = {}) { provinceList() {
params ? (params.subdistrict ? '' : (params.subdistrict = this.subdistrict)) : (params.subdistrict = this.subdistrict) var params = {}
params.subdistrict = this.subdistrict
// params ? (params.subdistrict ? '' : (params.subdistrict = this.subdistrict)) : (params.subdistrict = this.subdistrict)
let data = '' let data = ''
for (let key in params) { for (let key in params) {
data += '&' + key + '=' + params[key] data += '&' + key + '=' + params[key]
...@@ -137,21 +142,24 @@ export default { ...@@ -137,21 +142,24 @@ export default {
}) })
} }
}, },
selectProvince(val) { selectProvince(val) {
this.provinceForm.cityName = '' this.provinceForm.cityName = ''
this.provinceForm.townName = '' this.provinceForm.townName = ''
this.cityList = val.districts 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.districts 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)
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!