Skip to content

Commit

Permalink
Optimize the function of 'getAreaCode'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcc committed May 17, 2018
1 parent e6c937f commit 4189986
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/v-distpicker.js

Large diffs are not rendered by default.

27 changes: 25 additions & 2 deletions src/Distpicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,36 @@ export default {
chooseArea(name) {
this.currentArea = name
},
getAreaCodeByPreCode(name, preCode) {
let codes = []
for(let x in DISTRICTS) {
for(let y in DISTRICTS[x]) {
if(name === DISTRICTS[x][y]) {
codes.push(y)
}
}
}
if (codes.length > 1) {
let index
codes.forEach((item, i) => {
if (item.slice(0, 2) == preCode) {
index = i
}
})
return codes[index]
} else {
return codes[0]
}
},
getAreaCode(name, check = '') {
for(let x in DISTRICTS) {
for(let y in DISTRICTS[x]) {
if(name === DISTRICTS[x][y]) {
if (check.length > 0) {
if (y.slice(0, 2) !== this.getAreaCode(check).slice(0, 2)) {
if (y.slice(0, 2) !== this.getAreaCodeByPreCode(check, y.slice(0, 2)).slice(0, 2)) {
continue
} else {
return y
Expand All @@ -248,7 +272,6 @@ export default {
}
},
getCodeValue(code) {
console.log(code)
for(let x in DISTRICTS) {
for(let y in DISTRICTS[x]) {
if(code === parseInt(y)) {
Expand Down

0 comments on commit 4189986

Please sign in to comment.