From 244e58a0b0c99e020c48eb67c3dc800016fd2855 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Wed, 24 Nov 2021 18:10:17 +0800 Subject: [PATCH] 调整单行描述组件显示策略 --- forms/chinaArea/ChinaLocations.weapp.js | 35 +++++++++++++++++++++++++++++++---- 1 files changed, 31 insertions(+), 4 deletions(-) diff --git a/forms/chinaArea/ChinaLocations.weapp.js b/forms/chinaArea/ChinaLocations.weapp.js index b6b3e04..7c1986d 100644 --- a/forms/chinaArea/ChinaLocations.weapp.js +++ b/forms/chinaArea/ChinaLocations.weapp.js @@ -1,5 +1,5 @@ /** - * ChinaLocations + * ChinaLocations For WeApp * @author Tevin */ @@ -35,6 +35,7 @@ const city = { label: children1[code2].name, value: code2, + area: children1[code2].area, // 电话区码 children: [], }; if (typeof children1[code2].children !== 'undefined') { @@ -84,7 +85,6 @@ }, // 省市区名称 getRegionNames(regions, callback) { - if (typeof regions === 'string') { regions = regions.split(','); } @@ -109,7 +109,6 @@ }, // 省市区文本转code getRegionCodes(regions, callback) { - if (typeof regions === 'string') { regions = regions.split(','); } @@ -147,6 +146,34 @@ } } return codes; - }, + // 电话区码 + getRegionsArea(regions) { + if (typeof regions === 'string') { + regions = regions.split(','); + } + if (!regions || regions.length === 0 || !regions[0]) { + return ''; + } + let area = ''; + // 省 + for (let provinceCode in ChinaLocationData) { + if (ChinaLocationData.hasOwnProperty(provinceCode)) { + if (provinceCode === regions[0]) { + // 市 + const provinceChildren = ChinaLocationData[provinceCode].children; + for (let cityCode in provinceChildren) { + if (provinceChildren.hasOwnProperty(cityCode)) { + if (cityCode === regions[1]) { + area = provinceChildren[cityCode].area; + break; + } + } + } + break; + } + } + } + return area; + } }; \ No newline at end of file -- Gitblit v1.9.1