<script lang="ts" setup>
|
import type { MesProWorkOrderBomApi } from '#/api/mes/pro/workorder/bom';
|
|
import { computed, ref, watch } from 'vue';
|
|
import { Alert, Table } from 'ant-design-vue';
|
|
import { getWorkOrderBomItemPreview } from '#/api/mes/pro/workorder/bom';
|
|
const props = defineProps<{
|
productId?: number;
|
quantity?: number;
|
}>();
|
|
const loading = ref(false);
|
const list = ref<MesProWorkOrderBomApi.BomItemPreview[]>([]);
|
|
/** 库存不充足的辅料(可用库存 + 在途采购 < 需求数量) */
|
const insufficientList = computed(() =>
|
list.value.filter((item) => item.stockSufficient === false),
|
);
|
const enoughCount = computed(
|
() => list.value.filter((item) => item.stockSufficient !== false).length,
|
);
|
/** 库存不足的辅料文案:物料名称(还差数量 单位) */
|
const insufficientText = computed(() =>
|
insufficientList.value
|
.map((item) => {
|
const gap =
|
(item.quantity ?? 0) -
|
(item.stockQuantity ?? 0) -
|
(item.purchaseOrderQuantity ?? 0);
|
return `${item.itemName ?? item.itemCode}(还差 ${gap} ${item.unitMeasureName ?? ''})`;
|
})
|
.join('、'),
|
);
|
|
const columns = [
|
{ title: '物料编码', dataIndex: 'itemCode', width: 140 },
|
{ title: '物料名称', dataIndex: 'itemName', width: 180 },
|
{ title: '规格型号', dataIndex: 'itemSpecification', width: 140 },
|
{ title: '需求数量', dataIndex: 'quantity', width: 110 },
|
{ title: '单位', dataIndex: 'unitMeasureName', width: 80 },
|
{ title: '可用库存', dataIndex: 'stockQuantity', width: 110 },
|
{ title: '在途采购', dataIndex: 'purchaseOrderQuantity', width: 110 },
|
{ title: '库存判断', dataIndex: 'stockSufficient', width: 110 },
|
];
|
|
async function load() {
|
list.value = [];
|
if (!props.productId || !props.quantity || props.quantity <= 0) {
|
return;
|
}
|
loading.value = true;
|
try {
|
list.value = await getWorkOrderBomItemPreview(
|
props.productId,
|
props.quantity,
|
);
|
} finally {
|
loading.value = false;
|
}
|
}
|
|
watch(() => [props.productId, props.quantity], load, { immediate: true });
|
|
defineExpose({
|
getInsufficientItems: () => insufficientList.value,
|
getList: () => list.value,
|
refresh: load,
|
});
|
</script>
|
|
<template>
|
<div>
|
<div v-if="!productId || !quantity" class="py-8 text-center text-gray-400">
|
请先选择产品并填写订单数量,系统将按工艺路线自动计算辅料用量
|
</div>
|
<template v-else>
|
<Alert
|
v-if="!loading && list.length > 0 && insufficientList.length > 0"
|
class="mb-3"
|
type="warning"
|
show-icon
|
>
|
<template #message>
|
有 {{ insufficientList.length }} 项辅料库存不足(可用库存 + 在途采购 <
|
需求数量),需先行采购;另有 {{ enoughCount }} 项库存充足。
|
</template>
|
<template #description>
|
<div class="leading-6">{{ insufficientText }}</div>
|
</template>
|
</Alert>
|
<Alert
|
v-else-if="!loading && list.length > 0"
|
class="mb-3"
|
type="success"
|
show-icon
|
message="全部辅料库存充足,可直接提交生成工单"
|
/>
|
<Alert
|
v-else-if="!loading"
|
class="mb-3"
|
type="info"
|
show-icon
|
message="未计算到辅料需求,请确认产品已配置工艺路线及投料 BOM"
|
/>
|
<Table
|
:columns="columns"
|
:data-source="list"
|
:loading="loading"
|
:pagination="false"
|
:scroll="{ y: 320 }"
|
bordered
|
row-key="itemId"
|
size="small"
|
>
|
<template #bodyCell="{ column, record }">
|
<template v-if="column.dataIndex === 'stockSufficient'">
|
<span v-if="record.stockSufficient === false" class="text-red-500">
|
库存不足
|
</span>
|
<span v-else class="text-green-600">充足</span>
|
</template>
|
</template>
|
</Table>
|
</template>
|
</div>
|
</template>
|