- 优化 State 组件渲染逻辑,增加状态判断避免无效渲染 - 在 Step1Form 组件中添加调试日志便于排查问题 - 调整 DeliveryFormSection 中 convertShipOrderVOToExamplesFormat 方法参数 - 重命名常量文件 shipOrder.ts 为 orderShip.ts 并扩展状态枚举值 - 新增草稿(DRAFT)和待发货(WAIT_SHIPMENT)两种订单状态配置 - 更新发货单页面导入模块路径并调整数据处理逻辑 - 修改发货单文档页面初始化方法参数并增强类型安全 - 重构发货单列表页删除冗余弹窗及生成单据逻辑 - 调整发票上传页面筛选条件限制仅允许特定状态下操作 - 优化审批结果页面发货单据下载流程简化交互步骤 - 补充业务接口定义完善 OrderShip 和 OrderSupplier 类型声明 - 更新工具函数中 purchaseOrderConverter 和 shipOrderConverter 实现细节 - 调整应用路由配置同步页面文件名变更影响范围
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
// 将PurchaseOrderVO转换为ShipOrderVO
|
||
import { generateShortId } from "@/utils";
|
||
import { DecimalUtils } from "@/utils/classes/calculators/core/DecimalUtils";
|
||
|
||
/**
|
||
* 将PurchaseOrderVO转换为ShipOrderVO
|
||
* @param purchaseOrderVO 采购订单对象
|
||
* @returns 发货单对象
|
||
*/
|
||
export const convertPurchaseOrderToOrderShip = (
|
||
purchaseOrderVO: BusinessAPI.PurchaseOrderVO
|
||
): BusinessAPI.OrderShip => {
|
||
// 添加一个辅助函数用于分组
|
||
const groupBy = <T>(
|
||
array: T[],
|
||
keyFn: (item: T) => string,
|
||
): Record<string, T[]> => {
|
||
return array.reduce(
|
||
(groups, item) => {
|
||
const key = keyFn(item);
|
||
if (!groups[key]) {
|
||
groups[key] = [];
|
||
}
|
||
groups[key].push(item);
|
||
return groups;
|
||
},
|
||
{} as Record<string, T[]>,
|
||
);
|
||
};
|
||
|
||
// 转换供应商列表为发货单项列表,根据 purchasePrice 分组
|
||
const suppliersByPrice = groupBy(
|
||
purchaseOrderVO.orderSupplierList || [],
|
||
(supplier) => String(supplier.purchasePrice)
|
||
);
|
||
|
||
const orderShipItemList: BusinessAPI.OrderShipItem[] = Object.entries(suppliersByPrice).map(
|
||
([price, suppliers]) => {
|
||
// 计算该价格下的总毛重、总净重等
|
||
const totalGrossWeight = DecimalUtils.toDecimalPlaces(suppliers.reduce(
|
||
(sum, supplier) => DecimalUtils.add(sum, supplier.grossWeight || 0), 0
|
||
))
|
||
|
||
const totalNetWeight = DecimalUtils.toDecimalPlaces(suppliers.reduce(
|
||
(sum, supplier) => DecimalUtils.add(sum, supplier.netWeight || 0), 0
|
||
));
|
||
|
||
const totalAmount = DecimalUtils.toDecimalPlaces(suppliers.reduce(
|
||
(sum, supplier) => DecimalUtils.add(sum, supplier.invoiceAmount || 0), 0
|
||
))
|
||
|
||
return {
|
||
itemId: generateShortId(),
|
||
orderShipId: "", // 将在创建发货单时填充
|
||
orderId: purchaseOrderVO.orderId,
|
||
grossWeight: totalGrossWeight,
|
||
boxWeight: totalGrossWeight - totalNetWeight,
|
||
netWeight: totalNetWeight,
|
||
unitPrice: parseFloat(price),
|
||
totalAmount: totalAmount,
|
||
watermelonGrade: "", // 需要手动填写
|
||
};
|
||
}
|
||
);
|
||
|
||
// 构建ShipOrder对象,不转换费用信息
|
||
return {
|
||
orderShipId: generateShortId(),
|
||
orderId: purchaseOrderVO.orderId,
|
||
orderSn: "",
|
||
watermelonGrade: "",
|
||
dealerId: purchaseOrderVO.orderVehicle?.dealerId!,
|
||
dealerName: purchaseOrderVO.orderVehicle?.dealerName!,
|
||
companyId: purchaseOrderVO.orderCompany?.companyId,
|
||
companyName: purchaseOrderVO.orderCompany?.fullName,
|
||
shippingAddress: purchaseOrderVO.orderVehicle?.origin,
|
||
receivingAddress: purchaseOrderVO.orderVehicle?.destination,
|
||
shippingDate: purchaseOrderVO.orderVehicle?.deliveryTime,
|
||
estimatedArrivalDate: "",
|
||
document: "",
|
||
state: 'WAIT_PAYMENT',
|
||
orderShipItemList
|
||
};
|
||
};
|