| | |
| | | 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' |
| | | |
| | | const route = useRoute() |
| | | const router = useRouter() |
| | |
| | | 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 = { |
| | | orderNo: data.orderId, |
| | |
| | | projectUnit: data.projectUnit || '-', |
| | | productType: data.productType || '-', |
| | | productDesc: data.productDesc || '-', |
| | | providerId: data.providerId || '' |
| | | } |
| | | |
| | | // 明细项映射 |
| | |
| | | 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('确定要确认交易?', '确认操作', { |
| | | confirmButtonText: '确定', |
| | |
| | | type: 'warning' |
| | | }) |
| | | |
| | | // 更新订单状态进入下一个状态 |
| | | // 如果涉及积分扣减,先进行积分扣减和流水记录 |
| | | 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 || '订单交易扣减积分' |
| | | |
| | | // 先执行积分扣减 |
| | | const deductRes: any = await pointsApi.deductPointsByFlow( |
| | | userId.toString(), |
| | | unitId, |
| | | totalPointsToDeduct, |
| | | orderId, |
| | | productNames || '订单交易扣减积分', // 使用产品名称作为备注 |
| | | '积分交易', // 数据类别 |
| | | detail.providerId |
| | | ) |
| | | if (!deductRes || deductRes.code !== 200) { |
| | | ElMessage.error(deductRes?.msg || deductRes?.message || '积分扣减失败,交易确认终止') |
| | | return |
| | | } |
| | | console.log(`积分扣减成功:${totalPointsToDeduct}`) |
| | | } catch (error) { |
| | | console.error('积分扣减失败:', error) |
| | | ElMessage.error('积分扣减失败,交易确认终止') |
| | | return |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 积分扣减成功后,更新订单状态进入下一个状态 |
| | | await orderApi.updateOrderStatusToNext(orderId) |
| | | |
| | | ElMessage.success('交易确认成功') |
| | | router.back() |
| | | } catch (error) { |