From a41fe1fd72c328471f7e051245c86237bbc3e568 Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Tue, 06 May 2025 15:01:20 +0800
Subject: [PATCH] 新建工单,地图坐标保存,坐标系转换处理; 详情中地图坐标系转换去除;

---
 src/views/tickets/ticket.vue |   65 +++++++++++++++++++++++---------
 1 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/src/views/tickets/ticket.vue b/src/views/tickets/ticket.vue
index dbcbffb..d93ca5c 100644
--- a/src/views/tickets/ticket.vue
+++ b/src/views/tickets/ticket.vue
@@ -463,6 +463,7 @@
 </template>
 
 <script>
+import { gcj02ToWgs84, wgs84ToGcj02 } from '@/utils/coordinateTransformation'
 import { getList, createTicket, getTicketInfo, flowEvent, getstatusCount, getStepInfo } from '@/api/tickets/ticket'
 import { export_json_to_excel } from '@/utils/exportExcel'
 import geoJson from '@/assets/geoJson.json'
@@ -1038,12 +1039,14 @@
           return
         }
 
+        let [lng, lat] = this.disposeLocation(true, this.form)
+
         const submitData = {
           eventName: this.form.name,
           content: this.form.content,
           workType: "1",
-          longitude: String(this.form.location[0]),
-          latitude: String(this.form.location[1]),
+          longitude: lng,
+          latitude: lat,
           address: this.form.address,
           workOrderTypeDictKey: this.form.type,
           aiType: Array.isArray(this.form.algorithm) ? this.form.algorithm : [this.form.algorithm], // 传数组
@@ -1099,13 +1102,16 @@
         if (!handlerValue || handlerValue === '未分配') {
           handlerValue = undefined
         }
+
+        let [lng, lat] = this.disposeLocation(true, this.form)
+
         const submitData = {
           id: this.form.id,
           eventName: this.form.name || undefined,
           content: this.form.content || undefined,
           workType: "1",
-          longitude: this.form.location?.[0] ? String(this.form.location[0]) : undefined,
-          latitude: this.form.location?.[1] ? String(this.form.location[1]) : undefined,
+          longitude: lng,
+          latitude: lat,
           address: this.form.address || undefined,
           workOrderTypeDictKey: this.form.type || undefined,
           aiType: this.form.algorithm && this.form.algorithm.length > 0
@@ -1873,13 +1879,19 @@
         photos: [],
       }
 
-      this.form.location = Array.isArray(row.location) && row.location.length >= 2
-        ? [
-          Number(row.location[0]),
-          Number(row.location[1]),
+      let curLocation = []
+
+      if (Array.isArray(row.location) && row.location.length >= 2) {
+        let [lng, lat] = this.disposeLocation(false, row)
+
+        curLocation = [
+          lng,
+          lat,
           row.location[2] || row.address || ''
         ]
-        : []
+      }
+
+      this.form.location = curLocation
       this.form.address = this.form.location[2] || ''
       // 设置地图中心点
       if (Array.isArray(this.form.location) && this.form.location.length >= 2) {
@@ -1907,16 +1919,6 @@
       })
 
       this.dialogVisible = true
-    },
-
-    // 添加数据监听以确保算法数据的响应性
-    watch: {
-      'form.algorithm': {
-        handler (newVal) {
-          console.log('算法值变化:', newVal)
-        },
-        deep: true
-      }
     },
 
     // 添加删除方法
@@ -2195,6 +2197,31 @@
       if (lastDot === -1) return url
       return url.slice(0, lastDot) + '_show' + url.slice(lastDot)
     },
+
+    /**
+     * 坐标转换方法处理
+     * @param goWgs84 是否由国测转换到84,默认false----由84转换到国测
+     */
+    disposeLocation (goWgs84 = false, data) {
+      let lng, lat
+      if (goWgs84) {
+        lng = data.location?.[0] ? String(data.location[0]) : undefined
+        lat = data.location?.[1] ? String(data.location[1]) : undefined
+
+        if (lng && lat) {
+          [lng, lat] = gcj02ToWgs84(Number(lng), Number(lat))
+        }
+      } else {
+        lng = Number(data.location[0])
+        lat = Number(data.location[1])
+
+        if (lng && lat) {
+          [lng, lat] = wgs84ToGcj02(Number(lng), Number(lat))
+        }
+      }
+
+      return [String(lng), String(lat)]
+    }
   },
 }
 </script>

--
Gitblit v1.9.3