2021-07-29 17:17:28 +05:00
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
import {Table, Input, Form, Popconfirm, Typography } from 'antd'
|
2021-07-28 17:59:16 +05:00
|
|
|
|
|
2021-07-29 17:17:28 +05:00
|
|
|
|
const originData = [
|
2021-07-28 17:59:16 +05:00
|
|
|
|
{
|
2021-07-29 17:17:28 +05:00
|
|
|
|
key: '1', depth: '', zenithAngle: '', magneticAzimuth: '', trueAzimuth: '', directAzimuth: '', verticalDepth: '', absoluteMark: '', localNorthOffset: '',
|
|
|
|
|
localEastOffset: '', outFallOffset: '', offsetAzimuth: '', areaIntensity: '', offsetStopAngle: '', zenithIntensity: '', comment: '', depthPlanFactDifference: '',
|
|
|
|
|
distancePlanFactDifference: ''
|
2021-07-28 17:59:16 +05:00
|
|
|
|
}
|
2021-07-29 17:17:28 +05:00
|
|
|
|
]
|
2021-07-28 17:59:16 +05:00
|
|
|
|
|
2021-07-29 17:17:28 +05:00
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
};
|
2021-07-28 17:59:16 +05:00
|
|
|
|
|
|
|
|
|
export function Nnb() {
|
2021-07-29 17:17:28 +05:00
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
const [data, setData] = useState(originData);
|
|
|
|
|
const [editingKey, setEditingKey] = useState('');
|
|
|
|
|
|
|
|
|
|
const isEditing = (row) => row.key === editingKey;
|
|
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
|
{
|
|
|
|
|
title: 'Глубина по стволу, м',
|
|
|
|
|
key: 'depth',
|
|
|
|
|
dataIndex: 'depth',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Зенитный угол, град',
|
|
|
|
|
key: 'zenithAngle',
|
|
|
|
|
dataIndex: 'zenithAngle',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Азимут магнитный, град',
|
|
|
|
|
key: 'magneticAzimuth',
|
|
|
|
|
dataIndex: 'magneticAzimuth',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Азимут истинный, град',
|
|
|
|
|
key: 'trueAzimuth',
|
|
|
|
|
dataIndex: 'trueAzimuth',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Азимут дирекц., град',
|
|
|
|
|
key: 'directAzimuth',
|
|
|
|
|
dataIndex: 'directAzimuth',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Глубина по вертикали, м',
|
|
|
|
|
key: 'verticalDepth',
|
|
|
|
|
dataIndex: 'verticalDepth',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Абсолютная отметка, м',
|
|
|
|
|
key: 'absoluteMark',
|
|
|
|
|
dataIndex: 'absoluteMark',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Лок. смещение к северу, м',
|
|
|
|
|
key: 'localNorthOffset',
|
|
|
|
|
dataIndex: 'localNorthOffset',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Лок. смещение к востоку, м',
|
|
|
|
|
key: 'localEastOffset',
|
|
|
|
|
dataIndex: 'localEastOffset',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Отклонение от устья, м',
|
|
|
|
|
key: 'outFallOffset',
|
|
|
|
|
dataIndex: 'outFallOffset',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Азимут смещения, град',
|
|
|
|
|
key: 'offsetAzimuth',
|
|
|
|
|
dataIndex: 'offsetAzimuth',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Пространст. интенсивность, град/10 м',
|
|
|
|
|
key: 'areaIntensity',
|
|
|
|
|
dataIndex: 'areaIntensity',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Угол установки отклон., град',
|
|
|
|
|
key: 'offsetStopAngle',
|
|
|
|
|
dataIndex: 'offsetStopAngle',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Интенсив. по зениту, град/10 м',
|
|
|
|
|
key: 'zenithIntensity',
|
|
|
|
|
dataIndex: 'zenithIntensity',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Комментарий',
|
|
|
|
|
key: 'comment',
|
|
|
|
|
dataIndex: 'comment',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Разница вертикальных глубин между ХХХ (план) и ХХХ (факт)',
|
|
|
|
|
key: 'depthPlanFactDifference',
|
|
|
|
|
dataIndex: 'depthPlanFactDifference',
|
|
|
|
|
align: 'center',
|
|
|
|
|
editable: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Расстояние в пространстве между ХХХ (план) и ХХХ (факт)',
|
|
|
|
|
key: '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 (key) => {
|
|
|
|
|
try {
|
|
|
|
|
const row = await form.validateFields();
|
|
|
|
|
const newData = [...data];
|
|
|
|
|
const index = newData.findIndex((item) => key === item.key);
|
|
|
|
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
const item = newData[index];
|
|
|
|
|
newData.splice(index, 1, { ...item, ...row });
|
|
|
|
|
setData(newData);
|
|
|
|
|
setEditingKey('');
|
|
|
|
|
} else {
|
|
|
|
|
newData.push(row);
|
|
|
|
|
setData(newData);
|
|
|
|
|
setEditingKey('');
|
|
|
|
|
}
|
|
|
|
|
} catch (errInfo) {
|
|
|
|
|
console.log('Validate Failed:', errInfo);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-28 17:59:16 +05:00
|
|
|
|
return (<>
|
2021-07-29 17:17:28 +05:00
|
|
|
|
<Form form={form} component={false}>
|
|
|
|
|
<Table
|
|
|
|
|
components={{
|
|
|
|
|
body: {
|
|
|
|
|
cell: EditableCell,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
columns={mergedColumns}
|
|
|
|
|
dataSource={data}
|
|
|
|
|
size={'small'}
|
|
|
|
|
bordered={true}
|
|
|
|
|
pagination={false}
|
|
|
|
|
/>
|
|
|
|
|
</Form>
|
2021-07-28 17:59:16 +05:00
|
|
|
|
</>)
|
|
|
|
|
}
|