From 5ab2bf237f737c91d8d698b05ee3a25f3afac646 Mon Sep 17 00:00:00 2001 From: goodmice Date: Tue, 2 Aug 2022 15:26:06 +0500 Subject: [PATCH] =?UTF-8?q?=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=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D1=8B=20=D1=81=D1=83=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=80=D0=B0=D0=BF=D0=BE=D1=80=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reports/DailyReport/ReportEditor.jsx | 328 +++++++----------- src/pages/Reports/DailyReport/index.jsx | 2 +- 2 files changed, 122 insertions(+), 208 deletions(-) diff --git a/src/pages/Reports/DailyReport/ReportEditor.jsx b/src/pages/Reports/DailyReport/ReportEditor.jsx index 8b56887..f4b6cbe 100644 --- a/src/pages/Reports/DailyReport/ReportEditor.jsx +++ b/src/pages/Reports/DailyReport/ReportEditor.jsx @@ -1,4 +1,4 @@ -import { DatePicker, Descriptions, Divider, Form, Input, InputNumber, Modal, Select, Space, Table } from 'antd' +import { DatePicker, Descriptions, Form, Input, InputNumber, Modal, Table, Tabs } from 'antd' import { memo, useCallback, useEffect, useState } from 'react' import moment from 'moment' @@ -7,15 +7,11 @@ import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { makeColumn, makeGroupColumn } from '@components/Table' import { DailyReportService } from '@api' -import { Tabs } from 'antd' const { Item: RawItem } = Form const { Summary } = Table const { TabPane } = Tabs -const onChange = (key) => { - console.log(key) -} const Item = memo(({ style, ...other }) => ) const table1Columns = [ @@ -54,13 +50,30 @@ const table1Columns = [ }), ]), ] + const names = [ - ['head', ['wellName', 'clusterName','contractor','countLaunchesMSE','customer','bottomholeDepth','verticalDepth','firstDriller','secondDriller','zenithAngle','azimuthAngle','penetrationSAUB','penetrationSpinMaster','penetrationTorkMaster','secondDriller','wellDepthIntervalFinishDate','wellDepthIntervalStartDate','workTimeSAUB','workTimeSpinMaster','workTimeTorkMaster','reportDate']], - ['bha', ['bhaDescription','extensionDrillingOneBegin','extensionDrillingOneFinish','sluiceBegin','sluiceFinish','climbBegin','climbFinish','descentBegin','descentFinish','extensionDrillingTwoBegin','extensionDrillingTwoFinish']], - ['noDrilling', ['actualTimeBarrelPreparation','actualTimeExtension','standardTimeBarrelPreparation','standardTimeExtension']], - ['timeBalance', ['drilling','flushing','building','elaboration','extension','repair','knbk','spo','pzr','pzr','pgr','gis','ozc','engineeringWorks','takingMeasure','cementing','simple','npv']], - ['saub', ['avgDiffDropRotor','avgDiffPressureSlide','declinesReasonsROP','deviationFromTVD','drillingTimeInRotor','declinesReasonsROP','extensionsCount','extensionsCount','penetrationInRotor','penetrationInSlide','rotorDrillingModes','rotorSlidePercent','reductionTimeDrilling','increaseSpeedSection','increaseSpeedDay','sectionDrillingTimeTotal','sectionPenetrationTotal','sectionROPPlan','slideDrillingModes','mspSection']], - ['sign', ['drillingMaster','supervisor']], + ['head', [ + 'wellName', 'clusterName', 'contractor', 'countLaunchesMSE', 'customer', 'bottomholeDepth', 'verticalDepth', + 'firstDriller', 'secondDriller', 'zenithAngle', 'azimuthAngle', 'penetrationSAUB', 'penetrationSpinMaster', + 'penetrationTorkMaster', 'secondDriller', 'wellDepthIntervalFinishDate', 'wellDepthIntervalStartDate', + 'workTimeSAUB', 'workTimeSpinMaster', 'workTimeTorkMaster', 'reportDate', + ]], + ['bha', [ + 'bhaDescription', 'extensionDrillingOneBegin', 'extensionDrillingOneFinish', 'sluiceBegin', 'sluiceFinish', + 'climbBegin', 'climbFinish', 'descentBegin', 'descentFinish', 'extensionDrillingTwoBegin', 'extensionDrillingTwoFinish', + ]], + ['noDrilling', ['actualTimeBarrelPreparation', 'actualTimeExtension', 'standardTimeBarrelPreparation', 'standardTimeExtension']], + ['timeBalance', [ + 'drilling', 'flushing', 'building', 'elaboration', 'extension', 'repair', 'knbk', 'spo', 'pzr', 'pzr', 'pgr', 'gis', + 'ozc', 'engineeringWorks', 'takingMeasure', 'cementing', 'simple', 'npv', + ]], + ['saub', [ + 'avgDiffDropRotor', 'avgDiffPressureSlide', 'declinesReasonsROP', 'deviationFromTVD', 'drillingTimeInRotor', + 'declinesReasonsROP', 'extensionsCount', 'extensionsCount', 'penetrationInRotor', 'penetrationInSlide', + 'rotorDrillingModes', 'rotorSlidePercent', 'reductionTimeDrilling', 'increaseSpeedSection', 'increaseSpeedDay', + 'sectionDrillingTimeTotal', 'sectionPenetrationTotal', 'sectionROPPlan', 'slideDrillingModes', 'mspSection' + ]], + ['sign', ['drillingMaster', 'supervisor']], ] const cellData = { @@ -233,6 +246,44 @@ const table2Summary = () => ( ) +const makeItem = (name, label) => ({ name, label }) +const renderDescriptions = (items) => items.map(({ name, label }) => ( + + + + + +)) + +const tab1Items = [ + makeItem('wellName', 'Название скважины'), + makeItem('clusterName', 'Название куста'), + makeItem('customer', 'Заказчик'), + makeItem('contractor', 'Подрядчик'), +] + +const tab4Items = [ + makeItem('drilling', 'Бурение'), + makeItem('sectionDrillingTimeTotal', 'Время бурения за секцию'), + makeItem('flushing', 'Промывка'), + makeItem('building', 'Наращивание'), + makeItem('elaboration', 'Проработка'), + makeItem('extension', 'Расширка'), + makeItem('repair', 'Ремонт'), + makeItem('knbk', 'КНБК'), + makeItem('spo', 'СПО'), + makeItem('pzr', 'ПЗР'), + makeItem('pvo', 'ПВО'), + makeItem('pgr', 'ПГР'), + makeItem('gis', 'ГИС'), + makeItem('ozc', 'ОЗЦ'), + makeItem('engineeringWorks', 'Тех. работы'), + makeItem('takingMeasure', 'Снятие замера'), + makeItem('cementing', 'Цементирование'), + makeItem('simple', 'Простой'), + makeItem('npv', 'НПВ'), +] + export const ReportEditor = memo(({ visible, data, onDone, onCancel, checkIsDateBusy }) => { const [form] = Form.useForm() const [isInvalid, setIsInvalid] = useState(false) @@ -240,69 +291,52 @@ export const ReportEditor = memo(({ visible, data, onDone, onCancel, checkIsDate const idWell = useIdWell() - const setFields = useCallback( - (data) => - form.setFieldsValue( - data - ? { - ...data.head, - ...data.bha, - ...data.noDrilling, - ...data.timeBalance, - ...data.saub, - ...data.sign, - reportDate: moment.utc(data.head.reportDate).local(), - } - : {} - ), - [form] - ) + const setFields = useCallback((data) => + form.setFieldsValue(data ? { + ...data.head, + ...data.bha, + ...data.noDrilling, + ...data.timeBalance, + ...data.saub, + ...data.sign, + reportDate: moment.utc(data.head.reportDate).local(), + } : {}) + , [form]) useEffect(() => setFields(data), [data, setFields]) - const onFormChange = useCallback( - async () => + const onFormChange = useCallback(async () => await form .validateFields() .then(() => setIsInvalid(false)) - .catch(() => setIsInvalid(true)), - [form] - ) + .catch(() => setIsInvalid(true)) + , [form]) - const onFormFinish = useCallback( - (formData) => - invokeWebApiWrapperAsync( - async () => { - console.log(formData) - const payload = Object.fromEntries(names.map(([head, names]) => [head, Object.fromEntries(names.map((name) => [name, formdata[name]]))])) - if (data) await DailyReportService.update(idWell, data.head.reportDate, payload) - else await DailyReportService.add(idWell, payload) - onDone?.(formData) - form.resetFields() - }, - setIsLoading, - 'Не удалось сохранить суточный рапорт', - 'Сохранение суточного рапорта' - ), - [data, onDone, idWell, form] - ) + const onFormFinish = useCallback((formData) => invokeWebApiWrapperAsync( + async () => { + const payload = Object.fromEntries(names.map(([head, names]) => [head, Object.fromEntries(names.map((name) => [name, formData[name]]))])) + if (data) await DailyReportService.update(idWell, data.head.reportDate, payload) + else await DailyReportService.add(idWell, payload) + onDone?.(formData) + form.resetFields() + }, + setIsLoading, + 'Не удалось сохранить суточный рапорт', + 'Сохранение суточного рапорта' + ), [data, onDone, idWell, form]) - const onDateChange = useCallback( - (date) => - invokeWebApiWrapperAsync( - async () => { - if (data) return - const newData = await DailyReportService.getOrGenerate(idWell, date.format('YYYY-MM-DD') + 'Z') - if (checkIsDateBusy(moment(newData.reportDate))) - throw new Error('Рапорт на данную дату уже существует') - setFields(newData) - }, - setIsLoading, - (e) => `Не удалось загрузить автозаполняемые данные для нового рапорта: ${e}`, - 'Получение автозаполняемых данных суточного рапорта' - ), - [idWell, data, setFields, checkIsDateBusy] - ) + const onDateChange = useCallback((date) => invokeWebApiWrapperAsync( + async () => { + if (data) return + const newData = await DailyReportService.getOrGenerate(idWell, date.format('YYYY-MM-DD') + 'Z') + if (checkIsDateBusy(moment(newData.reportDate))) + throw new Error('Рапорт на данную дату уже существует') + setFields(newData) + }, + setIsLoading, + (e) => `Не удалось загрузить автозаполняемые данные для нового рапорта: ${e}`, + 'Получение автозаполняемых данных суточного рапорта' + ), [idWell, data, setFields, checkIsDateBusy]) return ( - Суточная сводка бурения скважины № {data?.wellName} куст № {data?.clusterName} - - ) : ( - <>Новая cуточная сводка бурения скважины - ) - } + title={data ? ( + <>Суточная сводка бурения скважины № {data?.wellName} куст № {data?.clusterName} + ) : ( + <>Новая cуточная сводка бурения скважины + )} onOk={form.submit} okButtonProps={{ disabled: isInvalid, @@ -336,29 +366,10 @@ export const ReportEditor = memo(({ visible, data, onDone, onCancel, checkIsDate disabledDate={checkIsDateBusy} /> - - + + - - - - - - - - - - - - - - - - - - - - + {renderDescriptions(tab1Items)} - + - + @@ -390,7 +401,7 @@ export const ReportEditor = memo(({ visible, data, onDone, onCancel, checkIsDate pagination={false} /> - +
- +
- + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {renderDescriptions(tab4Items)} - - - +
- + @@ -619,14 +534,13 @@ export const ReportEditor = memo(({ visible, data, onDone, onCancel, checkIsDate - - + + - - - + + - + diff --git a/src/pages/Reports/DailyReport/index.jsx b/src/pages/Reports/DailyReport/index.jsx index 1ff339e..d160ded 100644 --- a/src/pages/Reports/DailyReport/index.jsx +++ b/src/pages/Reports/DailyReport/index.jsx @@ -24,7 +24,7 @@ const DailyReport = memo(() => { const updateTable = useCallback(() => invokeWebApiWrapperAsync( async () => { const data = arrayOrDefault(await DailyReportService.getList(idWell)) - setData(data) + setData(data.map((row) => ({ ...row, reportDate: row.head.reportDate }))) }, setIsLoading, 'Не удалось загрузить список суточных рапортов',