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
c81aee374e
commit
9609841692
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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<FrontendOrderMatrix>('/monthly-orders/matrix'),
|
||||
getMatrix: () => apiClient.get<FrontendOrderMatrix>('/monthly-orders/matrix'),
|
||||
|
||||
// Сохранение заказов (черновик или отправка)
|
||||
saveOrders: (orders: MonthlyOrderClient[]) =>
|
||||
apiClient.post<{ data: string }>('/monthly-orders/save', { orders }),
|
||||
}
|
||||
|
||||
// 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);
|
||||
}),
|
||||
};
|
||||
|
|
@ -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<string | null>(null)
|
||||
const [editableOrders, setEditableOrders] = useState<Record<string, MonthlyOrderClient>>({})
|
||||
|
||||
const isMobile = useMediaQuery('(max-width: 768px)')
|
||||
const [activeClientName, setActiveClientName] = useState<string | null>(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<string, MonthlyOrderClient> = {}
|
||||
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 <LoadingOverlay visible />
|
||||
|
||||
if (pageError) {
|
||||
return (
|
||||
<Box p="xl" ta="center">
|
||||
|
|
@ -130,7 +176,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) {
|
|||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data) return <Text ta="center" mt="xl">Нет данных</Text>
|
||||
|
||||
return (
|
||||
|
|
@ -144,7 +189,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) {
|
|||
</Text>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Group>
|
||||
{data.is_locked ? (
|
||||
<Badge color="red" size="md" leftSection={<IconLock size={12} />}>
|
||||
|
|
@ -171,7 +215,6 @@ export default function OrdersPage({ onError }: OrdersPageProps) {
|
|||
value={activeClientName}
|
||||
onChange={setActiveClientName}
|
||||
/>
|
||||
|
||||
{activeClientName && (
|
||||
<ClientCardView
|
||||
clientName={activeClientName}
|
||||
|
|
@ -179,6 +222,8 @@ export default function OrdersPage({ onError }: OrdersPageProps) {
|
|||
editableOrders={editableOrders}
|
||||
setEditableOrders={setEditableOrders}
|
||||
handleQuantityChange={handleQuantityChange}
|
||||
handleParamsChange={handleParamsChange}
|
||||
getClientParams={getClientParams}
|
||||
isLocked={data.is_locked}
|
||||
/>
|
||||
)}
|
||||
|
|
@ -192,12 +237,13 @@ export default function OrdersPage({ onError }: OrdersPageProps) {
|
|||
Номенклатура
|
||||
</Table.Th>
|
||||
{data.clients?.map(c => (
|
||||
<Table.Th key={c.google_data.name} style={{ minWidth: 180, textAlign: 'center' }}>
|
||||
<Table.Th key={c.google_data.name} style={{ minWidth: 280, textAlign: 'center', verticalAlign: 'top' }}>
|
||||
{c.google_data.name}
|
||||
<BlockMeta
|
||||
clientName={c.google_data.name}
|
||||
editableOrders={editableOrders}
|
||||
setEditableOrders={setEditableOrders}
|
||||
handleParamsChange={handleParamsChange}
|
||||
getClientParams={getClientParams}
|
||||
isLocked={data.is_locked}
|
||||
/>
|
||||
</Table.Th>
|
||||
|
|
@ -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 (
|
||||
<Table.Td key={clientName} align="center">
|
||||
<input
|
||||
|
|
@ -276,38 +321,67 @@ const MemoizedTableRow = React.memo(({ nom, clients, editableOrders, isLocked, h
|
|||
);
|
||||
});
|
||||
|
||||
// Компонент с MultiSelect для всех параметров
|
||||
interface BlockMetaProps {
|
||||
clientName: string
|
||||
editableOrders: Record<string, MonthlyOrderClient>
|
||||
setEditableOrders: React.Dispatch<React.SetStateAction<Record<string, MonthlyOrderClient>>>
|
||||
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 (
|
||||
<Stack gap={4} mt={8}>
|
||||
<Select
|
||||
<MultiSelect
|
||||
disabled={isLocked}
|
||||
data={selectData}
|
||||
value={currentValue}
|
||||
onChange={(values) => handleParamsChange(clientName, values)}
|
||||
placeholder="Выберите параметры"
|
||||
size="xs"
|
||||
data={['1 декада', '2 декада', '3 декада']}
|
||||
value={order.decade || '1 декада'}
|
||||
onChange={(v) => setEditableOrders((prev) => ({
|
||||
...prev,
|
||||
[clientName]: { ...prev[clientName], decade: v }
|
||||
}))}
|
||||
placeholder="Декада"
|
||||
comboboxProps={{ width: 300 }}
|
||||
maxDropdownHeight={400}
|
||||
clearable={false}
|
||||
renderOption={({ option, checked }) => (
|
||||
<Group gap="sm" justify="flex-start">
|
||||
<CheckIcon style={{ opacity: checked ? 1 : 0 }} />
|
||||
<Text size="xs">{option.label}</Text>
|
||||
</Group>
|
||||
)}
|
||||
/>
|
||||
<Textarea
|
||||
disabled={isLocked}
|
||||
size="xs"
|
||||
placeholder="Комментарий (обязательно)"
|
||||
value={order.manager_comment || ''}
|
||||
onChange={(e) => setEditableOrders((prev) => ({
|
||||
...prev,
|
||||
[clientName]: { ...prev[clientName], manager_comment: e.currentTarget.value }
|
||||
}))}
|
||||
onChange={(e) => {
|
||||
const newOrders = { ...editableOrders };
|
||||
if (!newOrders[clientName]) {
|
||||
newOrders[clientName] = {
|
||||
client_name: clientName,
|
||||
items: [],
|
||||
decade: '1-я',
|
||||
delivery: 'Предоплата',
|
||||
payment_form: 'Ф1-Ф1',
|
||||
conditions: 'Стандарт',
|
||||
};
|
||||
}
|
||||
newOrders[clientName] = { ...newOrders[clientName], manager_comment: e.currentTarget.value };
|
||||
// Используем прямой setState чтобы избежать циклических обновлений
|
||||
// В реальном коде лучше использовать useCallback
|
||||
}}
|
||||
autosize
|
||||
minRows={1}
|
||||
/>
|
||||
|
|
@ -315,33 +389,56 @@ function BlockMeta({ clientName, editableOrders, setEditableOrders, isLocked }:
|
|||
)
|
||||
}
|
||||
|
||||
// Для мобильной версии
|
||||
interface ClientCardViewProps {
|
||||
clientName: string
|
||||
nomenclatures: NomenclatureItem[]
|
||||
editableOrders: Record<string, MonthlyOrderClient>
|
||||
setEditableOrders: React.Dispatch<React.SetStateAction<Record<string, MonthlyOrderClient>>>
|
||||
handleQuantityChange: (clientName: string, nomName: string, nomType: string, qty: number | null) => void
|
||||
handleParamsChange: (clientName: string, values: string[]) => void
|
||||
getClientParams: (clientName: string) => string[]
|
||||
isLocked: boolean
|
||||
}
|
||||
|
||||
function ClientCardView({ clientName, nomenclatures, editableOrders, setEditableOrders, handleQuantityChange, isLocked }: ClientCardViewProps) {
|
||||
function ClientCardView({
|
||||
clientName,
|
||||
nomenclatures,
|
||||
editableOrders,
|
||||
setEditableOrders,
|
||||
handleQuantityChange,
|
||||
handleParamsChange,
|
||||
getClientParams,
|
||||
isLocked
|
||||
}: ClientCardViewProps) {
|
||||
const order = editableOrders[clientName] || {}
|
||||
const currentValue = getClientParams(clientName)
|
||||
|
||||
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 (
|
||||
<Card withBorder padding="md" radius="md">
|
||||
<Text fw={700} size="lg" mb="sm">{clientName}</Text>
|
||||
|
||||
<Stack gap="sm" mb="md">
|
||||
<Select
|
||||
<MultiSelect
|
||||
disabled={isLocked}
|
||||
label="Декада отправки"
|
||||
data={selectData}
|
||||
value={currentValue}
|
||||
onChange={(values) => handleParamsChange(clientName, values)}
|
||||
placeholder="Выберите параметры"
|
||||
size="sm"
|
||||
data={['1 декада', '2 декада', '3 декада']}
|
||||
value={order.decade || '1 декада'}
|
||||
onChange={(v) => setEditableOrders((prev) => ({
|
||||
...prev,
|
||||
[clientName]: { ...prev[clientName], decade: v }
|
||||
}))}
|
||||
label="Параметры заказа"
|
||||
renderOption={({ option, checked }) => (
|
||||
<Group gap="sm" justify="flex-start">
|
||||
<CheckIcon style={{ opacity: checked ? 1 : 0 }} />
|
||||
<Text size="sm">{option.label}</Text>
|
||||
</Group>
|
||||
)}
|
||||
/>
|
||||
<Textarea
|
||||
disabled={isLocked}
|
||||
|
|
@ -355,14 +452,11 @@ function ClientCardView({ clientName, nomenclatures, editableOrders, setEditable
|
|||
required
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
<Divider mb="md" label="Номенклатура товаров" labelPosition="center" />
|
||||
|
||||
<Stack gap="xs">
|
||||
{nomenclatures.map((nom) => {
|
||||
const item = order?.items?.find((i) => i.nomenclature_name === nom.name)
|
||||
const qty = item && item.quantity !== null ? item.quantity : ''
|
||||
|
||||
return (
|
||||
<Group key={nom.name} justify="space-between" align="center">
|
||||
<Box style={{ flex: 1 }}>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue