From b46065a201c09ce69f111806f2bda4a5f476bc4e Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期六, 18 十月 2025 17:20:22 +0800
Subject: [PATCH] fix:用户同步,机构同步

---
 app/pages/mine/index.vue |   55 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/app/pages/mine/index.vue b/app/pages/mine/index.vue
index e936762..6ee6073 100644
--- a/app/pages/mine/index.vue
+++ b/app/pages/mine/index.vue
@@ -106,13 +106,15 @@
 <script>
   import storage from '@/utils/storage'
   import { getUserProfile } from "@/api/system/user"
+  import { getUserBoundVehicle, unbindVehicleFromUser } from '@/api/vehicle'
   
   export default {
     data() {
       return {
         name: this.$store.state.user.name,
         phonenumber: '',
-        boundVehicle: '', // 妯℃嫙缁戝畾鐨勮溅杈嗕俊鎭�
+        boundVehicle: '', // 缁戝畾鐨勮溅杈嗕俊鎭�
+        boundVehicleId: null, // 缁戝畾鐨勮溅杈咺D
         version: getApp().globalData.config.appInfo.version
       }
     },
@@ -130,18 +132,35 @@
     methods: {
       // 鑾峰彇鐢ㄦ埛淇℃伅
       getUserInfo() {
+        const userId = this.$store.state.user.userId
+        
+        // 鑾峰彇鐢ㄦ埛鍩烘湰淇℃伅
         getUserProfile().then(response => {
           const user = response.data
           this.name = user.userName
           this.phonenumber = user.phonenumber
-          // 妯℃嫙缁戝畾杞﹁締淇℃伅锛屽疄闄呴」鐩腑搴斾粠鐢ㄦ埛淇℃伅鎴栬溅杈嗘帴鍙h幏鍙�
-          this.boundVehicle = '绮12345'
         }).catch(() => {
           // 鑾峰彇鐢ㄦ埛淇℃伅澶辫触鏃朵娇鐢ㄩ粯璁ゅ��
           this.name = this.$store.state.user.name || '鏈櫥褰�'
           this.phonenumber = '鏈粦瀹�'
-          this.boundVehicle = '鏈粦瀹�'
         })
+        
+        // 鑾峰彇鐢ㄦ埛缁戝畾鐨勮溅杈嗕俊鎭�
+        if (userId) {
+          getUserBoundVehicle(userId).then(response => {
+            if (response.code === 200 && response.data) {
+              const vehicle = response.data
+              this.boundVehicle = vehicle.vehicleNumber || '鏈煡杞︾墝'
+              this.boundVehicleId = vehicle.vehicleId
+            } else {
+              this.boundVehicle = '鏈粦瀹�'
+              this.boundVehicleId = null
+            }
+          }).catch(() => {
+            this.boundVehicle = '鏈粦瀹�'
+            this.boundVehicleId = null
+          })
+        }
       },
       
       // 璺宠浆鍒扮粦瀹氳溅杈嗛〉闈�
@@ -151,10 +170,30 @@
       
       // 鍙栨秷缁戝畾杞﹁締
       unbindVehicle() {
-        this.$modal.confirm('鏄惁鍙栨秷缁戝畾杞﹁締锛�').then(() => {
-          // 杩欓噷鍙互璋冪敤API鍙栨秷缁戝畾杞﹁締
-          this.boundVehicle = '鏈粦瀹�'
-          this.$modal.showToast('鍙栨秷缁戝畾鎴愬姛')
+        const userId = this.$store.state.user.userId
+        const vehicleId = this.boundVehicleId
+        
+        if (!userId || !vehicleId) {
+          this.$modal.showToast('鏃犳硶鑾峰彇缁戝畾淇℃伅')
+          return
+        }
+        
+        this.$modal.confirm(`纭鍙栨秷缁戝畾杞﹁締 ${this.boundVehicle} 鍚楋紵`).then(() => {
+          // 璋冪敤API鍙栨秷缁戝畾杞﹁締
+          unbindVehicleFromUser(userId, vehicleId).then(response => {
+            if (response.code === 200) {
+              this.boundVehicle = '鏈粦瀹�'
+              this.boundVehicleId = null
+              this.$modal.showToast('鍙栨秷缁戝畾鎴愬姛')
+              // 鏇存柊鐢ㄦ埛淇℃伅
+              this.$store.dispatch('GetInfo')
+            } else {
+              this.$modal.showToast(response.msg || '鍙栨秷缁戝畾澶辫触')
+            }
+          }).catch(error => {
+            console.error('鍙栨秷缁戝畾澶辫触:', error)
+            this.$modal.showToast('鍙栨秷缁戝畾澶辫触锛岃閲嶈瘯')
+          })
         }).catch(() => {
           // 鐢ㄦ埛鍙栨秷鎿嶄綔
         })

--
Gitblit v1.9.1