Răsfoiți Sursa

Merge branch 'dev/v4.8.94_yf' of qmx/jy into feature/v4.8.94

yangfeng 1 an în urmă
părinte
comite
998adf2563

+ 85 - 10
src/web/staticres/js/selector/area-city-country.js

@@ -72,6 +72,24 @@ var areaCityCountrySelector = {
   name: 'areaCityCountry',
   template: areaCityCountryTemp,
   props: {
+     /**
+     *  const obj = {
+          安徽: {},
+          广西: {
+            贺州市: ['富川瑶族自治县']
+          },
+          河南: {
+            郑州市: []
+          }
+        }
+     *  父组件传递要显示的省市县区数据源(需要再从chinaMapJSON中过滤,拿到完整的省市县区数据源)
+     */
+    source: {
+      type: Object,
+      default () {
+        return {}
+      }
+    },
     // 初始化选中的地区('': 不选, {}:全国)
     initMap: {
       type: [Object, String],
@@ -189,6 +207,9 @@ var areaCityCountrySelector = {
     }
   },
   watch: {
+    source (val) {
+      this.initAreaMap()
+    }
     // initMap (val) {
     //   this.setState(val)
     // }
@@ -293,15 +314,17 @@ var areaCityCountrySelector = {
     initAreaMap () {
       const provinceList = this.getCitiesFromJSONArray()
       const specialRegion = ['全国', '香港', '澳门', '台湾']
-      // 如果需要包含全国、全部选项
-      if (this.isHaveAll) {
-        provinceList.unshift({
-          name: '全国',
-          checked: false,
-          disabled: false,
-          indeterminate: false,
-          children: []
-        })
+      if (Object.keys(this.source).length === 0) {
+        // 如果需要包含全国、全部选项
+        if (this.isHaveAll) {
+          provinceList.unshift({
+            name: '全国',
+            checked: false,
+            disabled: false,
+            indeterminate: false,
+            children: []
+          })
+        }
       }
       provinceList.forEach((province) => {
         province.children.unshift({
@@ -390,7 +413,12 @@ var areaCityCountrySelector = {
           }
         }
       })
-      return standardData
+      if (this.source && Object.keys(this.source).length > 0) {
+        // 显示部分省市县区数据(接口返回)
+        return this.formatSourceMapJson(standardData)
+      } else {
+        return standardData
+      }
     },
     /**
      * 将过滤好的地区数据转换成map格式(根据场景需要转换)
@@ -878,6 +906,53 @@ var areaCityCountrySelector = {
         }
       }
       return tagsArr.join(mark)
+    },
+    // 从chinaMapJSON数据中过滤出需要展示的省市县数据
+    formatSourceMapJson (arr) {
+      // const obj = {
+      //   安徽: {},
+      //   广西: {
+      //     贺州市: ['富川瑶族自治县']
+      //   },
+      //   河南: {
+      //     郑州市: []
+      //   }
+      // }
+      const obj = this.source
+      const data = JSON.parse(JSON.stringify(arr))
+      const newData = data.filter(item => {
+        const province = item.name
+        if (obj[province]) {
+          const cities = item.children
+          const objCities = Object.keys(obj[province])
+          const filteredCities = cities.filter(city => {
+            if (Object.keys(obj[province]).length === 0) {
+              return city
+            } else {
+              return objCities.includes(city.name)
+            }
+          })
+          filteredCities.forEach(city => {
+            const districts = city.children
+            const objDistricts = obj[province][city.name]
+            if (objDistricts) {
+              const filteredDistricts = districts.filter(district => {
+                if (objDistricts.length === 0) {
+                  return district
+                } else {
+                  return objDistricts.includes(district.name)
+                }
+              })
+              city.children = filteredDistricts
+            }
+          })
+          item.children = filteredCities
+          return true
+        }
+        return false
+      })
+      // console.log(newData, 'newData')
+      return newData
     }
   }
 }

Fișier diff suprimat deoarece este prea mare
+ 0 - 0
src/web/staticres/js/selector/area-city-country.min.js


Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff