From 570084e543239f927d37bdbfa1594d086ccc873e Mon Sep 17 00:00:00 2001
From: quanyawei <401863037@qq.com>
Date: Mon, 05 Feb 2024 14:55:54 +0800
Subject: [PATCH] fix:bug修复

---
 src/views/hotMap/index.vue |   81 +++++++++++++++++++++++++---------------
 1 files changed, 51 insertions(+), 30 deletions(-)

diff --git a/src/views/hotMap/index.vue b/src/views/hotMap/index.vue
index f68d0a0..b788b45 100644
--- a/src/views/hotMap/index.vue
+++ b/src/views/hotMap/index.vue
@@ -26,7 +26,6 @@
             v-model="orgId"
             size="small"
             placeholder="���������"
-            disabled
             @change="regionData"
           >
             <el-option
@@ -102,11 +101,11 @@
       heatmap: null,
       markerClusterer: null,
       orgData: [],
-      orgId: 71,
+      orgId: null,
       city: '������',
       formInline: {
-        city: '���������',
-        cityCode: '210381',
+        city: '',
+        cityCode: '',
         dayType: 'hour',
         starTime: '',
         endTime: '',
@@ -227,6 +226,7 @@
         speed: 2
       },
       polygon: null,
+      districtSearch: null,
       dateTimes: [],
       activeItem: {},
       markerList: []
@@ -251,18 +251,18 @@
       },
       deep: true
     },
-    'formInline.city': {
-      handler: function (newVal, oldVal) {
-        console.log('newVal', newVal === '')
-        if (newVal !== '') {
-          this.init1()
-          if (!!this.formInline.starTime && !!this.formInline.endTime) {
-            this.onSubmit()
-          }
-        }
-      },
-      deep: true
-    },
+    // 'formInline.city': {
+    //   handler: function (newVal, oldVal) {
+    //     console.log('newVal', newVal === '')
+    //     if (newVal !== '') {
+    //       this.init1()
+    //       if (!!this.formInline.starTime && !!this.formInline.endTime) {
+    //         this.onSubmit()
+    //       }
+    //     }
+    //   },
+    //   deep: true
+    // },
     activeItem: {
       handler (newVal, oldVal) {
         if (this.markerList.length > 0) {
@@ -276,14 +276,12 @@
       deep: true
     }
   },
+  created () {
+  },
   mounted () {
     let dataTime = dayjs().format('YYYY-MM-DD')
     this.getOrganizationId()
     this.getData(`${dataTime} 00`)
-    this.$nextTick(() => {
-      this.initMap()
-      this.createHeatMap()
-    })
   },
 
   destroyed () {
@@ -323,7 +321,7 @@
     initMap () {
       var map = new AMap.Map('mapd', {
         resizeEnable: true,
-        zooms: [10, 10],
+        zooms: [1, 10],
         zoom: 10,
       })
       this.map = map
@@ -333,12 +331,13 @@
     init1 () { // ������������
       var that = this
       this.map.setCity(this.formInline.city)
-      console.log('������', this.formInline.cityCode)
       if (that.polygon) {
         that.map.remove(that.polygon)
+        that.map.remove(that.districtSearch)
+        that.polygon = null
+        that.districtSearch = null
       }
-      console.log('that.polygon', that.polygon)
-      AMap.plugin('AMap.DistrictSearch', function () {
+      this.districtSearch = AMap.plugin('AMap.DistrictSearch', function () {
         new AMap.DistrictSearch({
           extensions: 'all',
           subdistrict: 0
@@ -382,7 +381,7 @@
             }
             this.heatMapData = []
             this.heatMapData = res.data
-            this.dataProcessing()
+            this.dataProcessing(this.heatMapData)
             this.heatmap.setDataSet({
               data: this.heatMapData,
               max: this.selectSensor.maxNumber
@@ -397,9 +396,11 @@
           console.log(err)
         })
     },
-    dataProcessing () {
+    dataProcessing (heatMapData) {
       // ���������������
-      const max = this.heatMapData.reduce((prev, current) => (prev.count > current.count ? prev : current)).count
+      console.log('this.heatMapData', this.heatMapData)
+      const max = heatMapData.reduce((prev, current) => (prev.count > current.count ? prev : current)).count
+
       // so2
       if (this.selectSensor.code === 'a21026') {
         if (max > 150 && max <= 475) {
@@ -532,6 +533,14 @@
       })
         .then(res => {
           this.orgData = res.data
+          let cityData = _.find(this.orgData, { id: this.orgId })
+          if (this.orgId === 73) {
+            this.formInline.city = cityData.cityName
+            this.formInline.cityCode = String(cityData.cityCode)
+          } else {
+            this.formInline.city = cityData.areaName
+            this.formInline.cityCode = String(cityData.areaCode)
+          }
         })
         .catch(err => {
           console.log(err)
@@ -554,7 +563,13 @@
         // this.map.clearMap()
         this.getDayListData()
         this.getData(this.formInline.starTime)
-        // this.init1()
+        this.$nextTick(() => {
+          if (this.map) {
+            this.map.destroy()
+          }
+          this.initMap()
+          this.createHeatMap()
+        })
         // this.map.setZoom(12)
       } else {
         this.$message({
@@ -567,8 +582,14 @@
     },
     regionData (id) {
       let cityData = _.find(this.orgData, { id: id })
-      this.formInline.city = cityData.areaName
-      this.formInline.cityCode = cityData.areaCode
+      if (id === 73) {
+        this.formInline.city = cityData.cityName
+        this.formInline.cityCode = String(cityData.cityCode)
+      } else {
+        this.formInline.city = cityData.areaName
+        this.formInline.cityCode = String(cityData.areaCode)
+      }
+      console.log('cityData', cityData)
     },
     selectHourData (data) {
       if (data) {

--
Gitblit v1.8.0