From 5f03b751ee821eba137ef3e74a28fcfab93bf8ae Mon Sep 17 00:00:00 2001 From: goodmice Date: Fri, 6 May 2022 17:04:33 +0500 Subject: [PATCH] =?UTF-8?q?=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=20DailyReport=20=20*=20?= =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B1?= =?UTF-8?q?=D0=BB=D0=BE=D0=BA=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=B4=D0=B0=D1=82=20=D1=80=D0=B0=D0=BF=D0=BE=D1=80?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=20*=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=91=D0=BD=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D1=80=D0=B0=D1=88=D0=B8=D0=B2=D0=B0=D0=B5=D0=BC?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=B4=D0=B0=D1=82=D1=8B=20=20*=20=D0=94=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D1=81=D0=B1=D1=80=D0=BE?= =?UTF-8?q?=D1=81=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D0=BB=D0=B5=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=80=D0=B0=D0=BF=D0=BE=D1=80=D1=82=D0=B0=20=20?= =?UTF-8?q?*=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=BE=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D0=BE=20=D1=84=D0=B8=D0=BB=D1=8C?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BE=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B6=D0=B0=D0=B5=D0=BC=D1=8B=D1=85=20=D1=80=D0=B0?= =?UTF-8?q?=D0=BF=D0=BE=D1=80=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reports/DailyReport/ReportEditor.jsx | 30 ++++++++++++++----- src/pages/Reports/DailyReport/index.jsx | 16 ++++++---- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/pages/Reports/DailyReport/ReportEditor.jsx b/src/pages/Reports/DailyReport/ReportEditor.jsx index 7ed3776..18697f1 100644 --- a/src/pages/Reports/DailyReport/ReportEditor.jsx +++ b/src/pages/Reports/DailyReport/ReportEditor.jsx @@ -16,9 +16,15 @@ const Item = memo(({ style, ...other }) => ( + makeColumn('От (дата, время)', 'dateStart', { width: 200, render: (_, { disabled, onChange, checkIsDateBusy }) => ( - + )}), ]), @@ -122,7 +128,7 @@ const table2Summary = () => ( ) -export const ReportEditor = memo(({ visible, data, onDone, onCancel }) => { +export const ReportEditor = memo(({ visible, data, onDone, onCancel, checkIsDateBusy }) => { const [form] = Form.useForm() const [isInvalid, setIsInvalid] = useState(false) const [isLoading, setIsLoading] = useState(false) @@ -150,22 +156,25 @@ export const ReportEditor = memo(({ visible, data, onDone, onCancel }) => { else await DailyReportService.add(idWell, formData) onDone?.(formData) + form.resetFields() }, setIsLoading, 'Не удалось сохранить суточный рапорт', 'Сохранение суточного рапорта', - ), [data, onDone, idWell]) + ), [data, onDone, idWell, form]) const onDateChange = useCallback((date) => invokeWebApiWrapperAsync( async () => { if (data) return - const newData = await DailyReportService.getOrGenerate(idWell, date.toISOString()) + const newData = await DailyReportService.getOrGenerate(idWell, date.format('YYYY-MM-DD') + 'Z') + if (checkIsDateBusy(moment(newData.reportDate))) + throw 'Рапорт на данную дату уже существует' setFields(newData) }, setIsLoading, 'Не удалось загрузить автозаполняемые данные для нового рапорта', 'Получение автозаполняемых данных суточного рапорта', - ), [idWell, data, setFields]) + ), [idWell, data, setFields, checkIsDateBusy]) return ( { onChange={onFormChange} > - + @@ -201,7 +215,7 @@ export const ReportEditor = memo(({ visible, data, onDone, onCancel }) => { bordered size={'small'} columns={table1Columns} - dataSource={[{ key: '', disabled: !!data, onChange: onDateChange }]} + dataSource={[{ key: '', disabled: !!data, onChange: onDateChange, checkIsDateBusy }]} pagination={false} /> diff --git a/src/pages/Reports/DailyReport/index.jsx b/src/pages/Reports/DailyReport/index.jsx index ae6379e..b9129a7 100644 --- a/src/pages/Reports/DailyReport/index.jsx +++ b/src/pages/Reports/DailyReport/index.jsx @@ -1,11 +1,11 @@ import moment from 'moment' -import { Button, DatePicker } from 'antd' +import { Button } from 'antd' import { FileExcelOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons' import { memo, useCallback, useContext, useEffect, useMemo, useState } from 'react' import { IdWellContext } from '@asb/context' import LoaderPortal from '@components/LoaderPortal' -import { Table, makeDateColumn, makeColumn } from '@components/Table' +import { DateRangeWrapper, Table, makeDateColumn, makeColumn } from '@components/Table' import { download, invokeWebApiWrapperAsync } from '@components/factory' import { DailyReportService } from '@api' import { arrayOrDefault } from '@utils' @@ -33,8 +33,10 @@ export const DailyReport = memo(() => { useEffect(updateTable, [updateTable]) + const checkIsDateBusy = useCallback((current) => current.isAfter(moment(), 'day') || data.some((row) => moment(row.reportDate).isSame(current, 'day')), [data]) + const columns = useMemo(() => [ - makeDateColumn('Дата', 'reportDate', undefined, undefined, { width: 300 }), + makeDateColumn('Дата', 'reportDate', undefined, 'YYYY.MM.DD', { width: 300 }), makeColumn('', '', { width: 200, render: (_, report) => ( <>