refactor(purchase): 优化价格计算组件状态管理
- 移除 MarketPriceSection 中的本地状态管理,直接使用 orderVO.pricingMethod - 将 Radio.Group 的 onChange 逻辑更新为调用 props.onChange 回调 - 更新所有引用 pricingMethod 的地方为直接使用 orderVO.pricingMethod - 删除 TaxProvisionSection 和 TaxSubsidySection 中的调试日志 - 简化组件状态更新逻辑,提高代码可维护性
This commit is contained in:
parent
f8199f7b55
commit
d6e3afd100
@ -1,4 +1,3 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Text, View } from "@tarojs/components";
|
||||
import { Radio } from "@nutui/nutui-react-taro";
|
||||
import { OrderCalculator } from "@/utils";
|
||||
@ -13,15 +12,6 @@ export default function MarketPriceSection(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();
|
||||
|
||||
@ -42,9 +32,9 @@ export default function MarketPriceSection(props: {
|
||||
<View className="text-neutral-darkest text-sm font-medium">
|
||||
{readOnly ? (
|
||||
<View>
|
||||
{pricingMethod === "BY_GROSS_WEIGHT"
|
||||
{orderVO.pricingMethod === "BY_GROSS_WEIGHT"
|
||||
? "按毛重报价"
|
||||
: pricingMethod === "BY_NET_WEIGHT"
|
||||
: orderVO.pricingMethod === "BY_NET_WEIGHT"
|
||||
? "按净重报价"
|
||||
: "未选择"}
|
||||
</View>
|
||||
@ -52,11 +42,13 @@ export default function MarketPriceSection(props: {
|
||||
<Radio.Group
|
||||
direction={"horizontal"}
|
||||
//@ts-ignore
|
||||
value={pricingMethod}
|
||||
value={orderVO.pricingMethod}
|
||||
onChange={(value) =>
|
||||
setPricingMethod(
|
||||
value as BusinessAPI.OrderVO["pricingMethod"],
|
||||
)
|
||||
onChange?.({
|
||||
...orderVO,
|
||||
pricingMethod:
|
||||
value as BusinessAPI.OrderVO["pricingMethod"],
|
||||
})
|
||||
}
|
||||
>
|
||||
<Radio value="BY_GROSS_WEIGHT">按毛重报价</Radio>
|
||||
@ -189,7 +181,7 @@ export default function MarketPriceSection(props: {
|
||||
<View className="flex items-center justify-between">
|
||||
<Text className="text-sm text-gray-500">销售金额</Text>
|
||||
<Text className="text-sm font-medium">
|
||||
{pricingMethod
|
||||
{orderVO.pricingMethod
|
||||
? `${calculator.calculateSupplierAmount(supplier)} 元`
|
||||
: "-"}
|
||||
</Text>
|
||||
@ -206,7 +198,7 @@ export default function MarketPriceSection(props: {
|
||||
销售金额
|
||||
</View>
|
||||
<View className="text-neutral-darkest text-sm font-medium">
|
||||
{pricingMethod ? `${saleAmount} 元` : "-"}
|
||||
{orderVO.pricingMethod ? `${saleAmount} 元` : "-"}
|
||||
</View>
|
||||
</View>
|
||||
<View className="flex !h-8 flex-row items-center justify-between">
|
||||
@ -215,7 +207,7 @@ export default function MarketPriceSection(props: {
|
||||
平均单价
|
||||
</View>
|
||||
<View className="text-neutral-darkest text-sm font-medium">
|
||||
{pricingMethod ? `${averagePurchasePrice} 元/斤` : "-"}
|
||||
{orderVO.pricingMethod ? `${averagePurchasePrice} 元/斤` : "-"}
|
||||
</View>
|
||||
</View>
|
||||
<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 className="text-neutral-darkest text-sm font-medium">
|
||||
{pricingMethod ? `${marketPrice} 元` : "-"}
|
||||
{orderVO.pricingMethod ? `${marketPrice} 元` : "-"}
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@ -11,7 +11,6 @@ export default function TaxProvisionSection(props: {
|
||||
const { orderVO, onChange, calculator, readOnly } = props;
|
||||
const orderDealer = orderVO.orderDealer;
|
||||
|
||||
console.log("orderDealer.taxProvision", orderDealer.taxProvision);
|
||||
return (
|
||||
<View className={"flex flex-col gap-2.5"}>
|
||||
{/* 卡片形式展示计提税金信息 */}
|
||||
|
||||
@ -11,7 +11,6 @@ export default function TaxSubsidySection(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"}>
|
||||
{/* 卡片形式展示返点信息 */}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user