2021-08-19 15:07:24 +05:00
|
|
|
|
import moment from 'moment'
|
2021-12-27 15:18:20 +05:00
|
|
|
|
import { Input } from 'antd'
|
2022-02-07 14:58:38 +05:00
|
|
|
|
import { useState, useEffect, memo } from 'react'
|
2021-12-27 15:18:20 +05:00
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
EditableTable,
|
|
|
|
|
DatePickerWrapper,
|
|
|
|
|
makeColumn,
|
2021-09-16 16:33:03 +05:00
|
|
|
|
makeDateSorter,
|
2021-12-27 15:18:20 +05:00
|
|
|
|
makeNumericColumnOptions,
|
|
|
|
|
makeSelectColumn,
|
|
|
|
|
makeActionHandler,
|
2022-02-07 14:58:38 +05:00
|
|
|
|
} from '@components/Table'
|
|
|
|
|
import { WellOperationService} from '@api'
|
|
|
|
|
import LoaderPortal from '@components/LoaderPortal'
|
|
|
|
|
import { invokeWebApiWrapperAsync } from '@components/factory'
|
|
|
|
|
import { hasPermission } from '@utils/permissions'
|
|
|
|
|
import { formatDate } from '@utils'
|
2021-08-19 15:07:24 +05:00
|
|
|
|
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const { TextArea } = Input
|
2021-08-19 15:07:24 +05:00
|
|
|
|
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const basePageSize = 160
|
|
|
|
|
|
|
|
|
|
const defaultColumns = [
|
2022-01-13 15:52:57 +05:00
|
|
|
|
makeSelectColumn('Конструкция секции', 'idWellSectionType', [], undefined, {
|
|
|
|
|
editable: true,
|
|
|
|
|
width: 160,
|
|
|
|
|
formItemRules: [({ getFieldValue }) => ({
|
|
|
|
|
validator(_, value) {
|
|
|
|
|
if (value?.length > 0)
|
|
|
|
|
return Promise.resolve()
|
|
|
|
|
return Promise.reject('Это обязательное поле!')
|
|
|
|
|
}
|
|
|
|
|
})],
|
|
|
|
|
}),
|
2021-12-27 15:18:20 +05:00
|
|
|
|
makeSelectColumn('Операция', 'idCategory', [], undefined, { editable: true, width: 200 }),
|
|
|
|
|
makeColumn('Доп. инфо', 'categoryInfo', { editable: true, width: 300, input: <TextArea/> }),
|
|
|
|
|
makeColumn('Глубина забоя на начало, м', 'depthStart', makeNumericColumnOptions(2, 'depthStart')),
|
|
|
|
|
makeColumn('Глубина забоя при завершении, м', 'depthEnd', makeNumericColumnOptions(2, 'depthEnd')),
|
|
|
|
|
makeColumn('Время начала', 'dateStart', {
|
|
|
|
|
editable: true,
|
|
|
|
|
width: 200,
|
|
|
|
|
input: <DatePickerWrapper/>,
|
|
|
|
|
initialValue: moment().format(),
|
|
|
|
|
sorter: makeDateSorter('dateStart'),
|
|
|
|
|
render: (_, record) => (
|
|
|
|
|
<div className={'text-align-r-container'}>
|
|
|
|
|
<span>{formatDate(record.dateStart)}</span>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}),
|
|
|
|
|
makeColumn('Часы', 'durationHours', makeNumericColumnOptions(2, 'durationHours')),
|
|
|
|
|
makeColumn('Комментарий', 'comment', { editable: true, input: <TextArea/> }),
|
|
|
|
|
]
|
2021-08-18 18:01:46 +05:00
|
|
|
|
|
2022-02-07 14:58:38 +05:00
|
|
|
|
export const WellOperationsEditor = memo(({ idWell, idType, ...other }) => {
|
2021-08-18 18:01:46 +05:00
|
|
|
|
const [pageNumAndPageSize, setPageNumAndPageSize] = useState({current:1, pageSize:basePageSize})
|
|
|
|
|
const [paginationTotal, setPaginationTotal] = useState(0)
|
|
|
|
|
const [operations, setOperations] = useState([])
|
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const [columns, setColumns] = useState(defaultColumns)
|
|
|
|
|
|
2021-08-19 15:07:24 +05:00
|
|
|
|
useEffect(() => invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
2021-12-27 15:18:20 +05:00
|
|
|
|
let categories = await WellOperationService.getCategories(idWell) ?? []
|
|
|
|
|
categories = categories.map((item) => ({ value: item.id, label: item.name }))
|
|
|
|
|
|
|
|
|
|
let sectionTypes = await WellOperationService.getSectionTypes(idWell) ?? []
|
|
|
|
|
sectionTypes = Object.keys(sectionTypes).map((key) => ({ value: parseInt(key), label: sectionTypes[key] }))
|
|
|
|
|
|
|
|
|
|
setColumns(preColumns => {
|
|
|
|
|
preColumns[0] = makeSelectColumn('Конструкция секции', 'idWellSectionType', sectionTypes, undefined, { editable: true, width: 160 })
|
|
|
|
|
preColumns[1] = makeSelectColumn('Операция', 'idCategory', categories, undefined, { editable: true, width: 200 })
|
|
|
|
|
return preColumns
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
'Не удалось загрузить список операций по скважине'
|
|
|
|
|
), [idWell])
|
2021-08-18 18:01:46 +05:00
|
|
|
|
|
|
|
|
|
const updateOperations = () => invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
|
|
|
|
const skip = ((pageNumAndPageSize.current - 1) * pageNumAndPageSize.pageSize) || 0
|
|
|
|
|
const take = pageNumAndPageSize.pageSize
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const paginatedOperations = await WellOperationService.getOperations(idWell,
|
|
|
|
|
idType, undefined, undefined, undefined, undefined,
|
2021-08-30 15:53:08 +05:00
|
|
|
|
undefined, undefined, skip, take )
|
2021-08-19 15:07:24 +05:00
|
|
|
|
const operations = paginatedOperations?.items ?? []
|
|
|
|
|
setOperations(operations)
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const total = paginatedOperations.count?? paginatedOperations.items?.length ?? 0
|
2021-08-18 18:01:46 +05:00
|
|
|
|
setPaginationTotal(total)
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
'Не удалось загрузить список операций по скважине'
|
|
|
|
|
)
|
|
|
|
|
|
2021-08-19 15:07:24 +05:00
|
|
|
|
useEffect(updateOperations, [idWell, idType, pageNumAndPageSize])
|
2021-08-18 18:01:46 +05:00
|
|
|
|
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const handlerProps = {
|
|
|
|
|
service: WellOperationService,
|
|
|
|
|
setLoader: setShowLoader,
|
|
|
|
|
errorMsg: `Не удалось выполнить операцию`,
|
|
|
|
|
onComplete: updateOperations,
|
|
|
|
|
idWell
|
2021-08-18 18:01:46 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const recordParser = (record) => ({
|
|
|
|
|
...record,
|
|
|
|
|
idType,
|
|
|
|
|
wellDepth: +record.wellDepth,
|
|
|
|
|
durationHours: +record.durationHours
|
|
|
|
|
})
|
2021-08-18 18:01:46 +05:00
|
|
|
|
|
2021-12-27 15:18:20 +05:00
|
|
|
|
return (
|
|
|
|
|
<LoaderPortal show={showLoader}>
|
|
|
|
|
<EditableTable
|
2022-02-07 14:58:38 +05:00
|
|
|
|
{...other}
|
2021-12-27 15:18:20 +05:00
|
|
|
|
bordered
|
2022-02-07 14:58:38 +05:00
|
|
|
|
size={'small'}
|
2021-12-27 15:18:20 +05:00
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={operations}
|
2022-02-07 14:58:38 +05:00
|
|
|
|
onRowAdd={hasPermission('WellOperation.edit') && makeActionHandler('insertRange', handlerProps, recordParser)}
|
|
|
|
|
onRowEdit={hasPermission('WellOperation.edit') && makeActionHandler('update', handlerProps, recordParser)}
|
|
|
|
|
onRowDelete={hasPermission('WellOperation.delete') && makeActionHandler('delete', handlerProps)}
|
2021-12-27 15:18:20 +05:00
|
|
|
|
pagination={{
|
|
|
|
|
current: pageNumAndPageSize.current,
|
|
|
|
|
pageSize: pageNumAndPageSize.pageSize,
|
|
|
|
|
showSizeChanger: false,
|
|
|
|
|
total: paginationTotal,
|
|
|
|
|
onChange: (page, pageSize) => setPageNumAndPageSize({ current: page, pageSize })
|
|
|
|
|
}}
|
2021-08-18 18:01:46 +05:00
|
|
|
|
/>
|
2021-12-27 15:18:20 +05:00
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
2022-02-07 14:58:38 +05:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default WellOperationsEditor
|