修复物料伙伴选项和空值处理

This commit is contained in:
文睿 张 2026-10-13 15:58:30 +08:00
parent 1474b4d066
commit 09bfd0e105
2 changed files with 32 additions and 8 deletions

View File

@ -62,8 +62,16 @@
{{ getUnitDisplay(row) }}
</template>
</el-table-column>
<el-table-column prop="supplier_name" label="供应商" min-width="140" />
<el-table-column prop="manufacturer_name" label="制造商" min-width="140" />
<el-table-column label="供应商" min-width="140">
<template #default="{ row }">
{{ row.supplier_name || '-' }}
</template>
</el-table-column>
<el-table-column label="制造商" min-width="140">
<template #default="{ row }">
{{ row.manufacturer_name || '-' }}
</template>
</el-table-column>
<el-table-column
label="操作"
width="240"
@ -372,16 +380,32 @@ onMounted(async () => {
// 检索框却只给有效物料的话,作废的那些就搜不出来(而这一页正是恢复它们的入口)。
// 业务单据页(入库/出库/申请)仍用只有有效物料的 materialOptions。
materialsStore.fetchHistoricalMaterialOptions()
const [categoryResponse, unitResponse, supplierResponse, manufacturerResponse] = await Promise.all([
const [categoryResult, unitResult, supplierResult, manufacturerResult] = await Promise.allSettled([
materialCategoriesApi.list(),
unitsApi.list(),
loadPartners('supplier'),
loadPartners('manufacturer')
])
categories.value = categoryResponse.data || []
units.value = (unitResponse.data || []).filter(item => item.status === 'active')
suppliers.value = supplierResponse
manufacturers.value = manufacturerResponse
if (categoryResult.status === 'fulfilled') {
categories.value = categoryResult.value.data || []
} else {
console.error('加载物料分类失败:', categoryResult.reason)
}
if (unitResult.status === 'fulfilled') {
units.value = (unitResult.value.data || []).filter(item => item.status === 'active')
} else {
console.error('加载计量单位失败:', unitResult.reason)
}
if (supplierResult.status === 'fulfilled') {
suppliers.value = supplierResult.value
} else {
console.error('加载供应商失败:', supplierResult.reason)
}
if (manufacturerResult.status === 'fulfilled') {
manufacturers.value = manufacturerResult.value
} else {
console.error('加载制造商失败:', manufacturerResult.reason)
}
})
async function loadPartners(role) {

View File

@ -34,7 +34,7 @@ export function toMaterialPayload(source) {
const payload = {}
for (const key of materialKeys) {
payload[key] = key === 'supplier_id' || key === 'manufacturer_id'
? source[key] ?? 0
? (source[key] == null || source[key] === '' ? 0 : source[key])
: key.endsWith('_id') ? source[key] ?? null : source[key] || ''
}
if (!payload.unit) payload.unit = '个'