| | |
| | | /** |
| | | * ChinaLocations |
| | | * ChinaLocations For WeApp |
| | | * @author Tevin |
| | | */ |
| | | |
| | |
| | | const city = { |
| | | label: children1[code2].name, |
| | | value: code2, |
| | | area: children1[code2].area, // 电话区码 |
| | | children: [], |
| | | }; |
| | | if (typeof children1[code2].children !== 'undefined') { |
| | |
| | | }, |
| | | // 省市区名称 |
| | | getRegionNames(regions, callback) { |
| | | |
| | | if (typeof regions === 'string') { |
| | | regions = regions.split(','); |
| | | } |
| | |
| | | }, |
| | | // 省市区文本转code |
| | | getRegionCodes(regions, callback) { |
| | | |
| | | if (typeof regions === 'string') { |
| | | regions = regions.split(','); |
| | | } |
| | |
| | | } |
| | | } |
| | | 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; |
| | | } |
| | | }; |