Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit ac02fbb

Browse files
committed
fix #9
1 parent c69d634 commit ac02fbb

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/area-select.vue

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,32 @@
9494
9595
watch: {
9696
curProvince (val, oldVal) {
97-
this.isSetDefault = true;
97+
this.provinceChange(val);
98+
},
99+
100+
curCity (val, oldVal) {
101+
this.cityChange(val);
102+
},
103+
104+
curArea (val, oldVal) {
105+
this.areaChange(val);
106+
},
107+
108+
curStreet (val, oldVal) {
109+
this.streetChange(val);
110+
},
111+
112+
value () {
113+
if (isArray(this.value) && this.value.length && !this.isSetDefault) {
114+
this.beforeSetDefault();
115+
this.setDefaultValue();
116+
this.provinceChange(this.curProvince);
117+
}
118+
}
119+
},
120+
121+
methods: {
122+
provinceChange (val) {
98123
if (this.level === 0) {
99124
this.selectChange();
100125
return;
@@ -114,10 +139,11 @@
114139
} else {
115140
this.curCity = Object.keys(this.citys)[0];
116141
}
142+
this.cityChange(this.curCity);
117143
}
118144
},
119145
120-
curCity (val, oldVal) {
146+
cityChange (val) {
121147
if (this.level === 1) {
122148
this.selectChange();
123149
return;
@@ -138,10 +164,11 @@
138164
// fix 市级下不存在城区(#7)
139165
this.curArea = this.areas ? Object.keys(this.areas)[0] : val;
140166
}
167+
this.areaChange(this.curArea);
141168
}
142169
},
143-
144-
curArea (val, oldVal) {
170+
171+
areaChange (val) {
145172
if (!/^\d+$/.test(String(val))) {
146173
return;
147174
}
@@ -165,26 +192,18 @@
165192
} else {
166193
this.curStreet = this.streets ? Object.keys(this.streets)[0] : val;
167194
}
195+
this.streetChange(this.curStreet);
168196
}
169197
},
170198
171-
curStreet (val, oldVal) {
199+
streetChange (val) {
172200
if (!/^\d+$/.test(String(val))) {
173201
return;
174202
}
175203
this.curStreetCode = val;
176204
this.selectChange();
177205
},
178206
179-
value () {
180-
if (isArray(this.value) && this.value.length && !this.isSetDefault) {
181-
this.beforeSetDefault();
182-
this.setDefaultValue();
183-
}
184-
}
185-
},
186-
187-
methods: {
188207
getAreaText (selected) {
189208
const texts = [];
190209
let city = '';
@@ -269,6 +288,7 @@
269288
this.$nextTick(() => {
270289
this.defaults = [];
271290
this.isCode = false;
291+
this.isSetDefault = false;
272292
});
273293
},
274294

0 commit comments

Comments
 (0)