feat(录单): 仓内加工行内显示/选择原材料
This commit is contained in:
@@ -57,6 +57,9 @@ export interface OrderParsedItemRowProps {
|
||||
onPriceCommit?: (skuCode: string, price: number) => void;
|
||||
onProcessingMethodChange?: (id: string, method: string) => void;
|
||||
onProcessingOwnerChange?: (id: string, owner: 'supplier' | 'warehouse') => void;
|
||||
/** 行内仓内加工原材料显示/修改 */
|
||||
rawMaterialLabel?: string | null;
|
||||
onSelectRawMaterial?: (id: string) => void;
|
||||
onProcessUnitPriceChange?: (id: string, processUnitPrice: number) => void;
|
||||
onRemarkChange?: (id: string, remark: string) => void;
|
||||
/** 规格人工修正(解析第 7 字段带来;本轮只展示,不落库) */
|
||||
@@ -101,6 +104,8 @@ const OrderParsedItemRowInner: React.FC<OrderParsedItemRowProps> = ({
|
||||
onPriceCommit,
|
||||
onProcessingMethodChange,
|
||||
onProcessingOwnerChange,
|
||||
rawMaterialLabel,
|
||||
onSelectRawMaterial,
|
||||
onProcessUnitPriceChange,
|
||||
onRemarkChange,
|
||||
onSpecChange,
|
||||
@@ -379,6 +384,27 @@ const OrderParsedItemRowInner: React.FC<OrderParsedItemRowProps> = ({
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{(item.processingOwner ||
|
||||
defaultProcessingOwnerForMethod(item.processingMethod)) === 'warehouse' &&
|
||||
onSelectRawMaterial && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onSelectRawMaterial(item.id)}
|
||||
disabled={!String(item.skuCode || '').trim()}
|
||||
title={String(item.skuCode || '').trim()
|
||||
? t('orders.processingRawMaterialHint')
|
||||
: t('orders.selectProcessingRawMaterial')}
|
||||
className={`px-1.5 py-0.5 text-[11px] rounded border max-w-[14rem] truncate disabled:opacity-50 ${
|
||||
rawMaterialLabel
|
||||
? 'app-status-success border-emerald-600'
|
||||
: 'border-amber-500 text-amber-700 bg-amber-50 dark:bg-amber-950/30'
|
||||
}`}
|
||||
>
|
||||
{rawMaterialLabel
|
||||
? `${t('orders.processingRawMaterial')}:${rawMaterialLabel}`
|
||||
: t('orders.selectProcessingRawMaterial')}
|
||||
</button>
|
||||
)}
|
||||
{(item.processingOwner ||
|
||||
defaultProcessingOwnerForMethod(item.processingMethod)) === 'warehouse' &&
|
||||
onProcessUnitPriceChange && (
|
||||
|
||||
@@ -734,4 +734,7 @@ export const orders: MessageDict = {
|
||||
'processingBomSetup.errMaterial': 'Please select a raw material',
|
||||
'processingBomSetup.errLoss': 'Loss rate must be between 0 and 95',
|
||||
'processingBomSetup.errSelf': 'Raw material cannot be the product itself',
|
||||
'processingRawMaterial': 'Raw material',
|
||||
'selectProcessingRawMaterial': 'Select raw material',
|
||||
'processingRawMaterialHint': 'Raw material required for in-house processing; click to edit',
|
||||
};
|
||||
|
||||
@@ -735,4 +735,7 @@ export const orders: MessageDict = {
|
||||
'processingBomSetup.errMaterial': 'Pilih bahan baku',
|
||||
'processingBomSetup.errLoss': 'Tingkat susut harus 0-95',
|
||||
'processingBomSetup.errSelf': 'Bahan baku tidak boleh produk itu sendiri',
|
||||
'processingRawMaterial': 'Bahan baku',
|
||||
'selectProcessingRawMaterial': 'Pilih bahan baku',
|
||||
'processingRawMaterialHint': 'Bahan baku untuk proses di gudang; klik untuk mengubah',
|
||||
};
|
||||
|
||||
@@ -728,4 +728,7 @@ export const orders: MessageDict = {
|
||||
'processingBomSetup.errMaterial': '请选择原材料商品',
|
||||
'processingBomSetup.errLoss': '损耗率须在 0-95 之间',
|
||||
'processingBomSetup.errSelf': '原材料不能是成品自身',
|
||||
'processingRawMaterial': '原材料',
|
||||
'selectProcessingRawMaterial': '选择原材料',
|
||||
'processingRawMaterialHint': '该商品仓内加工所需原材料,可点击修改',
|
||||
};
|
||||
|
||||
@@ -101,7 +101,9 @@ import {
|
||||
import { ProcessingBomSetupModal } from '../../components/order/ProcessingBomSetupModal';
|
||||
import {
|
||||
findMissingProcessingBomTargets,
|
||||
loadProductNameMap,
|
||||
loadProductProcessingBom,
|
||||
type ProcessingBomEntry,
|
||||
type ProcessingBomSetupTarget,
|
||||
} from '../../utils/processingBom';
|
||||
import { compressOrderRecognitionImage, isGeneralImageFile } from '../../utils/imageFileLimits';
|
||||
@@ -401,6 +403,10 @@ export const CustomerOrder: React.FC = () => {
|
||||
const submitInFlightRef = useRef(false);
|
||||
const [bomSetupOpen, setBomSetupOpen] = useState(false);
|
||||
const [bomSetupTargets, setBomSetupTargets] = useState<ProcessingBomSetupTarget[]>([]);
|
||||
const [bomSetupIntent, setBomSetupIntent] = useState<'submit' | 'row'>('submit');
|
||||
const [bomBySku, setBomBySku] = useState<Map<string, ProcessingBomEntry[]>>(new Map());
|
||||
const [bomMaterialNames, setBomMaterialNames] = useState<Map<string, string>>(new Map());
|
||||
const [bomReloadToken, setBomReloadToken] = useState(0);
|
||||
/**
|
||||
* 解析重入锁:解析结果是 append 写入(setParsedItems(prev => [...prev, ...])),
|
||||
* 重复解析会产生重复明细行。按钮 disabled 之外再补一层函数内同步守卫,
|
||||
@@ -1647,6 +1653,99 @@ export const CustomerOrder: React.FC = () => {
|
||||
);
|
||||
}, []);
|
||||
|
||||
/** 录单行内:仓内加工原材料的 BOM 查询键 */
|
||||
const bomQueryKey = useMemo(
|
||||
() =>
|
||||
parsedItems
|
||||
.filter((item) => item.skuCode && requiresWarehouseProcessing(item.processingMethod, item.processingOwner))
|
||||
.map((item) => `${String(item.skuCode).trim()}::${String(item.processingMethod || '').trim()}`)
|
||||
.sort()
|
||||
.join('|'),
|
||||
[parsedItems]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!bomQueryKey) {
|
||||
setBomBySku(new Map());
|
||||
setBomMaterialNames(new Map());
|
||||
return;
|
||||
}
|
||||
const rows = Array.from(
|
||||
new Map(
|
||||
parsedItems
|
||||
.filter(
|
||||
(item) =>
|
||||
item.skuCode &&
|
||||
requiresWarehouseProcessing(item.processingMethod, item.processingOwner)
|
||||
)
|
||||
.map((item) => [
|
||||
`${String(item.skuCode).trim()}::${String(item.processingMethod || '').trim()}`,
|
||||
item,
|
||||
])
|
||||
).values()
|
||||
);
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
try {
|
||||
const bomMap = await loadProductProcessingBom(
|
||||
rows.map((item) => String(item.skuCode).trim()),
|
||||
effectiveBranchCode
|
||||
);
|
||||
const materialCodes = [...bomMap.values()]
|
||||
.flatMap((entries) => entries.map((entry) => entry.material_sku))
|
||||
.filter(Boolean);
|
||||
const names = await loadProductNameMap(materialCodes, effectiveBranchCode);
|
||||
if (cancelled) return;
|
||||
setBomBySku(bomMap);
|
||||
setBomMaterialNames(names);
|
||||
} catch (error) {
|
||||
console.warn('加载加工原材料配置失败', error);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [bomQueryKey, effectiveBranchCode, bomReloadToken]);
|
||||
|
||||
const rawMaterialLabelForItem = useCallback(
|
||||
(item: ParsedItem): string | null => {
|
||||
const skuCode = String(item.skuCode || '').trim();
|
||||
const method = String(item.processingMethod || '').trim();
|
||||
if (!skuCode || !method) return null;
|
||||
const entries = bomBySku.get(skuCode) || [];
|
||||
const entry =
|
||||
entries.find((row) => row.method.toLowerCase() === method.toLowerCase()) ||
|
||||
entries.find((row) => !row.method) ||
|
||||
entries[0];
|
||||
if (!entry) return null;
|
||||
return bomMaterialNames.get(entry.material_sku) || entry.material_sku;
|
||||
},
|
||||
[bomBySku, bomMaterialNames]
|
||||
);
|
||||
|
||||
const openProcessingBomForItem = useCallback(
|
||||
(id: string) => {
|
||||
const item = parsedItemsRef.current.find((row) => row.id === id);
|
||||
if (!item) return;
|
||||
const skuCode = String(item.skuCode || '').trim();
|
||||
if (!skuCode) {
|
||||
notify.warning(t('orders.processingBomSetup.errMaterial'));
|
||||
return;
|
||||
}
|
||||
setBomSetupTargets([
|
||||
{
|
||||
skuCode,
|
||||
skuName: item.skuName || resolveOrderEntryNameForSubmit(item),
|
||||
processingMethod: String(item.processingMethod || '').trim(),
|
||||
},
|
||||
]);
|
||||
setBomSetupIntent('row');
|
||||
setBomSetupOpen(true);
|
||||
},
|
||||
[t]
|
||||
);
|
||||
|
||||
const updateItemProcessUnitPrice = useCallback((id: string, processUnitPrice: number) => {
|
||||
setParsedItems((prev) =>
|
||||
prev.map((item) =>
|
||||
@@ -1966,6 +2065,7 @@ export const CustomerOrder: React.FC = () => {
|
||||
const missing = findMissingProcessingBomTargets(warehouseRows, bomMap);
|
||||
if (missing.length) {
|
||||
setBomSetupTargets(missing);
|
||||
setBomSetupIntent('submit');
|
||||
setBomSetupOpen(true);
|
||||
submitInFlightRef.current = false;
|
||||
setIsSubmitting(false);
|
||||
@@ -2693,6 +2793,8 @@ export const CustomerOrder: React.FC = () => {
|
||||
// 独立进货:没有销售价,不展示价格输入框(金额仍显示,恒为 0)
|
||||
hidePriceInput={isIndependentInboundCustomer(selectedCustomer?.customer_code)}
|
||||
onProcessingMethodChange={updateItemProcessingMethod}
|
||||
rawMaterialLabel={rawMaterialLabelForItem(item)}
|
||||
onSelectRawMaterial={openProcessingBomForItem}
|
||||
onProcessingOwnerChange={updateItemProcessingOwner}
|
||||
onProcessUnitPriceChange={updateItemProcessUnitPrice}
|
||||
onCategoryChange={updateItemCategory}
|
||||
@@ -2814,7 +2916,10 @@ export const CustomerOrder: React.FC = () => {
|
||||
onSaved={() => {
|
||||
setBomSetupOpen(false);
|
||||
setBomSetupTargets([]);
|
||||
void confirmSubmitOrder();
|
||||
setBomReloadToken((value) => value + 1);
|
||||
if (bomSetupIntent === 'submit') {
|
||||
void confirmSubmitOrder();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user