1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<template>
<div>
<el-select v-model="formData.country" :disabled="readonly">
<el-option v-for="(item) in treeList" :value="item.id" :label="$l(item, 'title')" :key="item.id" />
</el-select>
<el-select v-model="formData.province" class="ml-10" :disabled="readonly">
<el-option v-for="(item) in provinceList" :value="item.id" :label="$l(item, 'title')" :key="item.id" />
</el-select>
<el-select v-model="formData.city" class="ml-10" :disabled="readonly">
<el-option v-for="(item) in cityList" :value="item.id" :label="$l(item, 'title')" :key="item.id" />
</el-select>
</div>
</template>
<script>
import { getListTree } from "@/api/ecw/region";
export default {
props:{
country: Number,
city: Number,
province: Number,
readonly: Boolean
},
data(){
return {
formData:{
country: undefined,
province: undefined,
city: undefined
},
treeList: [],
// provinceList: [],
// cityList:[]
}
},
watch:{
city(val){
this.$set(this.formData, 'city', val)
},
province(val){
this.$set(this.formData, 'province', val)
},
country(val){
this.$set(this.formData, 'country', val)
},
'formData.city'(city){
this.$emit('cityChange', city)
},
'formData.country'(country){
this.$emit('countryChange', country)
},
'formData.province'(province){
this.$emit('provinceChange', province)
}
},
computed:{
provinceList(){
if(!this.formData.country) return []
let country = this.treeList.find(item => item.id == this.formData.country)
return country && country.children || []
},
cityList(){
if(!this.provinceList.length) return []
let province = this.provinceList.find(item => item.id == this.formData.province)
return province && province.children || []
}
},
created(){
getListTree({treeType: 1}).then(response => {
this.treeList = response.data
})
this.formData = {
country: this.country,
province: this.province,
city: this.city
}
}
}
</script>