2021-10-12 11:10:33 +05:00
|
|
|
|
import { useState, useEffect } from 'react'
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
makeColumn,
|
2021-10-12 16:48:17 +05:00
|
|
|
|
makeNumericAvgRange
|
2021-10-12 11:10:33 +05:00
|
|
|
|
} from '../../components/Table'
|
|
|
|
|
import LoaderPortal from '../../components/LoaderPortal'
|
|
|
|
|
import { invokeWebApiWrapperAsync } from '../../components/factory'
|
|
|
|
|
import { EditableTable, SelectFromDictionary } from '../../components/Table'
|
2021-10-12 15:04:02 +05:00
|
|
|
|
import { DrillParamsService } from '../../services/api'
|
2021-10-12 11:10:33 +05:00
|
|
|
|
import { dictionarySectionType, getByKeyOrReturnKey } from './dictionary'
|
|
|
|
|
|
2021-10-15 16:02:35 +05:00
|
|
|
|
export const columns = [
|
|
|
|
|
makeColumn('Конструкция секции','idWellSectionType', {
|
|
|
|
|
editable:true,
|
|
|
|
|
input:<SelectFromDictionary dictionary={dictionarySectionType}/>,
|
|
|
|
|
width:160,
|
|
|
|
|
render:(_, record)=>getByKeyOrReturnKey(dictionarySectionType, record.idWellSectionType)
|
|
|
|
|
}),
|
|
|
|
|
// makeNumericStartEnd('Глубина', 'depth'),
|
2021-10-19 14:40:07 +05:00
|
|
|
|
makeNumericAvgRange('Нагрузка', 'axialLoad', 1),
|
|
|
|
|
makeNumericAvgRange('Давление', 'pressure', 1),
|
|
|
|
|
makeNumericAvgRange('Момент на ВСП', 'rotorTorque', 1),
|
|
|
|
|
makeNumericAvgRange('Обороты на ВСП', 'rotorSpeed', 1),
|
|
|
|
|
makeNumericAvgRange('Расход', 'flow', 1)
|
2021-10-15 16:02:35 +05:00
|
|
|
|
]
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-10-12 15:04:02 +05:00
|
|
|
|
export const WellDrillParams = ({idWell}) => {
|
2021-10-12 11:10:33 +05:00
|
|
|
|
const [params, setParams] = useState([])
|
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
|
|
|
|
|
2021-10-12 16:48:17 +05:00
|
|
|
|
const updateParams = () => invokeWebApiWrapperAsync(
|
2021-10-12 11:10:33 +05:00
|
|
|
|
async () => {
|
2021-10-12 16:48:17 +05:00
|
|
|
|
const params = await DrillParamsService.getAll(idWell)
|
2021-10-18 11:49:53 +05:00
|
|
|
|
setParams(Array.isArray(params) ? params : [])
|
2021-10-12 11:10:33 +05:00
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
'Не удалось загрузить список режимов бурения скважины'
|
|
|
|
|
)
|
|
|
|
|
|
2021-10-12 16:48:17 +05:00
|
|
|
|
useEffect(updateParams, [idWell])
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
|
|
|
|
const onAdd = async (param) => {
|
2021-10-12 16:48:17 +05:00
|
|
|
|
param.idWell = idWell
|
2021-10-14 16:56:29 +05:00
|
|
|
|
await DrillParamsService.insert(idWell, param)
|
2021-10-12 16:48:17 +05:00
|
|
|
|
updateParams()
|
2021-10-12 11:10:33 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onEdit = async (param) => {
|
|
|
|
|
if (!param.id) return
|
2021-10-12 16:48:17 +05:00
|
|
|
|
param.idWell = idWell
|
2021-10-14 16:56:29 +05:00
|
|
|
|
await DrillParamsService.update(idWell, param.id, param)
|
2021-10-12 16:48:17 +05:00
|
|
|
|
updateParams()
|
2021-10-12 11:10:33 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onDelete = async (param) => {
|
|
|
|
|
if (!param.id) return
|
2021-10-12 15:04:02 +05:00
|
|
|
|
await DrillParamsService.delete(idWell, param.id)
|
2021-10-12 16:48:17 +05:00
|
|
|
|
updateParams()
|
2021-10-12 11:10:33 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<LoaderPortal show={showLoader}>
|
|
|
|
|
<EditableTable
|
|
|
|
|
size={'small'}
|
|
|
|
|
bordered
|
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={params}
|
2021-10-12 16:48:17 +05:00
|
|
|
|
onRowAdd={onAdd}
|
2021-10-12 11:10:33 +05:00
|
|
|
|
onRowEdit={onEdit}
|
|
|
|
|
onRowDelete={onDelete}
|
2021-10-12 16:51:25 +05:00
|
|
|
|
pagination={false}
|
2021-10-12 11:10:33 +05:00
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
|
|
|
|
}
|