From 6a2a0cc5c62941ee34b337836b50a9e1b1170dbd Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 24 May 2020 15:28:51 +0800 Subject: [PATCH] feat(Area): use first city code when county list is empty (#6356) --- src/area/index.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/area/index.js b/src/area/index.js index 1463b2df6..9a4ac930c 100644 --- a/src/area/index.js +++ b/src/area/index.js @@ -197,17 +197,29 @@ export default createComponent({ this.$emit('confirm', values, index); }, + getDefaultCode() { + if (this.columnsPlaceholder.length) { + return PLACEHOLDER_CODE; + } + + const countyCodes = Object.keys(this.county); + if (countyCodes[0]) { + return countyCodes[0]; + } + + const cityCodes = Object.keys(this.city); + if (cityCodes[0]) { + return cityCodes[0]; + } + + return ''; + }, + setValues() { let { code } = this; if (!code) { - if (this.columnsPlaceholder.length) { - code = PLACEHOLDER_CODE; - } else if (Object.keys(this.county)[0]) { - code = Object.keys(this.county)[0]; - } else { - code = ''; - } + code = this.getDefaultCode(); } const { picker } = this.$refs;