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"); }, }); }; return ( <> {orderCost.name} {!readOnly && ( {orderCostItemList.length > 0 && ( setShowEditModal(true)} > 编辑 )} 删除 )} { 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 && ( {orderCostItemList.map((orderCostItem) => { return ( {orderCostItem.name} {orderCostItem.count} {orderCostItem.unit} ); })} )} {/* 使用 CostCreate 组件进行编辑 */} setShowEditModal(false)} onSave={(editedItem, editedItemList) => { onEdit(editedItem, editedItemList); setShowEditModal(false); }} /> ); }