- 统一使用非空断言操作符处理costItemId比较 - 在Step1Form中添加useImperativeHandle暴露表单验证方法 - 替换按钮图标组件为Icon增强视觉一致性 - 为输入框添加清空功能图标提升用户体验 - 调整商品单位默认值从"件"改为"kg" - 在MelonFarmer模块初始化时添加packageUsage配置 - 修正selected属性赋值逻辑确保布尔值正确性 - 简化OrderOption模块保存逻辑移除冗余try-catch - 重构OrderPackage模块减少依赖优化性能 - 引入全局loading状态改善异步操作反馈 - 重新设计纸箱类型启用逻辑支持动态配置 - 移除大量冗余状态管理与事件处理函数 - 优化useEffect依赖数组避免不必要的重复执行 - 整体简化组件结构提高可维护性
139 lines
4.2 KiB
TypeScript
139 lines
4.2 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");
|
|
},
|
|
});
|
|
};
|
|
|
|
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.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);
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
}
|