2021-12-29 11:11:49 +05:00
|
|
|
|
import { useState, useEffect, useCallback } from 'react'
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-29 11:11:49 +05:00
|
|
|
|
import { DrillParamsService, WellOperationService } from '../../services/api'
|
2021-10-12 11:10:33 +05:00
|
|
|
|
import LoaderPortal from '../../components/LoaderPortal'
|
|
|
|
|
import { invokeWebApiWrapperAsync } from '../../components/factory'
|
2021-12-29 11:11:49 +05:00
|
|
|
|
import {
|
|
|
|
|
EditableTable,
|
|
|
|
|
makeSelectColumn,
|
|
|
|
|
makeActionHandler,
|
|
|
|
|
makeNumericAvgRange,
|
|
|
|
|
} from '../../components/Table'
|
|
|
|
|
import { arrayOrDefault } from '../../utils'
|
2021-12-27 15:18:20 +05:00
|
|
|
|
|
2021-12-29 11:11:49 +05:00
|
|
|
|
export const getColumns = async (idWell) => {
|
|
|
|
|
let sectionTypes = await WellOperationService.getSectionTypes(idWell)
|
|
|
|
|
sectionTypes = Object.keys(sectionTypes).map((id) => ({
|
|
|
|
|
label: sectionTypes[id],
|
|
|
|
|
value: id,
|
|
|
|
|
}))
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-29 11:11:49 +05:00
|
|
|
|
return [
|
|
|
|
|
makeSelectColumn('Конструкция секции','idWellSectionType', sectionTypes, null, {
|
|
|
|
|
editable: true,
|
|
|
|
|
width: 160,
|
|
|
|
|
}),
|
|
|
|
|
makeNumericAvgRange('Нагрузка, т', 'axialLoad', 1),
|
|
|
|
|
makeNumericAvgRange('Давление, атм', 'pressure', 1),
|
|
|
|
|
makeNumericAvgRange('Момент на ВСП, кН·м', 'rotorTorque', 1),
|
|
|
|
|
makeNumericAvgRange('Обороты на ВСП, об/мин', 'rotorSpeed', 1),
|
|
|
|
|
makeNumericAvgRange('Расход, л/с', 'flow', 1),
|
|
|
|
|
]
|
|
|
|
|
}
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-27 15:18:20 +05:00
|
|
|
|
export const WellDrillParams = ({ idWell }) => {
|
2021-10-12 11:10:33 +05:00
|
|
|
|
const [params, setParams] = useState([])
|
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
2021-12-29 11:11:49 +05:00
|
|
|
|
const [columns, setColumns] = useState([])
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-29 11:11:49 +05:00
|
|
|
|
const updateParams = useCallback(async () => await invokeWebApiWrapperAsync(
|
2021-10-12 11:10:33 +05:00
|
|
|
|
async () => {
|
2021-12-29 11:11:49 +05:00
|
|
|
|
const params = arrayOrDefault(await DrillParamsService.getAll(idWell))
|
|
|
|
|
setParams(params)
|
2021-10-12 11:10:33 +05:00
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
'Не удалось загрузить список режимов бурения скважины'
|
2021-12-29 11:11:49 +05:00
|
|
|
|
), [idWell])
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-29 11:11:49 +05:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
setColumns(getColumns(idWell))
|
|
|
|
|
updateParams()
|
|
|
|
|
}, [idWell, updateParams])
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const handlerProps = {
|
|
|
|
|
service: DrillParamsService,
|
|
|
|
|
setLoader: setShowLoader,
|
|
|
|
|
errorMsg: `Не удалось выполнить операцию`,
|
|
|
|
|
onComplete: updateParams,
|
|
|
|
|
idWell
|
2021-10-12 11:10:33 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const recordParser = (record) => ({ ...record, idWell })
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<LoaderPortal show={showLoader}>
|
|
|
|
|
<EditableTable
|
|
|
|
|
size={'small'}
|
|
|
|
|
bordered
|
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={params}
|
2021-12-27 15:18:20 +05:00
|
|
|
|
onRowAdd={makeActionHandler('insert', handlerProps, recordParser)}
|
|
|
|
|
onRowEdit={makeActionHandler('update', handlerProps, recordParser)}
|
|
|
|
|
onRowDelete={makeActionHandler('delete', handlerProps, recordParser)}
|
2021-10-12 16:51:25 +05:00
|
|
|
|
pagination={false}
|
2021-10-12 11:10:33 +05:00
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
|
|
|
|
}
|