From b85aa12acad18f3b0ce9d590a87e5f4016ed9b1a Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Mon, 08 Nov 2021 12:04:35 +0800 Subject: [PATCH] 修复增加options的问题 --- forms/chinaArea/ChinaLocations.weapp.js | 33 +++++++++++++++++++++++++++++++-- 1 files changed, 31 insertions(+), 2 deletions(-) diff --git a/forms/chinaArea/ChinaLocations.weapp.js b/forms/chinaArea/ChinaLocations.weapp.js index d674b32..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') { @@ -145,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