This commit is contained in:
zlwu committed 2026-06-17 20:31:34 +08:00
1 parent 6bfabac50d
commit 58a47b96a5
38 files changed
+10159 -9660

No files matched your search

@@ -1639,6 +1639,133 @@
return items.length ? items.join(',') : '—'
})
/** 未完成结算的输注计划(已完成/已取消不再扣减) */
const isPendingSettlementSchedule = (schedule: Record<string, any>): boolean => {
const st = normalizeInfusionStatusCode(schedule.infusionStatus)
return st !== 'ywc' && st !== 'yqx'
}
const resolveYfkUnitPrice = (cp: Record<string, any>): number => {
const agreement = Number(cp.agreementPrice)
if (agreement > 0) return agreement
return Number(cp.actualPrice) || 0
}
const calcPendingSettlementAmount = (): number =>
infusionSchedules.value
.filter(isPendingSettlementSchedule)
.reduce(
(sum, s) =>
sum +
(s.cellProducts || []).reduce((lineSum: number, cp: any) => {
const qty = Math.max(1, Number(cp.quantity) || 1)
return lineSum + resolveYfkUnitPrice(cp) * qty
}, 0),
0
)
type PendingProductQtyItem = {
label: string
qty: number
projectCode: string
specText: string
cellTypeName: string
}
const calcPendingSettlementQtyByProduct = (): Map<string, PendingProductQtyItem> => {
const map = new Map<string, PendingProductQtyItem>()
for (const schedule of infusionSchedules.value.filter(isPendingSettlementSchedule)) {
for (const cp of schedule.cellProducts || []) {
const projectCode = (cp.projectCode || '').trim()
const specText = (cp.specText || '').trim()
const cellTypeName = (cp.cellTypeName || '').trim()
const key = projectCode ? `${projectCode}|${specText}` : `${cellTypeName}|${specText}`
if (!key.replace('|', '').trim()) continue
const qty = Math.max(1, Number(cp.quantity) || 1)
const label = formatCellProductDisplayLabel(cp)
const existing = map.get(key)
if (existing) {
existing.qty += qty
} else {
map.set(key, { label, qty, projectCode, specText, cellTypeName })
}
}
}
return map
}
const findOrderProductCurrentQty = (
orderProducts: any[],
item: PendingProductQtyItem
): number | null => {
const spec = item.specText
if (item.projectCode) {
const row = orderProducts.find(
(p) => (p.projectCode || '') === item.projectCode && (p.specText || '') === spec
)
if (row) return Number(row.currentQty) || 0
}
if (item.cellTypeName) {
const row = orderProducts.find(
(p) =>
(p.cellType || p.cellTypeName || '') === item.cellTypeName && (p.specText || '') === spec
)
if (row) return Number(row.currentQty) || 0
}
return null
}
/** 保存前校验渠道服务订单余额/份数,仅提示不阻断保存 */
const warnIfChannelSettlementInsufficient = async () => {
if (isClinical.value || isBasicExperiment.value) return
if (!formData.channelServiceOrderId || !formData.channelId) return
const pendingSchedules = infusionSchedules.value.filter(isPendingSettlementSchedule)
const hasProducts = pendingSchedules.some((s) => (s.cellProducts || []).length > 0)
if (!hasProducts) return
let orderDetail: any
try {
const res: any = await fetchChannelServiceOrderDetail(formData.channelServiceOrderId)
orderDetail = res?.data ?? res
} catch {
return
}
const orderType = orderDetail?.orderType || selectedServiceOrder.value?.orderType || ''
if (orderType === 'yfk') {
const required = calcPendingSettlementAmount()
if (required <= 0) return
const balance = Number(orderDetail.currentBalance) || 0
if (balance < required) {
ElMessage.warning(
`渠道服务订单余额可能不足:当前余额 ¥${formatMoneyDisplay(balance, 2)},待完成输注计划预估需 ¥${formatMoneyDisplay(required, 2)}。申请单仍会保存,完成输注时可能扣减失败。`
)
}
return
}
if (orderType === 'gmcp') {
const orderProducts = Array.isArray(orderDetail.products) ? orderDetail.products : []
const requiredMap = calcPendingSettlementQtyByProduct()
const shortfalls: string[] = []
for (const item of requiredMap.values()) {
const available = findOrderProductCurrentQty(orderProducts, item)
if (available === null) {
shortfalls.push(`「${item.label}」在服务订单中未找到持仓`)
} else if (available < item.qty) {
shortfalls.push(`「${item.label}」当前剩余 ${available} 份,预估需 ${item.qty} 份`)
}
}
if (shortfalls.length) {
ElMessage.warning(
`渠道服务订单产品份数可能不足:${shortfalls.join(';')}。申请单仍会保存,完成输注时可能扣减失败。`
)
}
}
}
const getCellProductProjectKey = (cp: any): string =>
(cp?.projectCode || cp?.priceId || '').trim()
@@ -2742,6 +2869,8 @@
}
}
await warnIfChannelSettlementInsufficient()
submitting.value = true
try {
const attachmentPayload = otherFileList.value.map((a) => ({