+ >({});
+ // 开始编辑
+ const startEdit = (key: string, currentValue: number) => {
+ const inputValue = currentValue === 0 ? "" : currentValue.toString();
+ setEditingStates((prev) => ({
+ ...prev,
+ [key]: { isEditing: true, inputValue },
+ }));
- useEffect(() => {
- if (!readOnly) {
- setColumns([...defaultColumns]);
+ // 聚焦输入框
+ setTimeout(() => {
+ if (inputRefs.current[key]) {
+ inputRefs.current[key].focus();
+ }
+ }, 0);
+ };
+
+ // 处理输入变化
+ const handleInputChange = (key: string, e: any) => {
+ const val = e.detail?.value || e.target?.value || "";
+ // 只允许数字和小数点
+ if (/^\d*\.?\d*$/.test(val) || val === "") {
+ setEditingStates((prev) => ({
+ ...prev,
+ [key]: { ...prev[key], inputValue: val },
+ }));
}
- }, [readOnly]);
+ };
+
+ // 保存编辑
+ const saveEdit = (key: string) => {
+ const state = editingStates[key];
+ if (!state) return;
+
+ let newValue = 0;
+ if (state.inputValue !== "" && !Number.isNaN(Number(state.inputValue))) {
+ newValue = Number(state.inputValue);
+ }
+
+ // 更新 orderVO 中的数据
+ const updatedOrderVO = { ...orderVO };
+ updatedOrderVO.orderSupplierList?.forEach((supplier) => {
+ supplier.orderPackageList?.forEach((pkg) => {
+ const pkgKey = `${pkg.boxBrandId}-${pkg.boxProductId}-${pkg.boxSpecId}`;
+ if (pkgKey === key) {
+ pkg.boxSalePrice = newValue;
+ }
+ });
+ });
+
+ // 触发 onChange 回调
+ onChange?.(updatedOrderVO);
+
+ // 退出编辑状态
+ setEditingStates((prev) => {
+ const newState = { ...prev };
+ delete newState[key];
+ return newState;
+ });
+ };
+
+ // 取消编辑
+ const cancelEdit = (key: string) => {
+ setEditingStates((prev) => {
+ const newState = { ...prev };
+ delete newState[key];
+ return newState;
+ });
+ };
+
+ const columns = useMemo(() => {
+ return [
+ {
+ title: "纸箱型号",
+ key: "boxProductName",
+ fixed: "left",
+ },
+ {
+ title: "个数",
+ key: "boxProductCount",
+ },
+ ...(orderVO.type === "PRODUCTION_PURCHASE"
+ ? [
+ {
+ title: "销售单价(元/斤)",
+ key: "boxSalePrice",
+ render: (
+ value: BusinessAPI.OrderPackage & {
+ orderPackageId?: string;
+ isTotalRow?: boolean;
+ },
+ ) => {
+ // 合计行不显示编辑按钮
+ if (value.isTotalRow) {
+ return value.boxSalePrice as number;
+ }
+
+ // 生成分组键
+ const key = `${value.boxBrandId}-${value.boxProductId}-${value.boxSpecId}`;
+ const editingState = editingStates[key];
+ const isEditing = editingState?.isEditing || false;
+
+ if (isEditing) {
+ return (
+
+ {
+ inputRefs.current[key] = el;
+ }}
+ type="digit"
+ value={editingState.inputValue}
+ onInput={(e) => handleInputChange(key, e)}
+ onBlur={() => saveEdit(key)}
+ className="flex-1 border-b border-blue-500 px-1"
+ style={{ minWidth: "80px" }}
+ onClick={(e) => e.stopPropagation()}
+ />
+ {
+ e.stopPropagation();
+ cancelEdit(key);
+ }}
+ >
+
+
+
+ );
+ }
+
+ return (
+ {
+ if (!readOnly) {
+ e.stopPropagation();
+ startEdit(key, value.boxSalePrice as number);
+ }
+ }}
+ >
+
+ {value.boxSalePrice as number}
+
+ {!readOnly && (
+
+
+
+ )}
+
+ );
+ },
+ },
+ {
+ title: "销售金额(元)",
+ key: "boxSalePayment",
+ },
+ ]
+ : []),
+ {
+ title: "箱重(斤)",
+ key: "boxProductWeight",
+ render: (
+ value: BusinessAPI.OrderPackage & {
+ orderPackageId?: string;
+ isTotalRow?: boolean;
+ },
+ ) => value.boxProductWeight,
+ },
+ {
+ title: "品牌",
+ key: "boxBrandName",
+ },
+ ];
+ }, [readOnly, editingStates]);
// 将所有包装信息合并并按品牌、型号、规格分组
const groupedPackageData = orderVO.orderSupplierList?.reduce(
@@ -99,7 +204,7 @@ export default function PackageInfoSection(props: {
?.filter((pkg) => pkg.boxType === "USED")
?.forEach((pkg) => {
// 生成分组键
- const key = `${pkg.boxBrandName}-${pkg.boxProductName}-${pkg.boxSpecId}`;
+ const key = `${pkg.boxBrandId}-${pkg.boxProductId}-${pkg.boxSpecId}`;
// 转换规格字段
const boxSpecId = pkg.boxSpecId;
@@ -208,11 +313,11 @@ export default function PackageInfoSection(props: {
if (rowData.isTotalRow) {
return (
- {formatCurrency(rowData.boxSalePrice as number)}
+ {rowData.boxSalePrice as number}
);
}
- return column.render(rowData, rowData);
+ return column?.render?.(rowData);
},
};
} else if (column.key === "boxSalePayment") {
@@ -223,7 +328,7 @@ export default function PackageInfoSection(props: {
if (rowData.isTotalRow) {
return (
- {formatCurrency(rowData.boxSalePayment)}
+ {rowData.boxSalePayment}
);
}
@@ -241,11 +346,11 @@ export default function PackageInfoSection(props: {
if (rowData.isTotalRow) {
return (
- {formatCurrency(rowData.boxProductWeight)}
+ {rowData.boxProductWeight}
);
}
- return column.render(rowData, rowData);
+ return column?.render?.(rowData);
},
};
}
@@ -257,7 +362,7 @@ export default function PackageInfoSection(props: {
return (
diff --git a/packages/app-client/src/constant/app.ts b/packages/app-client/src/constant/app.ts
index 69ed8d2..699db1f 100644
--- a/packages/app-client/src/constant/app.ts
+++ b/packages/app-client/src/constant/app.ts
@@ -1,2 +1,2 @@
// App 相关常量
-export const APP_VERSION = "v0.0.59";
+export const APP_VERSION = "v0.0.61";
diff --git a/packages/app-client/src/utils/classes/templates/PdfTemplate.ts b/packages/app-client/src/utils/classes/templates/PdfTemplate.ts
index c79a9ad..13ea4d8 100644
--- a/packages/app-client/src/utils/classes/templates/PdfTemplate.ts
+++ b/packages/app-client/src/utils/classes/templates/PdfTemplate.ts
@@ -35,11 +35,9 @@ export class PdfTemplate {
if (config.showDealerName || config.showWatermelonGrade) {
htmlString += `
- ${
- config.showWatermelonGrade
- ? `${config.dealerName || ""}-${config.watermelonGrade || ""}`
- : config.dealerName || ""
- }
+ ${config.showDealerName ? config.dealerName : ""}
+ ${config.showDealerName && config.showWatermelonGrade ? "- " : ""}
+ ${config.showWatermelonGrade ? config.watermelonGrade : ""}
`;
} else {
@@ -49,7 +47,8 @@ export class PdfTemplate {
if (config.showDestination || config.showVehicleNumber) {
htmlString += `
- ${config.destination || ""} ${config.vehicleNumber || ""}
+ ${config.showDestination ? config.destination : ""}
+ ${config.showVehicleNumber ? config.vehicleNumber : ""}
`;
} else {
diff --git a/packages/app-client/src/utils/converters/orderConverter.ts b/packages/app-client/src/utils/converters/orderConverter.ts
index 878240b..d4beda8 100644
--- a/packages/app-client/src/utils/converters/orderConverter.ts
+++ b/packages/app-client/src/utils/converters/orderConverter.ts
@@ -33,7 +33,7 @@ export const convertOrderToOrderShip = (
// 转换供应商列表为发货单项列表,根据 purchasePrice 分组
const suppliersByPrice = groupBy(
orderVO.orderSupplierList || [],
- (supplier) => String(supplier.purchasePrice),
+ (supplier) => String(supplier.salePrice || "0"),
);
const orderShipId = oldOrderShip?.orderShipId || generateShortId();
@@ -57,10 +57,15 @@ export const convertOrderToOrderShip = (
);
const totalAmount = DecimalUtils.toDecimalPlaces(
- suppliers.reduce(
- (sum, supplier) => DecimalUtils.add(sum, supplier.invoiceAmount || 0),
- 0,
- ),
+ suppliers.reduce((sum, supplier) => {
+ const amount = DecimalUtils.multiply(
+ orderVO.pricingMethod === "BY_GROSS_WEIGHT"
+ ? supplier.grossWeight
+ : supplier.netWeight,
+ supplier.salePrice || 0,
+ );
+ return DecimalUtils.add(sum, amount || 0);
+ }, 0),
);
const totalBoxCount = DecimalUtils.toDecimalPlaces(
@@ -89,7 +94,7 @@ export const convertOrderToOrderShip = (
grossWeight: totalGrossWeight,
boxWeight: totalGrossWeight - totalNetWeight,
netWeight: totalNetWeight,
- unitPrice: parseFloat(price),
+ unitPrice: price ? parseFloat(price) : 0,
totalAmount: totalAmount,
watermelonGrade: oldOrderShipItem?.watermelonGrade || "", // 需要手动填写
};
diff --git a/packages/app-client/src/utils/converters/orderShipConverter.ts b/packages/app-client/src/utils/converters/orderShipConverter.ts
index edc87c8..79b8620 100644
--- a/packages/app-client/src/utils/converters/orderShipConverter.ts
+++ b/packages/app-client/src/utils/converters/orderShipConverter.ts
@@ -42,7 +42,10 @@ export const convertOrderShipVOToExamplesFormat = (
}
});
- const packagesBySpec = groupBy(allPackages, (pkg) => pkg.boxSpecId);
+ const packagesBySpec = groupBy(
+ allPackages,
+ (pkg) => pkg.boxSpecName + pkg.boxProductName,
+ );
const orderShipPackageList = Object.entries(packagesBySpec).map(
([specId, packages]) => {