forked from ddrilling/asb_cloud_front
190 lines
7.5 KiB
JavaScript
190 lines
7.5 KiB
JavaScript
import { useState } from 'react'
|
||
import { useParams } from "react-router-dom";
|
||
import {Table, Input, Form, Popconfirm, Typography } from 'antd'
|
||
import { makeColumn } from '../factory'
|
||
import { NnbDataService } from '../../services/api/services/NnbDataService';
|
||
|
||
const originData = [
|
||
{
|
||
key: '11', depth: '', zenithAngle: '', magneticAzimuth: '', trueAzimuth: '', directAzimuth: '', verticalDepth: '', absoluteMark: '', localNorthOffset: '',
|
||
localEastOffset: '', outFallOffset: '', offsetAzimuth: '', areaIntensity: '', offsetStopAngle: '', zenithIntensity: '', comment: '', depthPlanFactDifference: '',
|
||
distancePlanFactDifference: ''
|
||
}
|
||
]
|
||
|
||
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: '',
|
||
pattern: '(-?[1-9]+\d*([.,]\d+)?)$|^(-?0[.,]\d*[1-9]+)$|^0$|^0.0$'
|
||
},
|
||
]}
|
||
>
|
||
<Input size="small" />
|
||
</Form.Item>
|
||
) : (
|
||
children
|
||
)}
|
||
</div>
|
||
</td>
|
||
);
|
||
};
|
||
|
||
export function Nnb() {
|
||
let {id} = useParams()
|
||
|
||
const [form] = Form.useForm();
|
||
const [editingKey, setEditingKey] = useState('');
|
||
const [data, setData] = useState(originData)
|
||
const [isUpdatingData, setIsUpdatingData] = useState(false)
|
||
|
||
const [loader, setLoader] = 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>
|
||
<a
|
||
href="javascript:;"
|
||
onClick={() => save(row.key)}
|
||
style={{ marginRight: 8 }}
|
||
>
|
||
Сохранить
|
||
</a>
|
||
<Popconfirm style={{width: '100px'}} title={<span>Отменить<br />редактирование?</span>} onConfirm={cancel}>
|
||
<a>Отменить</a>
|
||
</Popconfirm>
|
||
</span>
|
||
) : (
|
||
<Typography.Link disabled={editingKey !== ''} onClick={() => edit(row)}>
|
||
Редактировать
|
||
</Typography.Link>
|
||
);
|
||
},
|
||
}
|
||
];
|
||
|
||
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) => {
|
||
// TODO: Почему-то в formData из всей формы попадает только поле key. Остальное пришлось записывать в params ниже
|
||
// В аналогичной модалке DrillingFluid все ок, все поля формы попадают в formData.
|
||
const params = {
|
||
key: form.getFieldValue('key'),
|
||
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 {
|
||
setLoader(true)
|
||
await NnbDataService.put(`${id}`, 11, params)
|
||
|
||
setLoader(false)
|
||
|
||
setEditingKey('')
|
||
} catch (errInfo) {
|
||
console.log('Validate Failed:', errInfo);
|
||
}
|
||
};
|
||
|
||
|
||
return (<>
|
||
<Form form={form} component={false} onFinish={save}>
|
||
<Table
|
||
components={{
|
||
body: {
|
||
cell: EditableCell,
|
||
},
|
||
}}
|
||
columns={mergedColumns}
|
||
dataSource={data}
|
||
size={'small'}
|
||
bordered={true}
|
||
pagination={false}
|
||
/>
|
||
</Form>
|
||
</>)
|
||
} |