[improvement] Area: support oversrea code (#1897)

This commit is contained in:
neverland
2018-10-09 16:28:19 +08:00
committed by GitHub
parent f5e114cf08
commit ae15bbd141
5 changed files with 64 additions and 44 deletions

View File

@@ -99,6 +99,7 @@ import validateMobile from '../utils/validate/mobile';
const defaultData = {
name: '',
tel: '',
country: '',
province: '',
city: '',
county: '',
@@ -181,13 +182,13 @@ export default create({
},
areaText() {
const { province, city, county, areaCode } = this.data;
const { country, province, city, county, areaCode } = this.data;
if (areaCode) {
const arr = [province, city, county].filter(text => text);
if (province === city) {
arr.shift();
const arr = [country, province, city, county];
if (province && province === city) {
arr.splice(1, 1);
}
return arr.join('/');
return arr.filter(text => text).join('/');
}
return '';
}
@@ -225,19 +226,19 @@ export default create({
},
onAreaConfirm(values) {
const areaCode = (values[2] || values[1] || values[0]).code;
this.showAreaPopup = false;
this.data.areaCode = areaCode;
this.assignAreaValues(values);
this.assignAreaValues();
this.$emit('change-area', values);
},
assignAreaValues(values) {
Object.assign(this.data, {
province: values[0] ? values[0].name : '',
city: values[1] ? values[1].name : '',
county: values[2] ? values[2].name : ''
});
const { area } = this.$refs;
if (area) {
const detail = area.getArea();
detail.areaCode = detail.code;
delete detail.code;
Object.assign(this.data, detail);
}
},
onSave() {
@@ -299,12 +300,7 @@ export default create({
// set area code to area component
setAreaCode(code) {
this.data.areaCode = code || '';
this.$nextTick(() => {
const { area } = this.$refs;
if (area) {
this.assignAreaValues(area.getValues());
}
});
code && this.$nextTick(this.assignAreaValues);
},
setAddressDetail(value) {