From 568e137c3f2ae17f62b3b9ec9ebea37cb136bec0 Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Tue, 22 Feb 2022 15:21:28 +0800
Subject: [PATCH] 新增区域加载中公共组件

---
 forms/chinaArea/ChinaLocations.weapp.js |   37 ++++++++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/forms/chinaArea/ChinaLocations.weapp.js b/forms/chinaArea/ChinaLocations.weapp.js
index b6b3e04..72bf0ce 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') {
@@ -56,7 +57,7 @@
 
 export default {
     onReady(callback) {
-        if (ChinaLocationData.length > 0) {
+        if (locationTree.length > 0) {
             callback();
         } else {
             readyCallback = callback;
@@ -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