ERPTurbo_Client/packages/app-client/src/components/purchase/cost/CostCard.tsx
shenyifei 881685a653 feat(purchase): 优化采购模块费用与箱型信息处理逻辑
- 在 PriceEditor 组件中增加 negative 属性以支持负数显示
- 优化 Step1Form 表单模块渲染结构,提升可读性
- 修正 CostCard 中价格与数量的展示顺序
- 在 CostCreate 组件中过滤掉“空箱费”和“纸箱费”的选项
- 增加 getTitle 方法动态设置费用类型的标题
- 重构 OrderOption 中费用保存的筛选逻辑
- 强化 OrderCostItem 中字段校验及数据初始化处理
- 完善 BasicInfoSection 的发货日期选择器功能
- 调整 CostDifferenceSection 中分红金额相关文案与计算方式
- 简化 DeliveryFormSection 数据初始化流程
- 移除 EmptyBoxInfoSection 和 PackageInfoSection 中冗余的成本单价和箱重编辑功能
- 在 audit 页面中优化费用项目的初始化加载逻辑并确保计提费正确附加到订单中
2025-12-11 17:14:27 +08:00

147 lines
4.4 KiB
TypeScript

import { Text, View } from "@tarojs/components";
import { useState } from "react";
import { Dialog } from "@nutui/nutui-react-taro";
import { PriceEditor } from "@/components";
import CostCreate from "./CostCreate";
interface CostCardComponentProps {
item: BusinessAPI.OrderCost;
purchaseOrderVO: BusinessAPI.PurchaseOrderVO;
readOnly?: boolean;
onEdit: (
editedItem: BusinessAPI.OrderCost,
editedItemList: BusinessAPI.OrderCostItem[],
) => void;
onDelete: (orderCostId: string) => void;
costList: BusinessAPI.CostVO[];
}
export default function CostCard(props: CostCardComponentProps) {
const {
item: orderCost,
purchaseOrderVO,
readOnly,
onEdit,
onDelete,
costList,
} = props;
// 控制 CostCreate 组件的显示状态
const [showEditModal, setShowEditModal] = useState(false);
const amount = orderCost.count * orderCost.price;
const orderCostItemList = purchaseOrderVO.orderCostItemList?.filter(
(orderCostItem) =>
orderCost.costItemIds?.includes(orderCostItem.costItemId!),
);
const handleDelete = () => {
Dialog.open("dialog", {
title: "确认删除",
content: `确定要删除费用"${orderCost.name}"吗?`,
confirmText: "确认",
cancelText: "取消",
onConfirm: () => {
onDelete(orderCost.orderCostId);
Dialog.close("dialog");
},
onCancel: () => {
Dialog.close("dialog");
},
});
};
if (
orderCostItemList.length == 0 &&
(orderCost.type === "ARTIFICIAL_TYPE" || orderCost.type === "MATERIAL_TYPE")
) {
return;
}
return (
<>
<View className="bg-primary/3 rounded-lg border-b border-gray-100 p-2.5">
<View className="mb-2 flex items-center justify-between">
<Text className="text-sm font-medium">{orderCost.name}</Text>
{!readOnly && (
<View className="flex gap-2">
{orderCostItemList.length > 0 && (
<View
className="cursor-pointer rounded-lg bg-blue-100 px-3 py-1 text-xs font-medium text-blue-600 transition-colors hover:bg-blue-200"
onClick={() => setShowEditModal(true)}
>
</View>
)}
<View
className="cursor-pointer rounded-lg bg-red-100 px-3 py-1 text-xs font-medium text-red-600 transition-colors hover:bg-red-200"
onClick={handleDelete}
>
</View>
</View>
)}
</View>
<View className="flex flex-1">
<PriceEditor
value={amount}
onSave={(newAmount) => {
const newPrice = newAmount / orderCost.count;
const editedItem = {
...orderCost,
price: newPrice,
};
// 调用 onEdit 回调更新数据
onEdit(editedItem, orderCostItemList || []);
}}
readOnly={readOnly}
label="金额"
unit="元"
icon="money-bill"
hint="点击金额可直接编辑"
/>
{orderCostItemList.length > 0 && (
<View className="flex flex-1 flex-col gap-2 pl-4">
{orderCostItemList.map((orderCostItem) => {
return (
<View
key={orderCostItem.orderCostItemId}
className="flex items-center justify-between"
>
<Text className="text-sm text-gray-500">
{orderCostItem.name}
</Text>
<Text className="text-sm font-medium">
{orderCostItem.price} {orderCostItem.count}{" "}
{orderCostItem.unit}
</Text>
</View>
);
})}
</View>
)}
</View>
</View>
{/* 使用 CostCreate 组件进行编辑 */}
<CostCreate
type={orderCost.type}
costList={costList}
visible={showEditModal}
editMode
orderCost={orderCost}
orderCostItemList={orderCostItemList}
onClose={() => setShowEditModal(false)}
onSave={(editedItem, editedItemList) => {
onEdit(editedItem, editedItemList);
setShowEditModal(false);
}}
/>
</>
);
}