update
This commit is contained in:
parent
f24f8a5024
commit
7e8af9cdb3
@ -49,6 +49,8 @@ interface OutboundRecord {
|
||||
quantity: number;
|
||||
recipient: string;
|
||||
date: string;
|
||||
warehouse: string;
|
||||
supplier: string;
|
||||
}
|
||||
|
||||
const fadeIn = {
|
||||
@ -236,7 +238,7 @@ export default function InventoryManagement() {
|
||||
}))
|
||||
}
|
||||
|
||||
const addOutboundRecord = (productId: number, productName: string, quantity: number, recipient: string) => {
|
||||
const addOutboundRecord = (productId: number, productName: string, quantity: number, recipient: string, warehouse: string, supplier: string) => {
|
||||
const newRecord: OutboundRecord = {
|
||||
id: Date.now(),
|
||||
productId,
|
||||
@ -244,6 +246,8 @@ export default function InventoryManagement() {
|
||||
quantity,
|
||||
recipient,
|
||||
date: new Date().toISOString(),
|
||||
warehouse,
|
||||
supplier
|
||||
}
|
||||
setOutboundRecords(prevRecords => [...prevRecords, newRecord])
|
||||
|
||||
@ -257,6 +261,45 @@ export default function InventoryManagement() {
|
||||
)
|
||||
}
|
||||
|
||||
const updateWarehouseName = (oldName: string, newName: string) => {
|
||||
setInventory(prevInventory =>
|
||||
prevInventory.map(item =>
|
||||
item.warehouse === oldName ? { ...item, warehouse: newName } : item
|
||||
)
|
||||
)
|
||||
setOutboundRecords(prevRecords =>
|
||||
prevRecords.map(record =>
|
||||
record.warehouse === oldName ? { ...record, warehouse: newName } : record
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
const updateSupplierName = (oldName: string, newName: string) => {
|
||||
setInventory(prevInventory =>
|
||||
prevInventory.map(item =>
|
||||
item.supplier === oldName ? { ...item, supplier: newName } : item
|
||||
)
|
||||
)
|
||||
setOutboundRecords(prevRecords =>
|
||||
prevRecords.map(record =>
|
||||
record.supplier === oldName ? { ...record, supplier: newName } : record
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
const updateProductName = (oldName: string, newName: string) => {
|
||||
setInventory(prevInventory =>
|
||||
prevInventory.map(item =>
|
||||
item.name === oldName ? { ...item, name: newName } : item
|
||||
)
|
||||
)
|
||||
setOutboundRecords(prevRecords =>
|
||||
prevRecords.map(record =>
|
||||
record.productName === oldName ? { ...record, productName: newName } : record
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container mx-auto p-4 space-y-8">
|
||||
<header className="text-center bg-gradient-to-r from-blue-500 to-purple-600 text-white py-8 rounded-lg shadow-lg">
|
||||
@ -306,6 +349,7 @@ export default function InventoryManagement() {
|
||||
<Input
|
||||
id="itemQuantity"
|
||||
type="number"
|
||||
|
||||
value={newItemQuantity}
|
||||
onChange={(e) => setNewItemQuantity(e.target.value)}
|
||||
placeholder="输入数量"
|
||||
@ -490,13 +534,13 @@ export default function InventoryManagement() {
|
||||
</Card>
|
||||
</TabsContent>
|
||||
<TabsContent value="warehouses">
|
||||
<WarehouseManagement warehouses={warehouses} setWarehouses={setWarehouses} />
|
||||
<WarehouseManagement warehouses={warehouses} setWarehouses={setWarehouses} updateWarehouseName={updateWarehouseName} />
|
||||
</TabsContent>
|
||||
<TabsContent value="suppliers">
|
||||
<SupplierManagement suppliers={suppliers} setSuppliers={setSuppliers} />
|
||||
<SupplierManagement suppliers={suppliers} setSuppliers={setSuppliers} updateSupplierName={updateSupplierName} />
|
||||
</TabsContent>
|
||||
<TabsContent value="products">
|
||||
<ProductManagement products={products} setProducts={setProducts} />
|
||||
<ProductManagement products={products} setProducts={setProducts} updateProductName={updateProductName} />
|
||||
</TabsContent>
|
||||
<TabsContent value="outbound">
|
||||
<OutboundManagement
|
||||
@ -527,7 +571,15 @@ export default function InventoryManagement() {
|
||||
)
|
||||
}
|
||||
|
||||
function WarehouseManagement({ warehouses, setWarehouses }: { warehouses: string[], setWarehouses: React.Dispatch<React.SetStateAction<string[]>> }) {
|
||||
function WarehouseManagement({
|
||||
warehouses,
|
||||
setWarehouses,
|
||||
updateWarehouseName
|
||||
}: {
|
||||
warehouses: string[],
|
||||
setWarehouses: React.Dispatch<React.SetStateAction<string[]>>,
|
||||
updateWarehouseName: (oldName: string, newName: string) => void
|
||||
}) {
|
||||
const [newWarehouse, setNewWarehouse] = useState("")
|
||||
const [editingWarehouse, setEditingWarehouse] = useState<string | null>(null)
|
||||
const [editedWarehouseName, setEditedWarehouseName] = useState("")
|
||||
@ -549,6 +601,7 @@ function WarehouseManagement({ warehouses, setWarehouses }: { warehouses: string
|
||||
const saveEdit = () => {
|
||||
if (editingWarehouse && editedWarehouseName) {
|
||||
setWarehouses(warehouses.map(w => w === editingWarehouse ? editedWarehouseName : w))
|
||||
updateWarehouseName(editingWarehouse, editedWarehouseName)
|
||||
setEditingWarehouse(null)
|
||||
setEditedWarehouseName("")
|
||||
}
|
||||
@ -652,7 +705,15 @@ function WarehouseManagement({ warehouses, setWarehouses }: { warehouses: string
|
||||
)
|
||||
}
|
||||
|
||||
function SupplierManagement({ suppliers, setSuppliers }: { suppliers: Supplier[], setSuppliers: React.Dispatch<React.SetStateAction<Supplier[]>> }) {
|
||||
function SupplierManagement({
|
||||
suppliers,
|
||||
setSuppliers,
|
||||
updateSupplierName
|
||||
}: {
|
||||
suppliers: Supplier[],
|
||||
setSuppliers: React.Dispatch<React.SetStateAction<Supplier[]>>,
|
||||
updateSupplierName: (oldName: string, newName: string) => void
|
||||
}) {
|
||||
const [newSupplier, setNewSupplier] = useState("")
|
||||
const [editingSupplier, setEditingSupplier] = useState<number | null>(null)
|
||||
const [editedSupplierName, setEditedSupplierName] = useState("")
|
||||
@ -673,7 +734,11 @@ function SupplierManagement({ suppliers, setSuppliers }: { suppliers: Supplier[]
|
||||
|
||||
const saveEdit = () => {
|
||||
if (editingSupplier !== null && editedSupplierName) {
|
||||
const oldName = suppliers.find(s => s.id === editingSupplier)?.name
|
||||
setSuppliers(suppliers.map(s => s.id === editingSupplier ? { ...s, name: editedSupplierName } : s))
|
||||
if (oldName) {
|
||||
updateSupplierName(oldName, editedSupplierName)
|
||||
}
|
||||
setEditingSupplier(null)
|
||||
setEditedSupplierName("")
|
||||
}
|
||||
@ -777,7 +842,15 @@ function SupplierManagement({ suppliers, setSuppliers }: { suppliers: Supplier[]
|
||||
)
|
||||
}
|
||||
|
||||
function ProductManagement({ products, setProducts }: { products: Product[], setProducts: React.Dispatch<React.SetStateAction<Product[]>> }) {
|
||||
function ProductManagement({
|
||||
products,
|
||||
setProducts,
|
||||
updateProductName
|
||||
}: {
|
||||
products: Product[],
|
||||
setProducts: React.Dispatch<React.SetStateAction<Product[]>>,
|
||||
updateProductName: (oldName: string, newName: string) => void
|
||||
}) {
|
||||
const [newProduct, setNewProduct] = useState("")
|
||||
const [editingProduct, setEditingProduct] = useState<number | null>(null)
|
||||
const [editedProductName, setEditedProductName] = useState("")
|
||||
@ -798,7 +871,11 @@ function ProductManagement({ products, setProducts }: { products: Product[], set
|
||||
|
||||
const saveEdit = () => {
|
||||
if (editingProduct !== null && editedProductName) {
|
||||
const oldName = products.find(p => p.id === editingProduct)?.name
|
||||
setProducts(products.map(p => p.id === editingProduct ? { ...p, name: editedProductName } : p))
|
||||
if (oldName) {
|
||||
updateProductName(oldName, editedProductName)
|
||||
}
|
||||
setEditingProduct(null)
|
||||
setEditedProductName("")
|
||||
}
|
||||
@ -892,7 +969,7 @@ function ProductManagement({ products, setProducts }: { products: Product[], set
|
||||
您确定要删除这个商品吗?此操作无法撤销。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={deleteProduct}>确认删除</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
@ -910,7 +987,7 @@ function OutboundManagement({
|
||||
inventory: InventoryItem[],
|
||||
setInventory: React.Dispatch<React.SetStateAction<InventoryItem[]>>,
|
||||
outboundRecords: OutboundRecord[],
|
||||
addOutboundRecord: (productId: number, productName: string, quantity: number, recipient: string) => void,
|
||||
addOutboundRecord: (productId: number, productName: string, quantity: number, recipient: string, warehouse: string, supplier: string) => void,
|
||||
products: Product[]
|
||||
}) {
|
||||
const [selectedProduct, setSelectedProduct] = useState("")
|
||||
@ -925,7 +1002,7 @@ function OutboundManagement({
|
||||
alert('出库数量不能大于库存数量!')
|
||||
return
|
||||
}
|
||||
addOutboundRecord(product.id, product.name, quantity, recipient)
|
||||
addOutboundRecord(product.id, product.name, quantity, recipient, product.warehouse, product.supplier)
|
||||
// 清空输入框
|
||||
setSelectedProduct("")
|
||||
setOutboundQuantity("")
|
||||
@ -992,6 +1069,8 @@ function OutboundManagement({
|
||||
<TableHead>商品名称</TableHead>
|
||||
<TableHead>数量</TableHead>
|
||||
<TableHead>接收方</TableHead>
|
||||
<TableHead>仓库</TableHead>
|
||||
<TableHead>供应商</TableHead>
|
||||
<TableHead>日期</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
@ -1001,6 +1080,8 @@ function OutboundManagement({
|
||||
<TableCell>{record.productName}</TableCell>
|
||||
<TableCell>{record.quantity}</TableCell>
|
||||
<TableCell>{record.recipient}</TableCell>
|
||||
<TableCell>{record.warehouse}</TableCell>
|
||||
<TableCell>{record.supplier}</TableCell>
|
||||
<TableCell>{format(new Date(record.date), 'yyyy-MM-dd HH:mm:ss')}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
|
Loading…
Reference in New Issue
Block a user