Browse Source

地图点击社区交互

Shannon_mu 2 years ago
parent
commit
62cc8b4b29

+ 12 - 4
commandCenter/src/components/common/Header.vue

@@ -92,15 +92,21 @@ export default {
         };
     },
     computed: {
-        ...mapState(['globalCommunity']),
+        ...mapState(['globalCommunity','thisArr']),
         menuList() {
             return this.$store.getters['getMenuList'] || [];
         }
     },
     watch: {
-        globalCommunity: {
+        // globalCommunity: {
+        //     handler(newVal, oldVal) {
+        //         // this.communityValue = !!newVal.type ? [newVal.value[0]] : newVal;
+        //     },
+        //     deep: true
+        // },
+        thisArr: {
             handler(newVal, oldVal) {
-                console.log(newVal, oldVal);
+                this.communityValue =  this.$store.getters['getThisArr']
             },
             deep: true
         }
@@ -142,6 +148,7 @@ export default {
             this.time.thisTime = this.$moment().format('YYYY/MM/DD');
         },
         selectChange() {
+            console.log(this.communityValue);
             let thisValue = this.$refs.multipleValue.getCheckedNodes()[0];
             // 选择是否为公司
             if (!!thisValue && thisValue.data.type == 'org') {
@@ -157,7 +164,7 @@ export default {
                 });
             } else {
                 this.$store.commit('setGlobalCommunity', {
-                    value: [thisValue.value]
+                    value: [!!thisValue ? thisValue.value : null]
                 });
             }
         },
@@ -176,6 +183,7 @@ export default {
                 if (status == 0) {
                     this.scOptions = data;
                     this.communityValue = [data[0].value];
+                    this.$store.commit('setFindCompanyCommunityTree', data);
                     if (data[0].type == 'org') {
                         let arrs = [];
                         let ids = [data[0].value];

+ 16 - 2
commandCenter/src/store/store.js

@@ -30,7 +30,9 @@ const store = new Vuex.Store({
         communityArray: [],
         homeCommunityAll: '',
         scale: "",
-        globalCommunity: {}
+        globalCommunity: {},
+        findCompanyCommunityTree: [],
+        thisArr: []
     },
     getters: {
         getTheme(state) {
@@ -87,7 +89,13 @@ const store = new Vuex.Store({
         },
         getGlobalCommunity(state) {
             return state.globalCommunity;
-        }
+        },
+        getFindCompanyCommunityTree(state) {
+            return state.findCompanyCommunityTree;
+        },
+        getThisArr(state) {
+            return state.thisArr;
+        },
     },
     mutations: {
         setPopups(state, data) {
@@ -140,6 +148,12 @@ const store = new Vuex.Store({
         },
         setGlobalCommunity(state, data) {
             state.globalCommunity = data;
+        },
+        setFindCompanyCommunityTree(state, data) {
+            state.findCompanyCommunityTree = data;
+        },
+        setThisArr(state, data) {
+            state.thisArr = data;
         }
     },
     actions: {

+ 18 - 16
commandCenter/src/views/commandDispatch/index.vue

@@ -101,7 +101,7 @@ export default {
         };
     },
     computed: {
-        ...mapState(['homeCommunityAll']),
+        ...mapState(['globalCommunity']),
         points() {
             let showArr = [];
             this.point.map((item) => {
@@ -120,16 +120,17 @@ export default {
         }
     },
     watch: {
-        //全局社区接口调用
-        homeCommunityAll(val) {
-            if (!!val) {
-                this.mixins_query.communityId = val;
-                this.getData();
-                this.getImg();
-                this.showMap = false;
-            } else {
-                this.showMap = true;
-            }
+        globalCommunity: {
+            handler(newVal, oldVal) {
+                this.mixins_query.communityId = !!newVal.type ? null : newVal.value.join();
+                this.mixins_query.companyIds = !!newVal.type ? newVal.value.join() : null;
+                this.showMap = !!newVal.type ? true : false;
+                if (newVal.type == null || newVal.type == undefined) {
+                    this.getData();
+                    this.getImg();
+                }
+            },
+            deep: true
         }
     },
     methods: {
@@ -268,11 +269,12 @@ export default {
     },
 
     created() {
-        this.mixins_query.communityId = this.homeCommunityAll;
-        if (!!this.mixins_query.communityId) {
-            this.showMap = false;
-            this.getImg();
-            this.getData();
+        debugger;
+        const { type, value } = this.globalCommunity;
+        this.mixins_query.communityId = !!type ? null : !!value ? value.join() : null;
+        this.mixins_query.companyIds = !!type ? value.join() : null;
+        if (!!type) {
+            this.showMap = true;
         }
     }
 };

+ 57 - 41
commandCenter/src/views/commandDispatch/map.vue

@@ -21,41 +21,29 @@ export default {
             addressName: '', //地址查询名称
             poisArray: [],
             loadding: true,
-            mixins_query: {
-                communityId: ''
-            },
             centet: []
         };
     },
     mounted() {},
     computed: {
-        ...mapState(['homeCommunityAll']),
+        ...mapState(['globalCommunity', 'findCompanyCommunityTree']),
         poisArrays() {
-            return this.poisArray;
-            // let arrs = [];
-            // this.poisArray.map((item) => {
-            //     if (!!this.mixins_query.communityId) {
-            //         if (item.id == this.mixins_query.communityId) {
-            //             arrs = [item];
-            //         }
-            //     } else {
-            //         arrs = this.poisArray;
-            //     }
-            // });
-            // return arrs;
+            let arrs = [];
+            this.fitersValue(arrs, this.findCompanyCommunityTree);
+            return arrs;
         }
     },
     watch: {
-        homeCommunityAll(val) {
-            if (!!val) {
-                this.mixins_query.communityId = val;
+        globalCommunity: {
+            handler(newVal, oldVal) {
                 if (!!this.map) {
                     this.map.clearMap();
                 }
-            }
-            if (this.poisArrays.length > 0) {
-                this.addIcon(this.poisArrays);
-            }
+                if (this.poisArrays.length > 0) {
+                    this.addIcon(this.poisArrays);
+                }
+            },
+            deep: true
         }
     },
 
@@ -98,7 +86,7 @@ export default {
                 });
                 self.marker.setLabel({
                     offset: new AMap.Pixel(-15, 50),
-                    content: `${item.communityName}`
+                    content: `${item.name}`
                 });
                 if (self.poisArrays.length < 2) {
                     self.map.setFitView();
@@ -109,9 +97,36 @@ export default {
             });
         },
         setCommunity(its) {
-            this.$store.commit('setHomeCommunityAll', its.id);
+            this.$store.commit('setGlobalCommunity', {
+                value: [its.value]
+            });
+            let newarr = this.finterParent(this.findCompanyCommunityTree, its.value);
+            newarr.push(its.value);
+            this.$store.commit('setThisArr', newarr);
             this.$parent.showMap = false;
         },
+        finterParent(data, id) {
+            // 深度遍历查找
+            function dfs(data, id, parents) {
+                for (var i = 0; i < data.length; i++) {
+                    var item = data[i];
+                    // 找到id则返回父级id
+                    if (item.value === id) return parents;
+                    // children不存在或为空则不递归
+                    if (!item.children || !item.children.length) continue;
+                    // 往下查找时将当前id入栈
+                    parents.push(item.value);
+
+                    if (dfs(item.children, id, parents).length) return parents;
+                    // 深度遍历查找未找到时当前id 出栈
+                    parents.pop();
+                }
+                // 未找到时返回空数组
+                return [];
+            }
+
+            return dfs(data, id, []);
+        },
         //搜索区域
         districtMask(val) {
             if (!this.district) {
@@ -157,10 +172,12 @@ export default {
             });
         },
         getPoin(resolve) {
-            this.$http.get('/sc-community/assets/community/list').then(({ data, status, msg }) => {
+            this.$http.get('/sc-community/assets/tree/community/findCompanyCommunityTree').then(({ data, status, msg }) => {
                 if (status == 0) {
-                    this.poisArray = data;
-                    this.centet = this.getPointsCenter(data);
+                    let arrs = [];
+                    this.fitersValue(arrs, data);
+                    this.centet = this.getPointsCenter(arrs);
+
                     resolve && resolve(true);
                 }
             });
@@ -204,25 +221,24 @@ export default {
                 Math.floor(((tmp_lng * 180) / Math.PI) * 1000000) / 1000000,
                 Math.floor(((tmp_lat * 180) / Math.PI) * 1000000) / 1000000
             ];
+        },
+        fitersValue(arrs, value) {
+            let thisValue = this.globalCommunity.value;
+            value.map((item) => {
+                if (item.type == 'org') {
+                    this.fitersValue(arrs, item.children);
+                } else {
+                    if (thisValue.includes(item.parentId)) {
+                        arrs.push(item);
+                    }
+                }
+            });
         }
     },
     destroyed() {
         this.map && this.map.destroy();
     },
     created() {
-        // this.getPoin();
-        // new Promise((resolve) => {
-        //     this.getLoc(resolve);
-        // }).then(() => {
-        //     new Promise((resolve) => {
-        //         if (!!AMap) {
-        //             resolve(true);
-        //         }
-        //     }).then(() => {
-        //         this.init();
-        //     });
-        // });
-
         new Promise((resolve) => {
             this.getPoin(resolve);
         }).then(() => {

+ 4 - 16
commandCenter/src/views/communityAssets/assembly/allcommunit.js

@@ -8,7 +8,6 @@ export default {
     computed: {
         //全局社区
         ...mapState(['globalCommunity']),
-
         resize() {
             // 通过scale值来判断窗口是变化
             return this.$store.getters['getScale'];
@@ -17,14 +16,8 @@ export default {
     watch: {
         globalCommunity: {
             handler(newVal, oldVal) {
-                if (!!newVal.type) {
-                    this.mixins_query.communityId = null;
-                    this.mixins_query.companyIds = newVal.value.join();
-                } else {
-                    this.mixins_query.companyIds = null;
-                    this.mixins_query.communityId = newVal.value.join();
-                }
-
+                this.mixins_query.communityId = !!newVal.type ? null : newVal.value.join();
+                this.mixins_query.companyIds = !!newVal.type ? newVal.value.join() : null;
                 this.getData();
             },
             deep: true
@@ -36,12 +29,7 @@ export default {
     methods: {},
     created() {
         const { type, value } = this.globalCommunity
-        if (!!type) {
-            this.mixins_query.communityId = null;
-            this.mixins_query.companyIds = value.join();
-        } else {
-            this.mixins_query.companyIds = null;
-            this.mixins_query.communityId = value.join();
-        }
+        this.mixins_query.communityId = !!type ? null : !!value ? value.join() : null;
+        this.mixins_query.companyIds = !!type ? value.join() : null;
     }
 };

+ 12 - 7
commandCenter/src/views/financialAnalysis/smallModuleIndex/allcommunit.js

@@ -7,7 +7,7 @@ export default {
   },
   computed: {
     //全局社区
-    ...mapState(['homeCommunityAll']),
+    ...mapState(['globalCommunity']),
 
     resize() {
       // 通过scale值来判断窗口是变化
@@ -15,16 +15,21 @@ export default {
     }
   },
   watch: {
-    //全局社区接口调用
-    'homeCommunityAll'(n) {
-      this.mixins_query.communityId = n;
-      this.getData();
-    }
+    globalCommunity: {
+      handler(newVal, oldVal) {
+        this.mixins_query.communityId = !!newVal.type ? null : newVal.value.join();
+        this.mixins_query.companyIds = !!newVal.type ? newVal.value.join() : null;
+        this.getData();
+      },
+      deep: true
+    },
   },
   methods: {
   },
   created() {
-    this.mixins_query.communityId = this.homeCommunityAll;
+    const { type, value } = this.globalCommunity
+    this.mixins_query.communityId = !!type ? null : !!value ? value.join() : null;
+    this.mixins_query.companyIds = !!type ? value.join() : null;
     this.getData();
   }
 }

+ 11 - 6
commandCenter/src/views/industrialInvestment/assembly/allcommunit.js

@@ -7,7 +7,7 @@ export default {
     },
     computed: {
         //全局社区
-        ...mapState(['homeCommunityAll']),
+        ...mapState(['globalCommunity']),
 
         resize() {
             // 通过scale值来判断窗口是变化
@@ -16,9 +16,13 @@ export default {
     },
     watch: {
         //全局社区接口调用
-        homeCommunityAll(n) {
-            this.mixins_query.communityId = n;
-            this.getData();
+        globalCommunity: {
+            handler(newVal, oldVal) {
+                this.mixins_query.communityId = !!newVal.type ? null : newVal.value.join();
+                this.mixins_query.companyIds = !!newVal.type ? newVal.value.join() : null;
+                this.getData();
+            },
+            deep: true
         },
         resize(va) {
             // console.log(va);
@@ -26,7 +30,8 @@ export default {
     },
     methods: {},
     created() {
-        this.mixins_query.communityId = this.homeCommunityAll;
-        // this.getData();
+        const { type, value } = this.globalCommunity
+        this.mixins_query.communityId = !!type ? null : !!value ? value.join() : null;
+        this.mixins_query.companyIds = !!type ? value.join() : null;
     }
 };

+ 11 - 6
commandCenter/src/views/operationalServices/assembly/allcommunit.js

@@ -7,7 +7,7 @@ export default {
     },
     computed: {
         //全局社区
-        ...mapState(['homeCommunityAll']),
+        ...mapState(['globalCommunity']),
 
         resize() {
             // 通过scale值来判断窗口是变化
@@ -16,9 +16,13 @@ export default {
     },
     watch: {
         //全局社区接口调用
-        homeCommunityAll(n) {
-            this.mixins_query.communityId = n;
-            this.getData();
+        globalCommunity: {
+            handler(newVal, oldVal) {
+                this.mixins_query.communityId = !!newVal.type ? null : newVal.value.join();
+                this.mixins_query.companyIds = !!newVal.type ? newVal.value.join() : null;
+                this.getData();
+            },
+            deep: true
         },
         resize(va) {
             // console.log(va);
@@ -26,7 +30,8 @@ export default {
     },
     methods: {},
     created() {
-        this.mixins_query.communityId = this.homeCommunityAll;
-        // this.getData();
+        const { type, value } = this.globalCommunity
+        this.mixins_query.communityId = !!type ? null : !!value ? value.join() : null;
+        this.mixins_query.companyIds = !!type ? value.join() : null;
     }
 };

+ 12 - 8
commandCenter/src/views/smallModule/allcommunit.js

@@ -7,7 +7,7 @@ export default {
   },
   computed: {
     //全局社区
-    ...mapState(['homeCommunityAll']),
+    ...mapState(['globalCommunity']),
 
     resize() {
       // 通过scale值来判断窗口是变化
@@ -16,17 +16,21 @@ export default {
   },
   watch: {
     //全局社区接口调用
-    'homeCommunityAll'(n) {
-      this.mixins_query.communityId = n;
-      this.getData();
-    }, resize(va) {
-      // console.log(va);
-    }
+    globalCommunity: {
+      handler(newVal, oldVal) {
+        this.mixins_query.communityId = !!newVal.type ? null : newVal.value.join();
+        this.mixins_query.companyIds = !!newVal.type ? newVal.value.join() : null;
+        this.getData();
+      },
+      deep: true
+    },
   },
   methods: {
   },
   created() {
-    this.mixins_query.communityId = this.homeCommunityAll;
+    const { type, value } = this.globalCommunity
+    this.mixins_query.communityId = !!type ? null : !!value ? value.join() : null;
+    this.mixins_query.companyIds = !!type ? value.join() : null;
     this.getData();
   }
 }