[improvement] Area: support oversrea code (#1897)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -120,26 +120,6 @@ test('valid postal code', () => {
|
||||
expect(errorInfo.postalCode).toBeFalsy();
|
||||
});
|
||||
|
||||
test('select area', () => {
|
||||
const wrapper = mount(AddressEdit, {
|
||||
propsData: {
|
||||
areaList
|
||||
}
|
||||
});
|
||||
const { vm } = wrapper;
|
||||
const { data } = vm;
|
||||
|
||||
vm.onAreaConfirm([
|
||||
{ name: '北京市' },
|
||||
{ name: '北京市' },
|
||||
{ name: '朝阳区', code: '123456' }
|
||||
]);
|
||||
expect(data.province).toEqual('北京市');
|
||||
expect(data.city).toEqual('北京市');
|
||||
expect(data.county).toEqual('朝阳区');
|
||||
expect(data.areaCode).toEqual('123456');
|
||||
});
|
||||
|
||||
test('on change detail', () => {
|
||||
const wrapper = mount(AddressEdit);
|
||||
const field = wrapper.findAll('.van-field__control').at(3);
|
||||
|
||||
Reference in New Issue
Block a user