asb_cloud_front/src/pages/WellOperations/WellDrillParams.jsx

78 lines
2.5 KiB
React
Raw Normal View History

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