refactor(purchase): 优化订单计算逻辑和组件数据处理
- 移除CostSummarySection中formatCurrency调用,保持数值类型 - 根据订单类型动态显示PackageInfoSection销售单价列 - 为ProductionLossSection和TaxProvisionSection添加calculator参数 - 为TaxSubsidySection添加calculator参数支持 - 优化审计页面提交逻辑,添加calculator计算回填 - 简化组件onChange回调处理 - 改进CostCalculator中空值判断逻辑
This commit is contained in:
parent
91a5010130
commit
f8199f7b55
@ -1,5 +1,5 @@
|
||||
import { Table, TableColumnProps } from "@nutui/nutui-react-taro";
|
||||
import { formatCurrency, OrderCalculator } from "@/utils";
|
||||
import { OrderCalculator } from "@/utils";
|
||||
import { useState } from "react";
|
||||
import { DecimalUtils } from "@/utils/classes/calculators/core/DecimalUtils";
|
||||
|
||||
@ -56,14 +56,14 @@ export default function CostSummarySection(props: {
|
||||
{
|
||||
id: 1,
|
||||
costType: "成本合计(不含运费)",
|
||||
unitCost: `${formatCurrency(unitCostWithoutFreight)}`,
|
||||
amount: `${formatCurrency(costWithoutFreight)}`,
|
||||
unitCost: unitCostWithoutFreight,
|
||||
amount: costWithoutFreight,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
costType: "成本合计(含运费)",
|
||||
unitCost: `${formatCurrency(unitCostWithFreight)}`,
|
||||
amount: `${formatCurrency(costWithFreight)}`,
|
||||
unitCost: unitCostWithFreight,
|
||||
amount: costWithFreight,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@ -22,45 +22,53 @@ export default function PackageInfoSection(props: {
|
||||
title: "个数",
|
||||
key: "boxProductCount",
|
||||
},
|
||||
{
|
||||
title: "销售单价(元/斤)",
|
||||
key: "boxSalePrice",
|
||||
render: (
|
||||
value: BusinessAPI.OrderPackage & {
|
||||
orderPackageId?: string;
|
||||
isTotalRow?: boolean;
|
||||
},
|
||||
) => {
|
||||
// 合计行不显示编辑按钮
|
||||
if (value.isTotalRow) {
|
||||
return formatCurrency(value.boxSalePrice as number);
|
||||
}
|
||||
|
||||
return (
|
||||
<View
|
||||
className="flex w-full items-center justify-between"
|
||||
onClick={(e) => {
|
||||
if (!readOnly) {
|
||||
e.stopPropagation();
|
||||
...(orderVO.type === "PRODUCTION_PURCHASE"
|
||||
? [
|
||||
{
|
||||
title: "销售单价(元/斤)",
|
||||
key: "boxSalePrice",
|
||||
render: (
|
||||
value: BusinessAPI.OrderPackage & {
|
||||
orderPackageId?: string;
|
||||
isTotalRow?: boolean;
|
||||
},
|
||||
) => {
|
||||
// 合计行不显示编辑按钮
|
||||
if (value.isTotalRow) {
|
||||
return formatCurrency(value.boxSalePrice as number);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<View className={!readOnly ? "cursor-pointer underline" : ""}>
|
||||
{formatCurrency(value.boxSalePrice as number)}
|
||||
</View>
|
||||
{!readOnly && (
|
||||
<View className="-m-2 ml-2 flex items-center justify-center p-2">
|
||||
<Icon name={"pen-to-square"} size={16} color={"#1a73e8"} />
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "销售金额(元)",
|
||||
key: "boxSalePayment",
|
||||
},
|
||||
|
||||
return (
|
||||
<View
|
||||
className="flex w-full items-center justify-between"
|
||||
onClick={(e) => {
|
||||
if (!readOnly) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<View className={!readOnly ? "cursor-pointer underline" : ""}>
|
||||
{formatCurrency(value.boxSalePrice as number)}
|
||||
</View>
|
||||
{!readOnly && (
|
||||
<View className="-m-2 ml-2 flex items-center justify-center p-2">
|
||||
<Icon
|
||||
name={"pen-to-square"}
|
||||
size={16}
|
||||
color={"#1a73e8"}
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "销售金额(元)",
|
||||
key: "boxSalePayment",
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: "箱重(斤)",
|
||||
key: "boxProductWeight",
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
import { Text, View } from "@tarojs/components";
|
||||
import { PriceEditor } from "@/components";
|
||||
import { OrderCalculator } from "@/utils";
|
||||
|
||||
export default function ProductionLossSection(props: {
|
||||
orderVO: BusinessAPI.OrderVO;
|
||||
onChange?: (orderVO: BusinessAPI.OrderVO) => void;
|
||||
readOnly?: boolean;
|
||||
calculator: OrderCalculator;
|
||||
}) {
|
||||
const { orderVO, onChange, readOnly } = props;
|
||||
const { orderVO, onChange, calculator, readOnly } = props;
|
||||
const orderDealer = orderVO.orderDealer;
|
||||
|
||||
return (
|
||||
@ -19,7 +21,12 @@ export default function ProductionLossSection(props: {
|
||||
|
||||
<View className="flex">
|
||||
<PriceEditor
|
||||
value={orderDealer.lossAmount || 0}
|
||||
value={
|
||||
orderDealer.lossAmount === null ||
|
||||
orderDealer.lossAmount === undefined
|
||||
? calculator.getLossAmount()
|
||||
: orderDealer.lossAmount
|
||||
}
|
||||
onSave={(newValue) => {
|
||||
// 更新父组件的状态
|
||||
onChange?.({
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
import { Text, View } from "@tarojs/components";
|
||||
import { PriceEditor } from "@/components";
|
||||
import { OrderCalculator } from "@/utils";
|
||||
|
||||
export default function TaxProvisionSection(props: {
|
||||
orderVO: BusinessAPI.OrderVO;
|
||||
onChange?: (orderVO: BusinessAPI.OrderVO) => void;
|
||||
readOnly?: boolean;
|
||||
calculator: OrderCalculator;
|
||||
}) {
|
||||
const { orderVO, onChange, readOnly } = props;
|
||||
const { orderVO, onChange, calculator, readOnly } = props;
|
||||
const orderDealer = orderVO.orderDealer;
|
||||
|
||||
console.log("orderDealer.taxProvision", orderDealer.taxProvision);
|
||||
@ -20,7 +22,12 @@ export default function TaxProvisionSection(props: {
|
||||
|
||||
<View className="flex">
|
||||
<PriceEditor
|
||||
value={orderDealer.taxProvision || 0}
|
||||
value={
|
||||
orderDealer.taxProvision === null ||
|
||||
orderDealer.taxProvision === undefined
|
||||
? calculator.getTaxProvision()
|
||||
: orderDealer.taxProvision
|
||||
}
|
||||
onSave={(newValue) => {
|
||||
// 更新父组件的状态
|
||||
onChange?.({
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
import { Text, View } from "@tarojs/components";
|
||||
import { PriceEditor } from "@/components";
|
||||
import { OrderCalculator } from "@/utils";
|
||||
|
||||
export default function TaxSubsidySection(props: {
|
||||
orderVO: BusinessAPI.OrderVO;
|
||||
onChange?: (orderVO: BusinessAPI.OrderVO) => void;
|
||||
readOnly?: boolean;
|
||||
calculator: OrderCalculator;
|
||||
}) {
|
||||
const { orderVO, onChange, readOnly } = props;
|
||||
const { orderVO, onChange, calculator, readOnly } = props;
|
||||
const orderDealer = orderVO.orderDealer;
|
||||
|
||||
console.log("orderDealer.taxSubsidy", orderDealer.taxSubsidy);
|
||||
return (
|
||||
<View className={"flex flex-col gap-2.5"}>
|
||||
{/* 卡片形式展示返点信息 */}
|
||||
@ -19,7 +22,12 @@ export default function TaxSubsidySection(props: {
|
||||
|
||||
<View className="flex">
|
||||
<PriceEditor
|
||||
value={orderDealer.taxSubsidy || 0}
|
||||
value={
|
||||
orderDealer.taxSubsidy === null ||
|
||||
orderDealer.taxSubsidy === undefined
|
||||
? calculator.getTaxSubsidy()
|
||||
: orderDealer.taxSubsidy
|
||||
}
|
||||
onSave={(newValue) => {
|
||||
console.log("newValue taxSubsidy", newValue);
|
||||
// 更新父组件的状态
|
||||
|
||||
@ -345,8 +345,50 @@ export default hocAuth(function Page(props: CommonComponent) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 这里应该调用提交审核API
|
||||
console.log("提交老板审核:", orderVO);
|
||||
if (!orderVO) {
|
||||
Toast.show("toast", {
|
||||
icon: "fail",
|
||||
title: "提示",
|
||||
content: "提交失败",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 公司返点(税费补贴)
|
||||
if (
|
||||
(orderVO.orderDealer.taxSubsidy === null ||
|
||||
orderVO.orderDealer.taxSubsidy === undefined) &&
|
||||
orderVO.orderDealer.enableCompanyRebate
|
||||
) {
|
||||
orderVO.orderDealer.taxSubsidy = calculator.getTaxSubsidy();
|
||||
}
|
||||
|
||||
// 利润分成
|
||||
if (
|
||||
(orderVO.orderDealer.profitSharing === null ||
|
||||
orderVO.orderDealer.profitSharing === undefined) &&
|
||||
orderVO.orderDealer.shareAdjusted
|
||||
) {
|
||||
orderVO.orderDealer.profitSharing = calculator.getPersonalProfit();
|
||||
}
|
||||
|
||||
// 损失金额
|
||||
if (
|
||||
(orderVO.orderDealer.lossAmount === null ||
|
||||
orderVO.orderDealer.lossAmount === undefined) &&
|
||||
orderVO.orderDealer.enableLoss
|
||||
) {
|
||||
orderVO.orderDealer.lossAmount = calculator.getLossAmount();
|
||||
}
|
||||
|
||||
// 计提税金
|
||||
if (
|
||||
(orderVO.orderDealer.taxProvision === null ||
|
||||
orderVO.orderDealer.taxProvision === undefined) &&
|
||||
orderVO.orderDealer.enableAccrualTax
|
||||
) {
|
||||
orderVO.orderDealer.taxProvision = calculator.getTaxProvision();
|
||||
}
|
||||
|
||||
const {
|
||||
data: { data: auditVO, success, errMessage },
|
||||
@ -806,51 +848,7 @@ export default hocAuth(function Page(props: CommonComponent) {
|
||||
)
|
||||
}
|
||||
orderVO={orderVO}
|
||||
onChange={(orderVO) => {
|
||||
const calculator = new OrderCalculator(orderVO);
|
||||
console.log("calculator", calculator, section);
|
||||
// 公司返点(税费补贴)
|
||||
if (
|
||||
(orderVO.orderDealer.taxSubsidy === null ||
|
||||
orderVO.orderDealer.taxSubsidy === undefined) &&
|
||||
orderVO.orderDealer.enableCompanyRebate
|
||||
) {
|
||||
orderVO.orderDealer.taxSubsidy =
|
||||
calculator.getTaxSubsidy();
|
||||
}
|
||||
|
||||
// 利润分成
|
||||
if (
|
||||
(orderVO.orderDealer.profitSharing === null ||
|
||||
orderVO.orderDealer.profitSharing === undefined) &&
|
||||
orderVO.orderDealer.shareAdjusted
|
||||
) {
|
||||
orderVO.orderDealer.profitSharing =
|
||||
calculator.getPersonalProfit();
|
||||
}
|
||||
|
||||
// 损失金额
|
||||
if (
|
||||
(orderVO.orderDealer.lossAmount === null ||
|
||||
orderVO.orderDealer.lossAmount === undefined) &&
|
||||
orderVO.orderDealer.enableLoss
|
||||
) {
|
||||
orderVO.orderDealer.lossAmount =
|
||||
calculator.getLossAmount();
|
||||
}
|
||||
|
||||
// 计提税金
|
||||
if (
|
||||
(orderVO.orderDealer.taxProvision === null ||
|
||||
orderVO.orderDealer.taxProvision === undefined) &&
|
||||
orderVO.orderDealer.enableAccrualTax
|
||||
) {
|
||||
orderVO.orderDealer.taxProvision =
|
||||
calculator.getTaxProvision();
|
||||
}
|
||||
|
||||
setOrderVO(orderVO);
|
||||
}}
|
||||
onChange={setOrderVO}
|
||||
// @ts-ignore
|
||||
costList={costList}
|
||||
calculator={calculator}
|
||||
|
||||
@ -55,7 +55,7 @@ export class CostCalculator {
|
||||
|
||||
// 优先使用手动设置的税费补贴
|
||||
const manualTaxSubsidy = this.order.orderDealer?.taxSubsidy;
|
||||
if (manualTaxSubsidy) {
|
||||
if (manualTaxSubsidy !== undefined && manualTaxSubsidy !== null) {
|
||||
return manualTaxSubsidy;
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ export class CostCalculator {
|
||||
|
||||
// 优先使用手动设置的计提税金
|
||||
const manualTaxProvision = this.order.orderDealer?.taxProvision;
|
||||
if (manualTaxProvision) {
|
||||
if (manualTaxProvision !== undefined && manualTaxProvision !== null) {
|
||||
return manualTaxProvision;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user