forked from ddrilling/asb_cloud_front
205 lines
7.5 KiB
JavaScript
205 lines
7.5 KiB
JavaScript
import { useState, useEffect } from 'react'
|
||
import { useParams } from "react-router-dom";
|
||
import {Table, InputNumber, Form, Popconfirm, Typography, Button } from 'antd'
|
||
import LoaderPortal from '../LoaderPortal'
|
||
import { makeColumn } from '../Table'
|
||
import { NnbDataService } from '../../services/api/services/NnbDataService';
|
||
import { notify } from "../factory"
|
||
|
||
|
||
const EditableCell = ({
|
||
editing,
|
||
dataIndex,
|
||
title,
|
||
inputType,
|
||
record,
|
||
index,
|
||
children,
|
||
...restProps
|
||
}) => {
|
||
return (
|
||
<td {...restProps} style={{paddingLeft: 2, paddingRight: 2}}>
|
||
<div style={{width: '100%', display: 'flex', justifyContent: 'center'}}>
|
||
{editing ? (
|
||
<Form.Item
|
||
name={dataIndex}
|
||
style={{ margin: 0 }}
|
||
rules={[
|
||
{
|
||
required: true,
|
||
message: ''
|
||
},
|
||
]}
|
||
>
|
||
<InputNumber size="small" style={{width:"auto"}} />
|
||
</Form.Item>
|
||
) : (
|
||
children
|
||
)}
|
||
</div>
|
||
</td>
|
||
);
|
||
};
|
||
|
||
export function Nnb() {
|
||
let {id} = useParams()
|
||
|
||
const [form] = Form.useForm();
|
||
const [editingKey, setEditingKey] = useState('');
|
||
const [data, setData] = useState({})
|
||
const [isUpdatingData, setIsUpdatingData] = useState(false)
|
||
const [showLoader, setShowLoader] = useState(false)
|
||
|
||
const isEditing = (row) => row.key === editingKey;
|
||
|
||
const columns = [
|
||
makeColumn('Глубина по стволу, м', 'depth', { dataIndex: 'depth', align: 'center', editable: true}),
|
||
makeColumn('Зенитный угол, град', 'zenithAngle', { dataIndex: 'zenithAngle', align: 'center', editable: true}),
|
||
makeColumn('Азимут магнитный, град', 'magneticAzimuth', { dataIndex: 'magneticAzimuth', align: 'center', editable: true}),
|
||
makeColumn('Азимут истинный, град', 'trueAzimuth', { dataIndex: 'trueAzimuth', align: 'center', editable: true}),
|
||
makeColumn('Азимут дирекц., град', 'directAzimuth', { dataIndex: 'directAzimuth', align: 'center', editable: true}),
|
||
makeColumn('Глубина по вертикали, м', 'verticalDepth', { dataIndex: 'verticalDepth', align: 'center', editable: true}),
|
||
makeColumn('Абсолютная отметка, м', 'absoluteMark', { dataIndex: 'absoluteMark', align: 'center', editable: true}),
|
||
makeColumn('Лок. смещение к северу, м', 'localNorthOffset', { dataIndex: 'localNorthOffset', align: 'center', editable: true}),
|
||
makeColumn('Лок. смещение к востоку, м', 'localEastOffset', { dataIndex: 'localEastOffset', align: 'center', editable: true}),
|
||
makeColumn('Отклонение от устья, м', 'outFallOffset', { dataIndex: 'outFallOffset', align: 'center', editable: true}),
|
||
makeColumn('Азимут смещения, град', 'offsetAzimuth', { dataIndex: 'offsetAzimuth', align: 'center', editable: true}),
|
||
makeColumn('Пространст. интенсивность, град/10 м', 'areaIntensity', { dataIndex: 'areaIntensity', align: 'center', editable: true}),
|
||
makeColumn('Угол установки отклон., град', 'offsetStopAngle', { dataIndex: 'offsetStopAngle', align: 'center', editable: true}),
|
||
makeColumn('Интенсив. по зениту, град/10 м', 'zenithIntensity', { dataIndex: 'zenithIntensity', align: 'center', editable: true}),
|
||
makeColumn('Комментарий', 'comment', { dataIndex: 'comment', align: 'comment', editable: true}),
|
||
makeColumn('Разница вертикальных глубин между ХХХ (план) и ХХХ (факт)', 'depthPlanFactDifference', { dataIndex: 'depthPlanFactDifference', align: 'center', editable: true}),
|
||
makeColumn('Расстояние в пространстве между ХХХ (план) и ХХХ (факт)', 'distancePlanFactDifference', { dataIndex: 'distancePlanFactDifference', align: 'center', editable: true}),
|
||
{
|
||
title: 'Действие',
|
||
dataIndex: 'action',
|
||
align: 'center',
|
||
width: 150,
|
||
className: 'small-font',
|
||
render: (_, row) => {
|
||
const editable = isEditing(row);
|
||
return editable ? (
|
||
<span>
|
||
<Button
|
||
onClick={() => save(row.key)}
|
||
style={{ marginRight: 8 }}
|
||
>
|
||
Сохранить
|
||
</Button>
|
||
<Popconfirm style={{width: '100px'}} title={<span>Отменить<br />редактирование?</span>} onConfirm={cancel}>
|
||
<Button>Отменить</Button>
|
||
</Popconfirm>
|
||
</span>
|
||
) : (
|
||
<Typography.Link disabled={editingKey !== ''} onClick={() => edit(row)}>
|
||
Редактировать
|
||
</Typography.Link>
|
||
);
|
||
},
|
||
}
|
||
];
|
||
|
||
useEffect(() => {
|
||
const update = async () => {
|
||
setShowLoader(true)
|
||
|
||
try {
|
||
let response = await NnbDataService.get(id,11)
|
||
response.key = 11
|
||
setData(response)
|
||
}
|
||
catch (ex) {
|
||
notify(`Не удалось загрузить данные ННБ по скважине "${id}"`, 'error')
|
||
console.log(ex)
|
||
}
|
||
|
||
setIsUpdatingData(false)
|
||
setShowLoader(false)
|
||
}
|
||
update()
|
||
}, [id, isUpdatingData])
|
||
|
||
const mergedColumns = columns.map((col) => {
|
||
if (!col.editable) {
|
||
return col;
|
||
}
|
||
|
||
return {
|
||
...col,
|
||
onCell: (row) => ({
|
||
row,
|
||
dataIndex: col.dataIndex,
|
||
title: col.title,
|
||
editing: isEditing(row),
|
||
}),
|
||
};
|
||
});
|
||
|
||
const edit = (row) => {
|
||
form.setFieldsValue({
|
||
...row,
|
||
});
|
||
setEditingKey(row.key);
|
||
};
|
||
|
||
const cancel = () => {
|
||
setEditingKey('');
|
||
};
|
||
|
||
const save = async (formData) => {
|
||
const params = {
|
||
key: 11,
|
||
depth: form.getFieldValue('depth'),
|
||
zenithAngle: form.getFieldValue('zenithAngle'),
|
||
magneticAzimuth: form.getFieldValue('magneticAzimuth'),
|
||
trueAzimuth: form.getFieldValue('trueAzimuth'),
|
||
directAzimuth: form.getFieldValue('directAzimuth'),
|
||
verticalDepth: form.getFieldValue('verticalDepth'),
|
||
absoluteMark: form.getFieldValue('absoluteMark'),
|
||
localNorthOffset: form.getFieldValue('localNorthOffset'),
|
||
localEastOffset: form.getFieldValue('localEastOffset'),
|
||
outFallOffset: form.getFieldValue('outFallOffset'),
|
||
offsetAzimuth: form.getFieldValue('offsetAzimuth'),
|
||
areaIntensity: form.getFieldValue('areaIntensity'),
|
||
offsetStopAngle: form.getFieldValue('offsetStopAngle'),
|
||
zenithIntensity: form.getFieldValue('zenithIntensity'),
|
||
comment: form.getFieldValue('comment'),
|
||
depthPlanFactDifference: form.getFieldValue('depthPlanFactDifference'),
|
||
distancePlanFactDifference: form.getFieldValue('distancePlanFactDifference')
|
||
}
|
||
|
||
try {
|
||
setShowLoader(true)
|
||
await NnbDataService.put(`${id}`, 11, params)
|
||
|
||
setIsUpdatingData(true)
|
||
setShowLoader(false)
|
||
|
||
setEditingKey('')
|
||
} catch (errInfo) {
|
||
console.log('Validate Failed:', errInfo);
|
||
}
|
||
};
|
||
|
||
|
||
return (<LoaderPortal show={showLoader}>
|
||
<Form form={form} component={false} onFinish={save}>
|
||
<Table
|
||
components={{
|
||
body: {
|
||
cell: EditableCell,
|
||
},
|
||
}}
|
||
columns={mergedColumns}
|
||
dataSource={[data]}
|
||
size={'small'}
|
||
bordered={true}
|
||
pagination={false}
|
||
/>
|
||
</Form>
|
||
<div> </div>
|
||
<p style={{textAlign: "right"}}>
|
||
Дата последнего обновления: <b>{new Date(data?.lastUpdate).toLocaleString()}</b>
|
||
</p>
|
||
</LoaderPortal>)
|
||
} |