This commit is contained in:
zlwu committed 2026-08-28 17:38:37 +08:00
1 parent 3d98104455
commit 0d52442902
76 files changed
+21994 -12642

No files matched your search

@@ -2456,16 +2456,98 @@
}
}
function buildBatchStockOutPrefillFromSelection(): {
lines: BatchStockOutLine[]
options: ProductionMaterialBatchOption[]
skippedZero: number
} {
const sel = selectedRows.value || []
const lines: BatchStockOutLine[] = []
const options: ProductionMaterialBatchOption[] = []
const seen = new Set<string>()
let skippedZero = 0
for (const row of sel) {
const rem = Number(row.remainingQty) || 0
if (rem <= 0) {
skippedZero += 1
continue
}
const batchId = row.batchId || row.id
if (!batchId || seen.has(batchId)) continue
seen.add(batchId)
const unit = (row.unit || '').trim()
const mfr = (row.manufacturer || '').trim()
const cat = (row.catalogNo || '').trim()
lines.push({
batchId,
stockInNo: row.stockInNo || '',
materialName: row.materialName || '',
batchNo: row.batchNo || '',
remainingQty: rem,
qty: Math.min(1, rem),
usageUnit: unit,
remark: ''
})
options.push({
id: batchId,
batchId,
stockInNo: row.stockInNo || '',
stockInDate: row.stockInDate,
expireDate: row.expireDate,
productionDate: row.productionDate,
materialId: row.materialId,
materialCode: row.materialCode || '',
materialName: row.materialName || '',
materialType: row.materialType || '',
specModel: row.specModel || '',
unit,
batchNo: row.batchNo || '',
catalogNo: row.catalogNo || '',
manufacturer: row.manufacturer || '',
storageLocation: row.storageLocation,
unitPrice: row.unitPrice,
amount: row.amount,
remainingQty: rem,
label: `${row.stockInNo || ''} / ${row.materialName || ''} / 厂家:${mfr || '—'} / 批号:${
row.batchNo || '—'
} / 货号:${cat || '—'} / 剩:${rem}${unit}`
})
if (unit) ensureUnitOption(unit)
}
return { lines, options, skippedZero }
}
function mergeBatchOptions(extra: ProductionMaterialBatchOption[]) {
if (!extra.length) return
const ids = new Set(batchOptions.value.map((o) => o.id))
const missing = extra.filter((o) => o.id && !ids.has(o.id))
if (missing.length) {
batchOptions.value = [...missing, ...batchOptions.value]
}
}
function handleBatchStockOut() {
batchStockOutLines.value = [newBatchStockOutLine()]
const { lines, options, skippedZero } = buildBatchStockOutPrefillFromSelection()
const selectedCount = (selectedRows.value || []).length
if (selectedCount > 0 && lines.length === 0) {
ElMessage.warning('所选物料剩余数量均为 0,无法出库,请手动选择有库存的批次')
} else if (skippedZero > 0) {
ElMessage.warning(`已跳过 ${skippedZero} 项剩余数量为 0 的物料`)
}
batchStockOutLines.value = lines.length ? lines : [newBatchStockOutLine()]
batchOptions.value = options
batchStockOutForm.stockOutTime = formatNowDatetime()
batchStockOutForm.receiver = ''
batchStockOutForm.purpose = ''
batchStockOutForm.remark = ''
batchStockOutVisible.value = true
void searchReceiverUsers('')
void searchBatchOptions('')
void searchUnitOptions('')
void searchBatchOptions('').then(() => mergeBatchOptions(options))
void searchUnitOptions('').then(() => {
for (const line of batchStockOutLines.value) {
if (line.usageUnit) ensureUnitOption(line.usageUnit)
}
})
batchStockOutFormRef.value?.clearValidate?.()
}