Add znzt module
Deploy Manager App / deploy (push) Successful in 19s
Details
Deploy Manager App / deploy (push) Successful in 19s
Details
This commit is contained in:
parent
9701eb0b3f
commit
1bc5b93a22
|
|
@ -4,7 +4,7 @@ import {
|
|||
LoadingOverlay, Select, TextInput, Popover, ActionIcon, Stack, Textarea
|
||||
} from '@mantine/core'
|
||||
import { notifications } from '@mantine/notifications'
|
||||
import { IconDeviceFloppy, IconLock, IconSettings, IconSearch } from '@tabler/icons-react'
|
||||
import { IconDeviceFloppy, IconLock, IconSettings, IconSearch, IconFilter } from '@tabler/icons-react'
|
||||
import { useVirtualizer } from '@tanstack/react-virtual'
|
||||
import { monthlyOrdersApi } from "../api/monthlyOrders.ts"
|
||||
import type { FrontendOrderMatrix, MonthlyOrderClient, NomenclatureItem } from "../types/orders.ts"
|
||||
|
|
@ -44,7 +44,10 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
const [loading, setLoading] = useState(true)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [editableOrders, setEditableOrders] = useState<Record<string, MonthlyOrderClient>>({})
|
||||
|
||||
// Фильтры
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [selectedType, setSelectedType] = useState<string | null>(null);
|
||||
|
||||
const tableContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
|
|
@ -137,18 +140,38 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
}
|
||||
}
|
||||
|
||||
// Фильтрация номенклатуры
|
||||
// Извлечение уникальных типов номенклатуры для фильтра
|
||||
const nomenclatureTypes = useMemo(() => {
|
||||
if (!data?.nomenclatures) return [];
|
||||
return Array.from(new Set(data.nomenclatures.map(n => n.type))).sort();
|
||||
}, [data?.nomenclatures]);
|
||||
|
||||
// Фильтрация номенклатуры (поиск + тип)
|
||||
const filteredNom = useMemo(() => {
|
||||
if (!data?.nomenclatures) return [];
|
||||
return data.nomenclatures.filter(n => n.name.toLowerCase().includes(searchQuery.toLowerCase()));
|
||||
}, [data?.nomenclatures, searchQuery]);
|
||||
return data.nomenclatures.filter(n => {
|
||||
const matchSearch = n.name.toLowerCase().includes(searchQuery.toLowerCase());
|
||||
const matchType = selectedType ? n.type === selectedType : true;
|
||||
return matchSearch && matchType;
|
||||
});
|
||||
}, [data?.nomenclatures, searchQuery, selectedType]);
|
||||
|
||||
// Быстрый подсчет итоговой суммы для строки
|
||||
const getTotalForNom = useCallback((nomName: string) => {
|
||||
let total = 0;
|
||||
Object.values(editableOrders).forEach(order => {
|
||||
const item = order.items?.find(i => i.nomenclature_name === nomName);
|
||||
if (item?.quantity) total += item.quantity;
|
||||
});
|
||||
return total;
|
||||
}, [editableOrders]);
|
||||
|
||||
// Настройка виртуализации
|
||||
const rowVirtualizer = useVirtualizer({
|
||||
count: filteredNom.length,
|
||||
getScrollElement: () => tableContainerRef.current,
|
||||
estimateSize: () => 45,
|
||||
overscan: 15,
|
||||
estimateSize: () => 50,
|
||||
overscan: 10,
|
||||
});
|
||||
|
||||
if (loading) return <LoadingOverlay visible />
|
||||
|
|
@ -156,16 +179,27 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
|
||||
return (
|
||||
<Box display="flex" style={{ flexDirection: 'column', flexGrow: 1, overflow: 'hidden' }}>
|
||||
<Group justify="space-between" mb="md">
|
||||
<Group>
|
||||
<Group justify="space-between" mb="md" align="flex-end">
|
||||
<Group align="flex-end">
|
||||
<TextInput
|
||||
placeholder="Поиск по номенклатуре..."
|
||||
label="Поиск номенклатуры"
|
||||
placeholder="Название..."
|
||||
leftSection={<IconSearch size={16} />}
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.currentTarget.value)}
|
||||
w={300}
|
||||
w={250}
|
||||
/>
|
||||
<Badge color="gray" variant="light">Показано строк: {filteredNom.length}</Badge>
|
||||
<Select
|
||||
label="Фильтр по типу"
|
||||
placeholder="Все типы"
|
||||
data={['', ...nomenclatureTypes]}
|
||||
value={selectedType || ''}
|
||||
onChange={(val) => setSelectedType(val === '' ? null : val)}
|
||||
leftSection={<IconFilter size={16} />}
|
||||
w={200}
|
||||
clearable
|
||||
/>
|
||||
<Badge color="blue" variant="light" size="lg" mb={4}>Строк: {filteredNom.length}</Badge>
|
||||
</Group>
|
||||
|
||||
{data.is_locked ? (
|
||||
|
|
@ -177,45 +211,79 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
)}
|
||||
</Group>
|
||||
|
||||
{/* Контейнер таблицы, занимающий всё свободное место */}
|
||||
{/* Контейнер таблицы */}
|
||||
<Paper withBorder shadow="sm" style={{ flexGrow: 1, display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
||||
<div ref={tableContainerRef} style={{ overflow: 'auto', flexGrow: 1 }}>
|
||||
<Table stickyHeader striped highlightOnHover style={{ tableLayout: 'fixed', minWidth: 'max-content' }}>
|
||||
<Table.Thead>
|
||||
<Table.Tr>
|
||||
<Table.Th w={300} style={{ position: 'sticky', left: 0, zIndex: 3, background: 'var(--mantine-color-body)' }}>
|
||||
Номенклатура
|
||||
</Table.Th>
|
||||
{data.clients?.map(c => (
|
||||
<Table.Th key={c.google_data.name} w={180} style={{ textAlign: 'center' }}>
|
||||
<Group justify="center" gap={4} wrap="nowrap">
|
||||
<Text size="sm" fw={600} truncate>{c.google_data.name}</Text>
|
||||
<ClientSettingsPopover
|
||||
clientName={c.google_data.name}
|
||||
order={editableOrders[c.google_data.name]}
|
||||
updateClientMeta={updateClientMeta}
|
||||
isLocked={data.is_locked}
|
||||
/>
|
||||
</Group>
|
||||
</Table.Th>
|
||||
))}
|
||||
{/* 3 зафиксированные слева колонки */}
|
||||
<Table.Th w={50} style={{ position: 'sticky', left: 0, zIndex: 3, background: 'var(--mantine-color-body)' }}>№</Table.Th>
|
||||
<Table.Th w={300} style={{ position: 'sticky', left: 50, zIndex: 3, background: 'var(--mantine-color-body)' }}>Номенклатура</Table.Th>
|
||||
<Table.Th w={100} style={{ position: 'sticky', left: 350, zIndex: 3, background: 'var(--mantine-color-body)', borderRight: '2px solid var(--mantine-color-gray-3)' }}>Итого</Table.Th>
|
||||
|
||||
{/* Динамические колонки клиентов */}
|
||||
{data.clients?.map(c => {
|
||||
const clientName = c.google_data.name;
|
||||
const order = editableOrders[clientName];
|
||||
|
||||
return (
|
||||
<Table.Th key={clientName} w={240} style={{ textAlign: 'center', verticalAlign: 'top', padding: '10px 8px' }}>
|
||||
<Group justify="center" gap={4} wrap="nowrap" mb={6}>
|
||||
<Text size="sm" fw={600} style={{ whiteSpace: 'normal', wordBreak: 'break-word', lineHeight: 1.2 }}>
|
||||
{clientName}
|
||||
</Text>
|
||||
<ClientSettingsPopover
|
||||
clientName={clientName}
|
||||
order={order}
|
||||
updateClientMeta={updateClientMeta}
|
||||
isLocked={data.is_locked}
|
||||
/>
|
||||
</Group>
|
||||
|
||||
{/* Индикаторы выбранных параметров под именем */}
|
||||
<Group gap={4} justify="center">
|
||||
{order?.decade && <Badge size="xs" variant="outline" color="blue">{order.decade}</Badge>}
|
||||
{order?.delivery && <Badge size="xs" variant="outline" color="teal">{order.delivery}</Badge>}
|
||||
{order?.payment_form && <Badge size="xs" variant="outline" color="violet">{order.payment_form}</Badge>}
|
||||
{order?.manager_comment?.trim() && (
|
||||
<Badge size="xs" variant="filled" color="green" title={order.manager_comment}>Есть коммент</Badge>
|
||||
)}
|
||||
</Group>
|
||||
</Table.Th>
|
||||
)
|
||||
})}
|
||||
</Table.Tr>
|
||||
</Table.Thead>
|
||||
|
||||
<Table.Tbody>
|
||||
{/* Виртуальные отступы сверху */}
|
||||
{/* Отступы виртуализации (сверху) */}
|
||||
{rowVirtualizer.getVirtualItems().length > 0 && (
|
||||
<tr><td colSpan={data.clients.length + 1} style={{ height: rowVirtualizer.getVirtualItems()[0].start }} /></tr>
|
||||
<tr><td colSpan={data.clients.length + 3} style={{ height: rowVirtualizer.getVirtualItems()[0].start }} /></tr>
|
||||
)}
|
||||
|
||||
{/* Виртуализированные строки */}
|
||||
{/* Строки с данными */}
|
||||
{rowVirtualizer.getVirtualItems().map(virtualRow => {
|
||||
const nom = filteredNom[virtualRow.index];
|
||||
const total = getTotalForNom(nom.name);
|
||||
|
||||
return (
|
||||
<Table.Tr key={nom.name}>
|
||||
<Table.Td style={{ position: 'sticky', left: 0, background: 'var(--mantine-color-body)', zIndex: 1, borderRight: '1px solid var(--mantine-color-gray-3)' }}>
|
||||
<Text size="sm" fw={500} lineClamp={1} title={nom.name}>{nom.name}</Text>
|
||||
<Text size="xs" c="dimmed">{nom.type}</Text>
|
||||
{/* Зафиксированные колонки ячеек */}
|
||||
<Table.Td style={{ position: 'sticky', left: 0, background: 'var(--mantine-color-body)', zIndex: 1, borderRight: '1px solid var(--mantine-color-gray-2)' }}>
|
||||
<Text size="xs" c="dimmed">{virtualRow.index + 1}</Text>
|
||||
</Table.Td>
|
||||
<Table.Td style={{ position: 'sticky', left: 50, background: 'var(--mantine-color-body)', zIndex: 1, borderRight: '1px solid var(--mantine-color-gray-2)' }}>
|
||||
<Text size="sm" fw={500} style={{ whiteSpace: 'normal', wordBreak: 'break-word', lineHeight: 1.2 }}>{nom.name}</Text>
|
||||
<Text size="xs" c="dimmed" mt={2}>{nom.type}</Text>
|
||||
</Table.Td>
|
||||
<Table.Td style={{ position: 'sticky', left: 350, background: 'var(--mantine-color-body)', zIndex: 1, borderRight: '2px solid var(--mantine-color-gray-3)', textAlign: 'center' }}>
|
||||
<Badge color={total > 0 ? 'blue' : 'gray'} variant={total > 0 ? 'filled' : 'light'}>
|
||||
{total > 0 ? total : '-'}
|
||||
</Badge>
|
||||
</Table.Td>
|
||||
|
||||
{/* Ячейки ввода */}
|
||||
{data.clients.map(c => {
|
||||
const clientName = c.google_data.name;
|
||||
const item = editableOrders[clientName]?.items?.find(i => i.nomenclature_name === nom.name);
|
||||
|
|
@ -233,10 +301,10 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
)
|
||||
})}
|
||||
|
||||
{/* Виртуальные отступы снизу */}
|
||||
{/* Отступы виртуализации (снизу) */}
|
||||
{rowVirtualizer.getVirtualItems().length > 0 && (
|
||||
<tr>
|
||||
<td colSpan={data.clients.length + 1} style={{ height: rowVirtualizer.getTotalSize() - rowVirtualizer.getVirtualItems()[rowVirtualizer.getVirtualItems().length - 1].end }} />
|
||||
<td colSpan={data.clients.length + 3} style={{ height: rowVirtualizer.getTotalSize() - rowVirtualizer.getVirtualItems()[rowVirtualizer.getVirtualItems().length - 1].end }} />
|
||||
</tr>
|
||||
)}
|
||||
</Table.Tbody>
|
||||
|
|
@ -247,17 +315,17 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
)
|
||||
}
|
||||
|
||||
// Выпадающее меню параметров клиента для компактности заголовка
|
||||
// Выпадающее меню параметров
|
||||
function ClientSettingsPopover({ clientName, order, updateClientMeta, isLocked }: any) {
|
||||
return (
|
||||
<Popover width={300} position="bottom" withArrow shadow="md">
|
||||
<Popover.Target>
|
||||
<ActionIcon variant="subtle" color="gray" size="sm">
|
||||
<ActionIcon variant="light" color="blue" size="sm">
|
||||
<IconSettings size={14} />
|
||||
</ActionIcon>
|
||||
</Popover.Target>
|
||||
<Popover.Dropdown>
|
||||
<Title order={6} mb="sm">Настройки: {clientName}</Title>
|
||||
<Title order={6} mb="sm" style={{ whiteSpace: 'normal' }}>Настройки: {clientName}</Title>
|
||||
<Stack gap="xs">
|
||||
<Group grow>
|
||||
<Select label="Декада" size="xs" disabled={isLocked} data={['1-я', '2-я', '3-я', 'Склад', 'Клиент']} value={order?.decade || '1-я'} onChange={v => updateClientMeta(clientName, 'decade', v)} />
|
||||
|
|
|
|||
Loading…
Reference in New Issue