refactor(purchase): 优化价格计算组件状态管理

- 移除 MarketPriceSection 中的本地状态管理,直接使用 orderVO.pricingMethod
- 将 Radio.Group 的 onChange 逻辑更新为调用 props.onChange 回调
- 更新所有引用 pricingMethod 的地方为直接使用 orderVO.pricingMethod
- 删除 TaxProvisionSection 和 TaxSubsidySection 中的调试日志
- 简化组件状态更新逻辑,提高代码可维护性
This commit is contained in:
shenyifei 2025-12-26 14:54:28 +08:00
parent f8199f7b55
commit d6e3afd100
3 changed files with 12 additions and 22 deletions

View File

@ -1,4 +1,3 @@
import { useEffect, useState } from "react";
import { Text, View } from "@tarojs/components"; import { Text, View } from "@tarojs/components";
import { Radio } from "@nutui/nutui-react-taro"; import { Radio } from "@nutui/nutui-react-taro";
import { OrderCalculator } from "@/utils"; import { OrderCalculator } from "@/utils";
@ -13,15 +12,6 @@ export default function MarketPriceSection(props: {
}) { }) {
const { orderVO, onChange, readOnly, calculator } = props; const { orderVO, onChange, readOnly, calculator } = props;
const [pricingMethod, setPricingMethod] =
useState<BusinessAPI.OrderVO["pricingMethod"]>();
useEffect(() => {
if (orderVO.pricingMethod) {
setPricingMethod(orderVO.pricingMethod);
}
}, [orderVO.pricingMethod]);
// 销售金额 // 销售金额
const saleAmount = calculator.getSalesAmount(); const saleAmount = calculator.getSalesAmount();
@ -42,9 +32,9 @@ export default function MarketPriceSection(props: {
<View className="text-neutral-darkest text-sm font-medium"> <View className="text-neutral-darkest text-sm font-medium">
{readOnly ? ( {readOnly ? (
<View> <View>
{pricingMethod === "BY_GROSS_WEIGHT" {orderVO.pricingMethod === "BY_GROSS_WEIGHT"
? "按毛重报价" ? "按毛重报价"
: pricingMethod === "BY_NET_WEIGHT" : orderVO.pricingMethod === "BY_NET_WEIGHT"
? "按净重报价" ? "按净重报价"
: "未选择"} : "未选择"}
</View> </View>
@ -52,11 +42,13 @@ export default function MarketPriceSection(props: {
<Radio.Group <Radio.Group
direction={"horizontal"} direction={"horizontal"}
//@ts-ignore //@ts-ignore
value={pricingMethod} value={orderVO.pricingMethod}
onChange={(value) => onChange={(value) =>
setPricingMethod( onChange?.({
value as BusinessAPI.OrderVO["pricingMethod"], ...orderVO,
) pricingMethod:
value as BusinessAPI.OrderVO["pricingMethod"],
})
} }
> >
<Radio value="BY_GROSS_WEIGHT"></Radio> <Radio value="BY_GROSS_WEIGHT"></Radio>
@ -189,7 +181,7 @@ export default function MarketPriceSection(props: {
<View className="flex items-center justify-between"> <View className="flex items-center justify-between">
<Text className="text-sm text-gray-500"></Text> <Text className="text-sm text-gray-500"></Text>
<Text className="text-sm font-medium"> <Text className="text-sm font-medium">
{pricingMethod {orderVO.pricingMethod
? `${calculator.calculateSupplierAmount(supplier)}` ? `${calculator.calculateSupplierAmount(supplier)}`
: "-"} : "-"}
</Text> </Text>
@ -206,7 +198,7 @@ export default function MarketPriceSection(props: {
</View> </View>
<View className="text-neutral-darkest text-sm font-medium"> <View className="text-neutral-darkest text-sm font-medium">
{pricingMethod ? `${saleAmount}` : "-"} {orderVO.pricingMethod ? `${saleAmount}` : "-"}
</View> </View>
</View> </View>
<View className="flex !h-8 flex-row items-center justify-between"> <View className="flex !h-8 flex-row items-center justify-between">
@ -215,7 +207,7 @@ export default function MarketPriceSection(props: {
</View> </View>
<View className="text-neutral-darkest text-sm font-medium"> <View className="text-neutral-darkest text-sm font-medium">
{pricingMethod ? `${averagePurchasePrice} 元/斤` : "-"} {orderVO.pricingMethod ? `${averagePurchasePrice} 元/斤` : "-"}
</View> </View>
</View> </View>
<View className="flex !h-8 flex-row items-center justify-between bg-yellow-200"> <View className="flex !h-8 flex-row items-center justify-between bg-yellow-200">
@ -228,7 +220,7 @@ export default function MarketPriceSection(props: {
</View> </View>
<View className="text-neutral-darkest text-sm font-medium"> <View className="text-neutral-darkest text-sm font-medium">
{pricingMethod ? `${marketPrice}` : "-"} {orderVO.pricingMethod ? `${marketPrice}` : "-"}
</View> </View>
</View> </View>
</View> </View>

View File

@ -11,7 +11,6 @@ export default function TaxProvisionSection(props: {
const { orderVO, onChange, calculator, readOnly } = props; const { orderVO, onChange, calculator, readOnly } = props;
const orderDealer = orderVO.orderDealer; const orderDealer = orderVO.orderDealer;
console.log("orderDealer.taxProvision", orderDealer.taxProvision);
return ( return (
<View className={"flex flex-col gap-2.5"}> <View className={"flex flex-col gap-2.5"}>
{/* 卡片形式展示计提税金信息 */} {/* 卡片形式展示计提税金信息 */}

View File

@ -11,7 +11,6 @@ export default function TaxSubsidySection(props: {
const { orderVO, onChange, calculator, readOnly } = props; const { orderVO, onChange, calculator, readOnly } = props;
const orderDealer = orderVO.orderDealer; const orderDealer = orderVO.orderDealer;
console.log("orderDealer.taxSubsidy", orderDealer.taxSubsidy);
return ( return (
<View className={"flex flex-col gap-2.5"}> <View className={"flex flex-col gap-2.5"}>
{/* 卡片形式展示返点信息 */} {/* 卡片形式展示返点信息 */}