From 80ca024e9ae633df0dc9f4e8f533f33b526afb3d Mon Sep 17 00:00:00 2001
From: p-honggang.li <p-honggang.li@pcitc.com>
Date: 星期一, 08 九月 2025 16:24:38 +0800
Subject: [PATCH] 修复文件上传获取不到用户信息的BUG

---
 src/views/tradeManage/confirm/index.vue |  133 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 131 insertions(+), 2 deletions(-)

diff --git a/src/views/tradeManage/confirm/index.vue b/src/views/tradeManage/confirm/index.vue
index 9c4a6d7..d893c4b 100644
--- a/src/views/tradeManage/confirm/index.vue
+++ b/src/views/tradeManage/confirm/index.vue
@@ -237,8 +237,12 @@
 import { Document, User, Goods, List } from '@element-plus/icons-vue'
 import { ElMessage, ElMessageBox } from 'element-plus'
 import orderApi from '@/api/orderApi'
+import pointsApi from '@/api/pointsApi' // 鏂板绉垎API瀵煎叆
 import { useUserInfo } from '@/stores/modules/userInfo'
 import createAxios from '@/utils/axios'
+import productApi from '@/api/productApi'
+import sysUserService from '@/api/sysUser'
+import {queryUserDetail} from "@/api/userInfo";
 
 const route = useRoute()
 const router = useRouter()
@@ -291,13 +295,63 @@
 onMounted(async () => {
   const orderId = String(route.params.id || '')
   if (!orderId) return
-  
+
+  // 鑾峰彇鐢ㄦ埛淇℃伅
+  if (!userStore.getUserId) {
+    try {
+      const res: any = await queryUserDetail()
+      if (res?.code === 200 && res.data) {
+        userStore.updateUserDetail(res.data)
+      } else {
+        ElMessage.error(res?.msg || '鏃犳硶鑾峰彇鐢ㄦ埛淇℃伅锛岃鍏堢櫥褰�')
+        return
+      }
+    } catch (e) {
+      console.error('鑾峰彇鐢ㄦ埛璇︽儏澶辫触:', e)
+      ElMessage.error('鑾峰彇鐢ㄦ埛淇℃伅澶辫触锛岃绋嶅悗閲嶈瘯')
+      return
+    }
+  }
+
   try {
     const res = (await orderApi.getOrderDetail(orderId)) as any
     const data = res?.data || {}
 
     const statusName: string = data.orderStatus || ''
     const uiStatus = statusServerToUi[statusName] || 'INFO'
+
+    // 鏍规嵁浜у搧id鑾峰彇浜у搧淇℃伅锛屾洿鏂板ご閮ㄥ睍绀�
+    try {
+      if (data.productId) {
+        const detailRes: any = await productApi.getProductById({ id: data.productId })
+        if (detailRes?.code === 200 && detailRes.data) {
+          // 鐢ㄤ骇鍝佽鎯呰ˉ鍏ㄥご淇℃伅
+          data.productName = detailRes.data.name || data.productName
+          data.providerName = detailRes.data.submissionUnit || data.providerName
+          data.industry = detailRes.data.industrialChainName || data.industry
+          data.productDesc = detailRes.data.describe || data.productDesc
+          data.projectUnit = detailRes.data.importantAreaName || data.productDesc
+          data.productType = detailRes.data.typeName || data.productDesc
+        }
+      }
+    } catch (e) {
+      // 蹇界暐浜у搧璇︽儏澶辫触锛屼笉闃诲璁㈠崟璇︽儏
+    }
+
+    // 鑾峰彇鐢ㄦ埛淇℃伅
+    try {
+      const userRes: any = await sysUserService.getUserdetail({ userId: data.userId })
+      if (userRes?.code === 200 && userRes.data) {
+        // 鐢ㄤ骇鍝佽鎯呰ˉ鍏ㄥご淇℃伅
+        data.unitName = userRes.data.unitName || data.unitName
+        data.userName = userRes.data.name || data.userName
+        data.userDept = userRes.data.departmentName || data.userDept
+        data.userPhone = userRes.data.phone || data.userPhone
+        data.userAccount = userRes.data.username || data.userAccount
+      }
+    }catch (e){
+
+    }
 
     // 鏄犲皠璁㈠崟璇︽儏澶撮儴淇℃伅
     const head = {
@@ -317,6 +371,7 @@
       projectUnit: data.projectUnit || '-',
       productType: data.productType || '-',
       productDesc: data.productDesc || '-',
+      providerId: data.providerId || ''
     }
 
     // 鏄庣粏椤规槧灏�
@@ -395,11 +450,47 @@
   try {
     const orderId = String(route.params.id || '')
     const userId = userStore.getUserId ? Number(userStore.getUserId) : undefined
+    console.log(userId)
     
     if (!orderId || !userId) {
       ElMessage.error('璁㈠崟ID鎴栫敤鎴稩D涓嶈兘涓虹┖')
       return
     }
+
+    // 妫�鏌ヨ鍗曟槸鍚︽秹鍙婄Н鍒嗘墸鍑�
+    const hasPointsDeduction = detail.items && detail.items.some((item: any) => Number(item.pricePoint || 0) > 0)
+    
+    // if (hasPointsDeduction) {
+    //   // 璁$畻闇�瑕佹墸鍑忕殑绉垎鎬婚
+    //   const totalPointsToDeduct = detail.items.reduce((sum: number, item: any) => {
+    //     return sum + (Number(item.pricePoint || 0) * Number(item.quantity || 0))
+    //   }, 0)
+    //
+    //   if (totalPointsToDeduct > 0) {
+    //     // 鑾峰彇褰撳墠鐢ㄦ埛绉垎浣欓
+    //     try {
+    //       const userPointsRes = await pointsApi.getUserPoints(userId)
+    //       if (userPointsRes.code !== 200 || !userPointsRes.data) {
+    //         ElMessage.error('鑾峰彇绉垎浣欓澶辫触')
+    //         return
+    //       }
+    //
+    //       const currentPoints = userPointsRes.data.balance || 0
+    //
+    //       if (currentPoints < totalPointsToDeduct) {
+    //         ElMessage.error(`绉垎浣欓涓嶈冻锛佸綋鍓嶇Н鍒嗭細${currentPoints.toLocaleString()}锛岄渶瑕佺Н鍒嗭細${totalPointsToDeduct.toLocaleString()}`)
+    //         return
+    //       }
+    //
+    //       // 绉垎浣欓鍏呰冻锛岀户缁墽琛�
+    //       console.log(`绉垎浣欓妫�鏌ラ�氳繃锛氬綋鍓�${currentPoints}锛岄渶瑕�${totalPointsToDeduct}`)
+    //     } catch (error) {
+    //       console.error('鑾峰彇绉垎浣欓澶辫触:', error)
+    //       ElMessage.error('鑾峰彇绉垎浣欓澶辫触锛岃閲嶈瘯')
+    //       return
+    //     }
+    //   }
+    // }
 
     // 纭鎿嶄綔
     await ElMessageBox.confirm('纭畾瑕佺‘璁や氦鏄擄紵', '纭鎿嶄綔', {
@@ -408,8 +499,46 @@
       type: 'warning'
     })
 
-    // 鏇存柊璁㈠崟鐘舵�佽繘鍏ヤ笅涓�涓姸鎬�
+    // 濡傛灉娑夊強绉垎鎵e噺锛屽厛杩涜绉垎鎵e噺鍜屾祦姘磋褰�
+    if (hasPointsDeduction) {
+      const totalPointsToDeduct = detail.items.reduce((sum: number, item: any) => {
+        return sum + (Number(item.pricePoint || 0) * Number(item.quantity || 0))
+      }, 0)
+      
+      if (totalPointsToDeduct > 0) {
+        try {
+          // 鑾峰彇鐢ㄦ埛鍗曚綅ID
+          const unitId = userStore.getUserInfo?.unitId || userStore.getUserInfo?.unitId || ''
+          
+          // 鑾峰彇褰撳墠璁㈣喘鐨勪骇鍝佸悕绉颁綔涓哄娉紙浣跨敤浜у搧鍚嶇О锛屼笉鏄浠跺悕绉帮級
+          const productNames = detail.productName || '璁㈠崟浜ゆ槗鎵e噺绉垎'
+          
+          // 鍏堟墽琛岀Н鍒嗘墸鍑�
+          const deductRes: any = await pointsApi.deductPointsByFlow(
+            userId.toString(), 
+            unitId,
+            totalPointsToDeduct, 
+            orderId, 
+            productNames || '璁㈠崟浜ゆ槗鎵e噺绉垎',  // 浣跨敤浜у搧鍚嶇О浣滀负澶囨敞
+            '绉垎浜ゆ槗',  // 鏁版嵁绫诲埆
+             detail.providerId
+          )
+          if (!deductRes || deductRes.code !== 200) {
+            ElMessage.error(deductRes?.msg || deductRes?.message || '绉垎鎵e噺澶辫触锛屼氦鏄撶‘璁ょ粓姝�')
+            return
+          }
+          console.log(`绉垎鎵e噺鎴愬姛锛�${totalPointsToDeduct}`)
+        } catch (error) {
+          console.error('绉垎鎵e噺澶辫触:', error)
+          ElMessage.error('绉垎鎵e噺澶辫触锛屼氦鏄撶‘璁ょ粓姝�')
+          return
+        }
+      }
+    }
+
+    // 绉垎鎵e噺鎴愬姛鍚庯紝鏇存柊璁㈠崟鐘舵�佽繘鍏ヤ笅涓�涓姸鎬�
     await orderApi.updateOrderStatusToNext(orderId)
+
     ElMessage.success('浜ゆ槗纭鎴愬姛')
     router.back()    
   } catch (error) {

--
Gitblit v1.8.0