mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 03:11:15 +00:00
[improvement] Area: support oversrea code (#1897)
This commit is contained in:
@@ -100,6 +100,11 @@ export default create({
|
||||
}));
|
||||
|
||||
if (code) {
|
||||
// oversea code
|
||||
if (code[0] === '9' && type === 'city') {
|
||||
code = '9';
|
||||
}
|
||||
|
||||
result = result.filter(item => item.code.indexOf(code) === 0);
|
||||
}
|
||||
|
||||
@@ -108,10 +113,15 @@ export default create({
|
||||
|
||||
// get index by code
|
||||
getIndex(type, code) {
|
||||
const compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
|
||||
let compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
|
||||
const list = this.getList(type, code.slice(0, compareNum - 2));
|
||||
code = code.slice(0, compareNum);
|
||||
|
||||
// oversea code
|
||||
if (code[0] === '9' && type === 'province') {
|
||||
compareNum = 1;
|
||||
}
|
||||
|
||||
code = code.slice(0, compareNum);
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
if (list[i].code.slice(0, compareNum) === code) {
|
||||
return i;
|
||||
@@ -153,7 +163,36 @@ export default create({
|
||||
},
|
||||
|
||||
getValues() {
|
||||
return this.$refs.picker ? this.$refs.picker.getValues() : [];
|
||||
return this.$refs.picker ? this.$refs.picker.getValues().filter(value => !!value) : [];
|
||||
},
|
||||
|
||||
getArea() {
|
||||
const values = this.getValues();
|
||||
const area = {
|
||||
code: '',
|
||||
country: '',
|
||||
province: '',
|
||||
city: '',
|
||||
county: ''
|
||||
};
|
||||
|
||||
if (!values.length) {
|
||||
return area;
|
||||
}
|
||||
|
||||
const names = values.map(item => item.name);
|
||||
|
||||
area.code = values[values.length - 1].code;
|
||||
if (area.code[0] === '9') {
|
||||
area.country = names[1] || '';
|
||||
area.province = names[2] || '';
|
||||
} else {
|
||||
area.province = names[0] || '';
|
||||
area.city = names[1] || '';
|
||||
area.county = names[2] || '';
|
||||
}
|
||||
|
||||
return area;
|
||||
},
|
||||
|
||||
reset() {
|
||||
|
Reference in New Issue
Block a user