fix(WEB): 수주 개소 그룹핑 개선 및 제품명 표시 수정
- floor+code 동일 시 인덱스 기반 균등 분배 로직 추가 - 제품명을 root_nodes[0].options.product_name에서 가져오도록 변경
This commit is contained in:
@@ -234,13 +234,55 @@ export function OrderRegistration({
|
||||
}, [])
|
||||
);
|
||||
|
||||
// 아이템을 개소별(floor+code)로 그룹핑
|
||||
// 아이템을 개소별로 그룹핑
|
||||
const itemGroups = useMemo(() => {
|
||||
const calcItems = form.selectedQuotation?.calculationInputs?.items;
|
||||
if (!calcItems || calcItems.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// floor+code 고유 키 수 확인 (모두 같은 값인지 판별)
|
||||
const uniqueLocKeys = new Set(
|
||||
calcItems.map(ci => `${ci.floor || '-'}|${ci.code || '-'}`)
|
||||
);
|
||||
|
||||
// 개소가 여러 개인데 floor+code가 모두 동일 → 인덱스 기반 균등 분배
|
||||
const useIndexGrouping = calcItems.length > 1 && uniqueLocKeys.size === 1;
|
||||
|
||||
if (useIndexGrouping) {
|
||||
const itemsPerLocation = Math.ceil(form.items.length / calcItems.length);
|
||||
const result: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
productCode: string;
|
||||
locationCount: number;
|
||||
quantity: number;
|
||||
amount: number;
|
||||
items: OrderItem[];
|
||||
}> = [];
|
||||
|
||||
calcItems.forEach((ci, idx) => {
|
||||
const start = idx * itemsPerLocation;
|
||||
const end = Math.min(start + itemsPerLocation, form.items.length);
|
||||
const groupItems = form.items.slice(start, end);
|
||||
const amount = groupItems.reduce((sum, item) => sum + (item.amount ?? 0), 0);
|
||||
const floor = ci.floor || '-';
|
||||
const code = ci.code || '-';
|
||||
|
||||
result.push({
|
||||
key: `loc_${idx}`,
|
||||
label: `${idx + 1}. ${floor} / ${code}`,
|
||||
productCode: ci.productName || ci.productCode || '',
|
||||
locationCount: 1,
|
||||
quantity: ci.quantity ?? 1,
|
||||
amount,
|
||||
items: groupItems,
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// floor+code → calculationInput 매핑 (개소 메타정보)
|
||||
const locationMetaMap = new Map<string, {
|
||||
productCode: string;
|
||||
|
||||
@@ -538,8 +538,8 @@ function transformApiToFrontend(apiData: ApiOrder): Order {
|
||||
note: apiData.note ?? undefined,
|
||||
items: apiData.items?.map(transformItemApiToFrontend) || [],
|
||||
nodes: apiData.root_nodes?.map(transformNodeApiToFrontend) || [],
|
||||
// 목록 페이지용 추가 필드
|
||||
productName: apiData.items?.[0]?.item_name ?? undefined,
|
||||
// 목록 페이지용 추가 필드: 첫 root_node의 options.product_name (FG 제품명)
|
||||
productName: (apiData.root_nodes?.[0]?.options?.product_name as string) || undefined,
|
||||
receiverAddress: apiData.options?.shipping_address ?? undefined,
|
||||
receiverPlace: apiData.options?.receiver_contact ?? undefined,
|
||||
frameCount: apiData.root_nodes_sum_quantity ?? apiData.quantity ?? undefined,
|
||||
|
||||
Reference in New Issue
Block a user