2021-10-12 11:10:33 +05:00
|
|
|
|
import { useState, useEffect } from 'react'
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
makeColumn,
|
|
|
|
|
makeNumericAvgRange,
|
|
|
|
|
makeNumericStartEnd
|
|
|
|
|
} 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'
|
|
|
|
|
|
|
|
|
|
const basePageSize = 160;
|
|
|
|
|
|
|
|
|
|
|
2021-10-12 15:04:02 +05:00
|
|
|
|
export const WellDrillParams = ({idWell}) => {
|
2021-10-12 11:10:33 +05:00
|
|
|
|
const [pageNumAndPageSize, setPageNumAndPageSize] = useState({current:1, pageSize:basePageSize})
|
|
|
|
|
const [paginationTotal, setPaginationTotal] = useState(0)
|
|
|
|
|
const [params, setParams] = useState([])
|
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
|
|
|
|
|
|
|
|
|
const updatePrograms = () => invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
|
|
|
|
const skip = ((pageNumAndPageSize.current - 1) * pageNumAndPageSize.pageSize) || 0
|
|
|
|
|
const take = pageNumAndPageSize.pageSize
|
2021-10-12 15:04:02 +05:00
|
|
|
|
const paginatedParams = await DrillParamsService.getParams(idWell, skip, take)
|
2021-10-12 11:10:33 +05:00
|
|
|
|
const params = paginatedParams?.items ?? []
|
|
|
|
|
setParams(params)
|
|
|
|
|
const total = paginatedParams.count?? paginatedParams.items?.length ?? 0
|
|
|
|
|
setPaginationTotal(total)
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
'Не удалось загрузить список режимов бурения скважины'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
useEffect(updatePrograms, [idWell, pageNumAndPageSize])
|
|
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
|
makeColumn('Конструкция секции','id_wellsection_type', {
|
|
|
|
|
editable:true,
|
|
|
|
|
input:<SelectFromDictionary dictionary={dictionarySectionType}/>,
|
|
|
|
|
width:160,
|
|
|
|
|
render:(_, record)=>getByKeyOrReturnKey(dictionarySectionType, record.idWellSectionType)
|
|
|
|
|
}),
|
2021-10-12 15:04:02 +05:00
|
|
|
|
// makeNumericStartEnd('Глубина', 'depth'),
|
|
|
|
|
makeNumericAvgRange('Нагрузка', 'axialLoad'),
|
|
|
|
|
makeNumericAvgRange('Давление', 'pressure'),
|
|
|
|
|
makeNumericAvgRange('Момент на ВПС', 'topDriveTorque'),
|
|
|
|
|
makeNumericAvgRange('Обороты на ВПС', 'topDriveSpeed'),
|
|
|
|
|
makeNumericAvgRange('Расход', 'flow')
|
2021-10-12 11:10:33 +05:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const onAdd = async (param) => {
|
|
|
|
|
if (!param.id) return
|
|
|
|
|
// TODO: Add row
|
2021-10-12 15:04:02 +05:00
|
|
|
|
await DrillParamsService.saveDrillParams(idWell, param)
|
2021-10-12 11:10:33 +05:00
|
|
|
|
updatePrograms()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onEdit = async (param) => {
|
|
|
|
|
if (!param.id) return
|
|
|
|
|
// TODO: Edit row
|
2021-10-12 15:04:02 +05:00
|
|
|
|
await DrillParamsService.update(idWell, param.id, param)
|
2021-10-12 11:10:33 +05:00
|
|
|
|
updatePrograms()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 11:10:33 +05:00
|
|
|
|
updatePrograms()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<LoaderPortal show={showLoader}>
|
|
|
|
|
<EditableTable
|
|
|
|
|
size={'small'}
|
|
|
|
|
bordered
|
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={params}
|
2021-10-12 15:04:02 +05:00
|
|
|
|
//onRowAdd={onAdd}
|
2021-10-12 11:10:33 +05:00
|
|
|
|
onRowEdit={onEdit}
|
|
|
|
|
onRowDelete={onDelete}
|
|
|
|
|
pagination={{
|
|
|
|
|
current: pageNumAndPageSize.current,
|
|
|
|
|
pageSize: pageNumAndPageSize.pageSize,
|
|
|
|
|
showSizeChanger: false,
|
|
|
|
|
total: paginationTotal,
|
|
|
|
|
onChange: (page, pageSize) => setPageNumAndPageSize({current: page, pageSize: pageSize})
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
|
|
|
|
}
|