city.vue
3.26 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<style scoped>
.address-select {
margin-bottom: 10px;
/*margin-left: 5em;
height: 30px !important;
overflow: hidden;
width: 407px !important;
border: 0px !important;*/
}
.address-readonly {
color: #606f7a;
background: #E1E1E1 !important;
}
.address-select span {
display: inline-block;
min-width:27%;
text-align: right;
}
.address-select span:first-child {
margin-left: 10px;
}
select {
width: 110px;
height: 32px;
line-height: 32px;
border: 0 none;
}
</style>
<template>
<div class="address-select address-readonly" v-if="readonly" :style="styles">
<span :id='id' style='margin-left:5em;'>{{province}}</span>
<span>{{city}}</span>
<span>{{area}}</span>
</div>
<div class="address-select" v-else :style="styles" :disabled='disabled'>
<select v-model="province" :style="selectstyle" class="hover-none" :id='id' style='margin-left:5em;' :disabled='disabled'>
<option v-for="item in areaMap.provinceArray" :value="item">{{item}}</option>
</select>
省
<select v-model="city" :style="selectstyle" class="hover-none" :disabled='disabled'>
<option v-for="item in cityArray.sub" :value="item.name">{{item.name}}</option>
</select>
市
<select v-model="area" :style="selectstyle" class="hover-none" :disabled='disabled'>
<option v-for="item in areaArray.sub" :value="item.name">{{item.name}}</option>
</select>
区
</div>
</template>
<script>
module.exports = {
props: {
province: {
type: String,
twoWay: true,
default: '请选择'
},
city: {
type: String,
twoWay: true,
default: '请选择'
},
area: {
type: String,
twoWay: true,
default: '请选择'
},
readonly: {
type: Boolean,
default: false
},
styles:{},
selectstyle:{},
classname:{type:String,default:''},
id:{
type:String
},
hovers:{
type:String
},
disabled:{
type:Boolean
}
},
data: function () {
return {
firstProvinceModified: true,
firstCityModified: true
};
},
computed: {
areaMap: function () {
return this.$store.state.area;
},
cityArray: function () {
if (this.province === '请选择' || !this.province) {
return {
sub: []
};
}
return this.areaMap.map[this.province];
},
areaArray: function () {
if (this.province === '请选择' || this.city === '请选择' || !this.province || !this.city) {
return {
sub: []
};
}
if (!this.cityArray[this.city]) {
return {
sub: []
};
}
return this.cityArray[this.city];
}
},
watch: {
province: function () {
if (this.firstProvinceModified) {
this.firstProvinceModified = false;
} else {
this.city = '请选择';
this.area = '请选择';
}
},
city: function () {
if (this.firstCityModified) {
this.firstCityModified = false;
} else {
this.area = '请选择';
}
}
}
};
</script>