From 9609841692e00b2c3ca8c8fafd78481d604d574a Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Wed, 26 Aug 2026 09:47:09 +0300 Subject: [PATCH] Add znzt module --- package-lock.json | 28 + package.json | 1 + src/api/monthlyOrders.ts | 33 +- src/pages/OrdersPage.tsx | 184 +- src/rest.txt | 7964 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 8158 insertions(+), 52 deletions(-) create mode 100644 src/rest.txt diff --git a/package-lock.json b/package-lock.json index 6b1063a..9638c7f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@mantine/hooks": "^9.5.2", "@mantine/notifications": "^9.5.2", "@tabler/icons-react": "^3.46.0", + "@tanstack/react-virtual": "^3.14.10", "axios": "^1.19.0", "crypto-js": "^4.2.0", "dayjs": "^1.11.23", @@ -970,6 +971,33 @@ "react": ">= 16" } }, + "node_modules/@tanstack/react-virtual": { + "version": "3.14.10", + "resolved": "https://registry.npmjs.org/@tanstack/react-virtual/-/react-virtual-3.14.10.tgz", + "integrity": "sha512-SRyoUbdFMRHuYXMijV5H4ZarQWpXkj3iANq8OFre+pybeVap8ZJjZ3Nz9bVjx4d8PfobVUQUdKyyyHYk3E+djw==", + "license": "MIT", + "dependencies": { + "@tanstack/virtual-core": "3.17.8" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", + "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, + "node_modules/@tanstack/virtual-core": { + "version": "3.17.8", + "resolved": "https://registry.npmjs.org/@tanstack/virtual-core/-/virtual-core-3.17.8.tgz", + "integrity": "sha512-BfEvehNpOT75r5Ksc5xW6NZuXujTfb7nlSEyVu4XHG3gdxNg1KqXruWbDewXOUaUYIo4oRbSfkjIajz4MAT8tA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, "node_modules/@types/crypto-js": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz", diff --git a/package.json b/package.json index ed95a66..4732cb8 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@mantine/hooks": "^9.5.2", "@mantine/notifications": "^9.5.2", "@tabler/icons-react": "^3.46.0", + "@tanstack/react-virtual": "^3.14.10", "axios": "^1.19.0", "crypto-js": "^4.2.0", "dayjs": "^1.11.23", diff --git a/src/api/monthlyOrders.ts b/src/api/monthlyOrders.ts index 1780903..395b4f1 100644 --- a/src/api/monthlyOrders.ts +++ b/src/api/monthlyOrders.ts @@ -1,12 +1,31 @@ -import apiClient from './client' -import type {FrontendOrderMatrix, MonthlyOrderClient} from "../types/orders.ts"; +import apiClient from './client'; +import type { FrontendOrderMatrix, MonthlyOrderClient } from "../types/orders.ts"; export const monthlyOrdersApi = { - // Получение матрицы (клиенты из гугла + номенклатура + черновики из БД) - getMatrix: () => - apiClient.get('/monthly-orders/matrix'), + getMatrix: () => apiClient.get('/monthly-orders/matrix'), - // Сохранение заказов (черновик или отправка) saveOrders: (orders: MonthlyOrderClient[]) => apiClient.post<{ data: string }>('/monthly-orders/save', { orders }), -} \ No newline at end of file + + // TODO: Реализовать на бэкенде + uploadAttachment: (file: File, clientName: string) => { + const fd = new FormData(); + fd.append('file', file); + fd.append('client_name', clientName); + return apiClient.post<{ url: string }>('/monthly-orders/attachments', fd, { + headers: { 'Content-Type': 'multipart/form-data' }, + }); + }, + + // TODO: Реализовать на бэкенде + exportReport: (reportType: 1 | 2) => + apiClient.get(`/monthly-orders/report/${reportType}`, { responseType: 'blob' }) + .then((res) => { + const url = URL.createObjectURL(res.data); + const a = document.createElement('a'); + a.href = url; + a.download = `report_${reportType}_${new Date().toISOString().split('T')[0]}.xlsx`; + a.click(); + URL.revokeObjectURL(url); + }), +}; \ No newline at end of file diff --git a/src/pages/OrdersPage.tsx b/src/pages/OrdersPage.tsx index a0d6488..2ce1684 100644 --- a/src/pages/OrdersPage.tsx +++ b/src/pages/OrdersPage.tsx @@ -1,7 +1,8 @@ import React, { useState, useEffect, useCallback } from 'react' import { Box, Table, Title, Text, Paper, Stack, Button, Group, - Select, Textarea, Badge, LoadingOverlay, Card, Divider + MultiSelect, Textarea, Badge, LoadingOverlay, Card, Divider, + CheckIcon, Select } from '@mantine/core' import { useMediaQuery } from '@mantine/hooks' import { notifications } from '@mantine/notifications' @@ -9,6 +10,12 @@ import { IconDeviceFloppy, IconLock } from '@tabler/icons-react' import type { FrontendOrderMatrix, MonthlyOrderClient, NomenclatureItem } from "../types/orders.ts"; import { monthlyOrdersApi } from "../api/monthlyOrders.ts"; +// Константы для селекторов +const DECADE_OPTIONS = ['1-я', '2-я', '3-я', 'Склад', 'Клиент']; +const DELIVERY_OPTIONS = ['Предоплата', 'Отсрочка']; +const CONDITIONS_OPTIONS = ['Стандарт', 'Спец. условия', 'Акция']; +const PAYMENT_OPTIONS = ['Ф1-Ф1', 'Ф1-Ф2', 'Ф2-Ф1', 'Ф2-Ф2']; + interface OrdersPageProps { onError: (msg: string) => void; } @@ -19,7 +26,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { const [saving, setSaving] = useState(false) const [pageError, setPageError] = useState(null) const [editableOrders, setEditableOrders] = useState>({}) - const isMobile = useMediaQuery('(max-width: 768px)') const [activeClientName, setActiveClientName] = useState(null) @@ -30,7 +36,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { const res = await monthlyOrdersApi.getMatrix() const matrix = res.data setData(matrix) - if (matrix && matrix.clients) { const initialMap: Record = {} matrix.clients.forEach((c, idx) => { @@ -38,7 +43,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { if (!preserveActive && idx === 0) { setActiveClientName(clientName) } - if (c.db_order) { initialMap[clientName] = { ...c.db_order } } else { @@ -46,9 +50,10 @@ export default function OrdersPage({ onError }: OrdersPageProps) { client_name: clientName, items: [], manager_comment: '', - decade: '1 декада', - delivery: 'Самовывоз', - payment_form: 'Безналичная', + decade: '1-я', + delivery: 'Предоплата', + payment_form: 'Ф1-Ф1', + conditions: 'Стандарт', } } }) @@ -71,7 +76,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { setEditableOrders(prev => { const currentOrder = prev[clientName] || { client_name: clientName, items: [] } const items = [...(currentOrder.items || [])] - const existingIndex = items.findIndex(i => i.nomenclature_name === nomName) if (existingIndex >= 0) { if (qty === null || qty === 0) { @@ -82,7 +86,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { } else if (qty !== null && qty > 0) { items.push({ nomenclature_name: nomName, nomenclature_type: nomType, quantity: qty }) } - return { ...prev, [clientName]: { ...currentOrder, items } @@ -90,6 +93,51 @@ export default function OrdersPage({ onError }: OrdersPageProps) { }) }, []) + // Обработка выбора параметров из MultiSelect + const handleParamsChange = useCallback((clientName: string, values: string[]) => { + setEditableOrders(prev => { + const currentOrder = prev[clientName] || { + client_name: clientName, + items: [], + decade: '1-я', + delivery: 'Предоплата', + payment_form: 'Ф1-Ф1', + conditions: 'Стандарт', + } + + // Разбираем выбранные значения по категориям + const newDecade = values.find(v => DECADE_OPTIONS.includes(v)) || currentOrder.decade; + const newDelivery = values.find(v => DELIVERY_OPTIONS.includes(v)) || currentOrder.delivery; + const newConditions = values.find(v => CONDITIONS_OPTIONS.includes(v)) || currentOrder.conditions; + const newPayment = values.find(v => PAYMENT_OPTIONS.includes(v)) || currentOrder.payment_form; + + return { + ...prev, + [clientName]: { + ...currentOrder, + decade: newDecade, + delivery: newDelivery, + conditions: newConditions, + payment_form: newPayment, + } + } + }) + }, []) + + // Получаем текущие значения для клиента + const getClientParams = useCallback((clientName: string): string[] => { + const order = editableOrders[clientName]; + if (!order) return ['1-я', 'Предоплата', 'Стандарт', 'Ф1-Ф1']; + + const params: string[] = []; + if (order.decade) params.push(order.decade); + if (order.delivery) params.push(order.delivery); + if (order.conditions) params.push(order.conditions); + if (order.payment_form) params.push(order.payment_form); + + return params; + }, [editableOrders]); + const validateBeforeSave = (): boolean => { for (const [clientName, order] of Object.entries(editableOrders)) { const hasItems = order.items && order.items.length > 0 @@ -107,7 +155,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { const handleSave = async () => { if (!validateBeforeSave()) return - try { setSaving(true) const ordersArray = Object.values(editableOrders) @@ -122,7 +169,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { } if (loading) return - if (pageError) { return ( @@ -130,7 +176,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { ); } - if (!data) return Нет данных return ( @@ -144,7 +189,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { )} - {data.is_locked ? ( }> @@ -171,7 +215,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) { value={activeClientName} onChange={setActiveClientName} /> - {activeClientName && ( )} @@ -192,12 +237,13 @@ export default function OrdersPage({ onError }: OrdersPageProps) { Номенклатура {data.clients?.map(c => ( - + {c.google_data.name} @@ -223,7 +269,7 @@ export default function OrdersPage({ onError }: OrdersPageProps) { ) } -// 🚀 Мемоизированная строка с ультрабыстрыми нативными инпутами +// Мемоизированная строка таблицы interface MemoizedTableRowProps { nom: NomenclatureItem; clients: any[]; @@ -243,7 +289,6 @@ const MemoizedTableRow = React.memo(({ nom, clients, editableOrders, isLocked, h const order = editableOrders[clientName] const item = order?.items?.find(i => i.nomenclature_name === nom.name) const qty = item && item.quantity !== null ? item.quantity : '' - return ( - setEditableOrders: React.Dispatch>> + handleParamsChange: (clientName: string, values: string[]) => void + getClientParams: (clientName: string) => string[] isLocked: boolean } -function BlockMeta({ clientName, editableOrders, setEditableOrders, isLocked }: BlockMetaProps) { +function BlockMeta({ clientName, editableOrders, handleParamsChange, getClientParams, isLocked }: BlockMetaProps) { const order = editableOrders[clientName] || {} + const currentValue = getClientParams(clientName) + + // Создаем данные для MultiSelect с группировкой + const selectData = [ + { group: 'Декада', items: DECADE_OPTIONS.map(opt => ({ value: opt, label: opt })) }, + { group: 'Доставка', items: DELIVERY_OPTIONS.map(opt => ({ value: opt, label: opt })) }, + { group: 'Условия', items: CONDITIONS_OPTIONS.map(opt => ({ value: opt, label: opt })) }, + { group: 'Оплата', items: PAYMENT_OPTIONS.map(opt => ({ value: opt, label: opt })) }, + ]; return ( -