diff --git a/packages/app-client/src/components/purchase/cost/CostCard.tsx b/packages/app-client/src/components/purchase/cost/CostCard.tsx index 698ae25..552eade 100644 --- a/packages/app-client/src/components/purchase/cost/CostCard.tsx +++ b/packages/app-client/src/components/purchase/cost/CostCard.tsx @@ -94,23 +94,25 @@ export default function CostCard(props: CostCardComponentProps) { hint="点击金额可直接编辑" /> - - {orderCostItemList.map((orderCostItem) => { - return ( - - - {orderCostItem.name} - - - {orderCostItem.count} {orderCostItem.unit} - - - ); - })} - + {orderCostItemList.length > 0 && ( + + {orderCostItemList.map((orderCostItem) => { + return ( + + + {orderCostItem.name} + + + {orderCostItem.count} {orderCostItem.unit} + + + ); + })} + + )} diff --git a/packages/app-client/src/components/purchase/module/EmptyBoxModule.tsx b/packages/app-client/src/components/purchase/module/EmptyBoxModule.tsx index adf4769..23fd631 100644 --- a/packages/app-client/src/components/purchase/module/EmptyBoxModule.tsx +++ b/packages/app-client/src/components/purchase/module/EmptyBoxModule.tsx @@ -128,7 +128,7 @@ export default function EmptyBoxModule(props: IEmptyBoxModuleProps) { initBoxBrandList().then(); setEmptyBoxList(orderPackageList); - if (orderPackageList.length > 0) { + if (orderPackageList?.length > 0) { // 根据当前供应商确定需要检查的纸箱类型 let requiredTypes: string[] = ["EMPTY"]; diff --git a/packages/app-client/src/components/purchase/module/MelonFarmer.tsx b/packages/app-client/src/components/purchase/module/MelonFarmer.tsx index 1b3c4ad..7e1d7fb 100644 --- a/packages/app-client/src/components/purchase/module/MelonFarmer.tsx +++ b/packages/app-client/src/components/purchase/module/MelonFarmer.tsx @@ -549,6 +549,7 @@ export default forwardRef( }); }; + console.log("supplierVO", supplierVO); if (!supplierVO) { return; } @@ -588,9 +589,9 @@ export default forwardRef( ( // 初始化函数 const init = async (costIds: string[]) => { - let newOrderCostList: BusinessAPI.OrderCost[] = []; + // 创建一个映射,用于快速查找orderCostItemList中的项目 + const orderCostMap = new Map(); - // 获取成本列表 - const { - data: { data: costList, success }, - } = await business.cost.listCost({ - costListQry: { - status: true, - }, + orderCostList?.forEach((item) => { + if (item.costId && costIds.includes(item.costId)) { + orderCostMap.set(item.costId, item); + } }); - if (success) { - const newCostList = costList?.filter((item) => { - return costIds.includes(item.costId); - }); + // 构建初始列表,基于costTemplate中的项目 + const newOrderCostList: IOrderCost[] = []; - // 遍历costList,将costList中的项目添加到orderCostList中 - newCostList?.forEach((item) => { - const orderCost = orderCostList.find( - (cost) => cost.costId === item.costId, - ); + // 遍历costList,将costList中的项目添加到orderCostList中 + parsedCostTemplate.productionTypeList?.forEach((item) => { + const existingItem = orderCostMap.get(item.costItemId); - const selected = parsedCostTemplate.productionTypeList?.some( - (cost) => { - return cost.costId === item.costId; - }, - ); - - if (orderCost) { - newOrderCostList.push({ - ...orderCost, - selected: selected, - }); - } else { - newOrderCostList.push({ - orderCostId: generateShortId(), - costItemIds: item.costItemIds, - costId: item.costId, - name: item.name, - type: item.type, - selected: selected, - count: 1, - price: item.price || 0, - unit: item.unit || "元", - }); - } - }); - } + if (existingItem) { + newOrderCostList.push({ + ...existingItem, + selected: !!existingItem, + }); + } else { + newOrderCostList.push({ + orderCostId: generateShortId(), + costItemIds: item.costItemIds, + costId: item.costId, + name: item.name, + type: item.type, + selected: false, + count: 1, + price: item.price || 0, + unit: item.unit || "元", + }); + } + }); onChange?.({ ...value, diff --git a/packages/app-client/src/components/purchase/module/OrderCostItem.tsx b/packages/app-client/src/components/purchase/module/OrderCostItem.tsx index 512e7a5..099c784 100644 --- a/packages/app-client/src/components/purchase/module/OrderCostItem.tsx +++ b/packages/app-client/src/components/purchase/module/OrderCostItem.tsx @@ -47,8 +47,6 @@ export default forwardRef( } }); - console.log("orderCostItemList,", orderCostItemList); - // 构建初始列表,基于costTemplate中的项目 const newOrderCostItemList: IOrderCostItem[] = []; @@ -62,7 +60,7 @@ export default forwardRef( name: item.name, price: item.price, unit: item.unit, - selected: true, + selected: !!existingItem, count: existingItem?.count || 1, payerType: existingItem?.payerType, type: item.type, @@ -82,7 +80,7 @@ export default forwardRef( name: item.name, price: item.price, unit: item.unit, - selected: true, + selected: !!existingItem, count: existingItem?.count || 1, payerType: existingItem?.payerType, type: item.type, @@ -90,7 +88,6 @@ export default forwardRef( }); }); - console.log("newOrderCostItemList,", newOrderCostItemList); onChange?.({ ...value, orderCostItemList: newOrderCostItemList, diff --git a/packages/app-client/src/components/purchase/module/OrderPackage.tsx b/packages/app-client/src/components/purchase/module/OrderPackage.tsx index 325d82f..e05db36 100644 --- a/packages/app-client/src/components/purchase/module/OrderPackage.tsx +++ b/packages/app-client/src/components/purchase/module/OrderPackage.tsx @@ -41,7 +41,7 @@ export default forwardRef( useEffect(() => { // 初始化数据 - if (orderPackageList.length > 0) { + if (orderPackageList?.length > 0) { // 根据当前供应商确定需要检查的纸箱类型 let requiredTypes: string[] = []; diff --git a/packages/app-client/src/components/purchase/module/PurchasePreview.tsx b/packages/app-client/src/components/purchase/module/PurchasePreview.tsx index ac22c98..7315f66 100644 --- a/packages/app-client/src/components/purchase/module/PurchasePreview.tsx +++ b/packages/app-client/src/components/purchase/module/PurchasePreview.tsx @@ -245,7 +245,7 @@ export default function PurchasePreview(props: IPurchasePreviewProps) { - {purchaseOrder.orderPackageList.length > 0 && ( + {purchaseOrder.orderPackageList?.length > 0 && ( <> 空箱使用明细 diff --git a/packages/app-client/src/components/purchase/module/Weigh.tsx b/packages/app-client/src/components/purchase/module/Weigh.tsx index 8e5c081..87a8e9b 100644 --- a/packages/app-client/src/components/purchase/module/Weigh.tsx +++ b/packages/app-client/src/components/purchase/module/Weigh.tsx @@ -535,9 +535,9 @@ export default forwardRef(function Weigh(props, ref) { (function Weigh(props, ref) { [] = [ { @@ -422,19 +422,24 @@ export default hocAuth(function Page(props: CommonComponent) { purchaseOrder?.orderSupplierList[ purchaseOrder?.orderSupplierList.length - 1 ]?.isLast && ( - + + + 快捷操作 + + + )}