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BF=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D1=83=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=BB?= =?UTF-8?q?=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=BE=D0=BC=20=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=BE=D0=B2=20=D0=B2=20=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D0=B7=D0=B8=D0=BD=D0=B5=20=D0=B8=20=D1=83=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D1=88=D0=B5=D0=BD=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B8=D1=82=D0=BE=D0=B3=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supplies/create-supply-page.tsx | 396 +++++++++++++++--- 1 file changed, 329 insertions(+), 67 deletions(-) diff --git a/src/components/supplies/create-supply-page.tsx b/src/components/supplies/create-supply-page.tsx index 684edca..b9966ba 100644 --- a/src/components/supplies/create-supply-page.tsx +++ b/src/components/supplies/create-supply-page.tsx @@ -64,6 +64,8 @@ interface WholesalerProduct { interface SelectedProduct extends WholesalerProduct { selectedQuantity: number + wholesalerId: string + wholesalerName: string } // Моковые данные оптовиков @@ -243,27 +245,35 @@ export function CreateSupplyPage() { const updateProductQuantity = (productId: string, quantity: number) => { const product = mockProducts.find(p => p.id === productId) - if (!product) return + if (!product || !selectedWholesaler) return setSelectedProducts(prev => { - const existing = prev.find(p => p.id === productId) + const existing = prev.find(p => p.id === productId && p.wholesalerId === selectedWholesaler.id) if (quantity === 0) { - return prev.filter(p => p.id !== productId) + return prev.filter(p => !(p.id === productId && p.wholesalerId === selectedWholesaler.id)) } if (existing) { return prev.map(p => - p.id === productId ? { ...p, selectedQuantity: quantity } : p + p.id === productId && p.wholesalerId === selectedWholesaler.id + ? { ...p, selectedQuantity: quantity } + : p ) } else { - return [...prev, { ...product, selectedQuantity: quantity }] + return [...prev, { + ...product, + selectedQuantity: quantity, + wholesalerId: selectedWholesaler.id, + wholesalerName: selectedWholesaler.name + }] } }) } const getSelectedQuantity = (productId: string): number => { - const selected = selectedProducts.find(p => p.id === productId) + if (!selectedWholesaler) return 0 + const selected = selectedProducts.find(p => p.id === productId && p.wholesalerId === selectedWholesaler.id) return selected ? selected.selectedQuantity : 0 } @@ -335,70 +345,144 @@ export function CreateSupplyPage() { {showSummary && selectedProducts.length > 0 && ( - -
-

- - Резюме заказа -

- - {selectedProducts.length} товаров - -
-
- {selectedProducts.map((product) => { - const discountedPrice = product.discount - ? product.price * (1 - product.discount / 100) - : product.price - return ( -
-
- {product.name} -
- {product.name} -
- × {product.selectedQuantity} - {product.discount && ( - - -{product.discount}% - - )} + +
+
+

+ + Корзина ({selectedProducts.length}) +

+ +
+ + {/* Текущий оптовик */} +
+
+ + {selectedWholesaler?.name} + + {selectedProducts.filter(p => p.wholesalerId === selectedWholesaler?.id).length} товар(ов) + +
+ +
+ {selectedProducts.filter(p => p.wholesalerId === selectedWholesaler?.id).map((product) => { + const discountedPrice = product.discount + ? product.price * (1 - product.discount / 100) + : product.price + const totalPrice = discountedPrice * product.selectedQuantity + + return ( +
+ {product.name} +
+

{product.name}

+

{product.article}

+
+ × {product.selectedQuantity} +
+
{formatCurrency(totalPrice)}
+ {product.discount && ( +
+ {formatCurrency(product.price * product.selectedQuantity)} +
+ )} +
+
-
-
- - {formatCurrency(discountedPrice * product.selectedQuantity)} - - {product.discount && ( -
- {formatCurrency(product.price * product.selectedQuantity)} -
- )} -
-
- ) - })} -
- - Итого: {getTotalItems()} товаров - - - {formatCurrency(getTotalAmount())} - + ) + })} +
+
+ + {/* Другие оптовики в корзине */} + {Object.entries( + selectedProducts.filter(p => p.wholesalerId !== selectedWholesaler?.id).reduce((acc, product) => { + if (!acc[product.wholesalerId]) { + acc[product.wholesalerId] = { + wholesaler: product.wholesalerName, + products: [] + } + } + acc[product.wholesalerId].products.push(product) + return acc + }, {} as Record) + ).map(([wholesalerId, group]) => ( +
+
+ + {group.wholesaler} + + {group.products.length} товар(ов) + +
+ +
+ {group.products.map((product) => { + const discountedPrice = product.discount + ? product.price * (1 - product.discount / 100) + : product.price + const totalPrice = discountedPrice * product.selectedQuantity + + return ( +
+ {product.name} +
+

{product.name}

+

{product.article}

+
+ × {product.selectedQuantity} +
+
{formatCurrency(totalPrice)}
+ {product.discount && ( +
+ {formatCurrency(product.price * product.selectedQuantity)} +
+ )} +
+
+
+
+ ) + })} +
+
+ ))} + + {/* Итого */} +
+
+ + Итого: {getTotalItems()} товаров + + + {formatCurrency(getTotalAmount())} + +
+
-
)} @@ -596,8 +680,172 @@ export function CreateSupplyPage() {

Выберите оптовика для создания поставки

+ {selectedProducts.length > 0 && ( + + )}
+ {/* Корзина как в маркете */} + {showSummary && selectedProducts.length > 0 && ( + +
+
+

+ + Корзина ({selectedProducts.length}) +

+ +
+ + {/* Группировка по оптовикам */} + {Object.entries( + selectedProducts.reduce((acc, product) => { + if (!acc[product.wholesalerId]) { + acc[product.wholesalerId] = { + wholesaler: product.wholesalerName, + products: [] + } + } + acc[product.wholesalerId].products.push(product) + return acc + }, {} as Record) + ).map(([wholesalerId, group]) => ( +
+
+ + {group.wholesaler} + + {group.products.length} товар(ов) + +
+ +
+ {group.products.map((product) => { + const discountedPrice = product.discount + ? product.price * (1 - product.discount / 100) + : product.price + const totalPrice = discountedPrice * product.selectedQuantity + + return ( +
+ {product.name} +
+

{product.name}

+

{product.article}

+
+
+ + {product.selectedQuantity} + +
+
+
{formatCurrency(totalPrice)}
+ {product.discount && ( +
+ {formatCurrency(product.price * product.selectedQuantity)} +
+ )} +
+
+
+ +
+ ) + })} +
+
+ ))} + + {/* Итого */} +
+
+ + Итого: {getTotalItems()} товаров + + + {formatCurrency(getTotalAmount())} + +
+ +
+
+
+ )} +
{mockWholesalers.map((wholesaler) => ( ))}
+ + {/* Floating корзина */} + {selectedProducts.length > 0 && !showSummary && ( +
+ +
+ )}