DESKTOP-SVI9JE1\muzen преди 1 година
родител
ревизия
5effb7b641
променени са 1 файла, в които са добавени 40 реда и са изтрити 1 реда
  1. 40 1
      src/mixin/index.js

+ 40 - 1
src/mixin/index.js

@@ -10,6 +10,8 @@ import { list as functionList } from '@/api/device/function'
 
 import { options as blogClass } from '@/api/music/blogclass'
 
+import { options as mapList } from '@/api/operation/map'
+
 // 设备列表
 const devMixin = {
   data() {
@@ -615,6 +617,42 @@ const systemMixin = {
   }
 }
 
+// 省市区
+const mapMixin = {
+  data() {
+    return {
+      mapOptions: []
+    }
+  },
+  async mounted() {
+    await this.getMapOptions()
+  },
+  methods: {
+    // 省市区
+    getMapOptions() {
+      return new Promise((reslove, reject) => {
+        mapList().then(res => {
+          if (res.code === 0) {
+            reslove(this.mapOptions = res.data)
+          }
+        })
+      })
+    },
+    
+    areaFormatter(row) {
+      if (this.mapOptions.length > 0) {
+        let province = this.mapOptions.find(i => i.id == row.province)
+        let provinceName = province.name
+        let city = province.childList.length > 0 ? province.childList.find(i => i.id == row.city) : ''
+        let cityName = city ? `-${city.name}` : ''
+        let area = city && city.childList.length > 0 ? city.childList.find(i => i.id == row.area) : ''
+        let areaName = area ? `-${area.name}` : ''
+        return `${provinceName}${cityName}${areaName}`
+      }
+    },
+  }
+}
+
 export {
   devMixin,
   devModeMixin,
@@ -640,5 +678,6 @@ export {
   coverMixin,
   channelMixin,
   systemMixin,
-  blogClassMixin
+  blogClassMixin,
+  mapMixin
 }