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