2021-08-18 11:40:46 +05:00
|
|
|
|
import LoaderPortal from '../src/components/LoaderPortal'
|
2021-07-28 17:45:41 +05:00
|
|
|
|
import { useState, useEffect } from "react";
|
2021-08-18 11:40:46 +05:00
|
|
|
|
import {makeColumn, makeColumnsPlanFact, RegExpIsFloat} from '../src/components/factory'
|
|
|
|
|
import {WellSectionService} from '../src/services/api'
|
|
|
|
|
import {invokeWebApiWrapperAsync} from '../src/components/factory'
|
|
|
|
|
import { EditableTable } from '../src/components/EditableTable';
|
2021-08-12 15:43:03 +05:00
|
|
|
|
import { Input } from 'antd'
|
2021-07-28 17:45:41 +05:00
|
|
|
|
|
2021-08-12 15:43:03 +05:00
|
|
|
|
const TypeSelector = <Input list={'sectionTypeList'}/>
|
|
|
|
|
|
|
|
|
|
const DataListSectionTypes = <datalist id="sectionTypeList">
|
|
|
|
|
<option value="Пилотный ствол">Пилотный ствол</option>
|
|
|
|
|
<option value="Направление">Направление</option>
|
|
|
|
|
<option value="Кондуктор">Кондуктор</option>
|
|
|
|
|
<option value="Эксплуатационная колонна">Эксплуатационная колонна</option>
|
|
|
|
|
<option value="Транспортный ствол">Транспортный ствол</option>
|
|
|
|
|
<option value="Хвостовик">Хвостовик</option>
|
|
|
|
|
</datalist>
|
|
|
|
|
|
|
|
|
|
const numericColumnOptions = {
|
|
|
|
|
editable: true,
|
|
|
|
|
initialValue: 0,
|
|
|
|
|
formItemRules: [
|
2021-07-30 16:14:56 +05:00
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: `Введите число`,
|
2021-08-12 15:43:03 +05:00
|
|
|
|
pattern: RegExpIsFloat,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
|
makeColumn('Конструкция секции', 'sectionType', {editable:true, input:TypeSelector}),
|
|
|
|
|
makeColumnsPlanFact('Глубина, м', 'wellDepth', numericColumnOptions),
|
|
|
|
|
makeColumnsPlanFact('Период, д', 'buildDays', numericColumnOptions),
|
|
|
|
|
makeColumnsPlanFact('Механическая скорость проходки, м/час', 'rateOfPenetration', numericColumnOptions),
|
|
|
|
|
makeColumnsPlanFact('Рейсовая скорость, м/час', 'routeSpeed', numericColumnOptions),
|
|
|
|
|
makeColumnsPlanFact('Скорость подъема КНБК', 'bhaUpSpeed', numericColumnOptions),
|
|
|
|
|
makeColumnsPlanFact('Скорость спуска КНБК', 'bhaDownSpeed', numericColumnOptions),
|
|
|
|
|
makeColumnsPlanFact('Скорость спуска обсадной колонны', 'casingDownSpeed', numericColumnOptions),
|
2021-07-28 17:45:41 +05:00
|
|
|
|
]
|
|
|
|
|
|
2021-07-30 16:14:56 +05:00
|
|
|
|
export default function WellStat({idWell}){
|
2021-07-28 17:45:41 +05:00
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
2021-08-12 15:43:03 +05:00
|
|
|
|
const [items, setItems] = useState([])
|
2021-07-30 16:14:56 +05:00
|
|
|
|
|
2021-08-12 15:43:03 +05:00
|
|
|
|
const addKeysAndUpdateStateData = (items) =>{
|
|
|
|
|
const keyedItems = items?.map(item => ({...item, key:item.id}))??[]
|
|
|
|
|
setItems(keyedItems)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-08-17 17:42:42 +05:00
|
|
|
|
invokeWebApiWrapperAsync(
|
2021-08-12 15:43:03 +05:00
|
|
|
|
async () => {
|
|
|
|
|
const paginationContainer = await WellSectionService.getAll(idWell, 0, 1024)
|
|
|
|
|
addKeysAndUpdateStateData(paginationContainer.items)
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
`Не удалось загрузить секции по скважине "${idWell}"`)
|
2021-07-30 16:14:56 +05:00
|
|
|
|
} ,[idWell])
|
|
|
|
|
|
2021-08-12 15:43:03 +05:00
|
|
|
|
const onAdd = (item) => {
|
2021-08-17 17:42:42 +05:00
|
|
|
|
invokeWebApiWrapperAsync(
|
2021-08-12 15:43:03 +05:00
|
|
|
|
async () => {
|
|
|
|
|
const updatedItems = await WellSectionService.insert(idWell, [item])
|
|
|
|
|
const newItems = [...items, ...updatedItems]
|
|
|
|
|
addKeysAndUpdateStateData(newItems)
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
`Не удалось добавить секцию в скважину "${idWell}"`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onEdit = (item) => {
|
2021-08-17 17:42:42 +05:00
|
|
|
|
invokeWebApiWrapperAsync(
|
2021-08-12 15:43:03 +05:00
|
|
|
|
async () => {
|
|
|
|
|
const updatedItem = await WellSectionService.update(idWell, item.id, item)
|
|
|
|
|
const newItems = [...items]
|
|
|
|
|
const index = newItems.findIndex((i) => item.key === i.key)
|
|
|
|
|
newItems.splice(index, 1, updatedItem)
|
|
|
|
|
addKeysAndUpdateStateData(newItems)
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
`Не удалось изменить секцию в скважине "${idWell}"`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onDelete = (item) =>{
|
2021-08-17 17:42:42 +05:00
|
|
|
|
invokeWebApiWrapperAsync(
|
2021-08-12 15:43:03 +05:00
|
|
|
|
async () => {
|
|
|
|
|
await WellSectionService.delete(idWell, [item.id])
|
|
|
|
|
const newItems = [...items]
|
|
|
|
|
const index = newItems.findIndex((i) => item.key === i.key)
|
|
|
|
|
newItems.splice(index, 1)
|
|
|
|
|
addKeysAndUpdateStateData(newItems)
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
`Не удалось удалить секцию из скважины "${idWell}"`)
|
2021-08-02 11:09:55 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-28 17:45:41 +05:00
|
|
|
|
return(
|
|
|
|
|
<LoaderPortal show={showLoader}>
|
2021-07-30 16:14:56 +05:00
|
|
|
|
<EditableTable
|
|
|
|
|
columns={columns}
|
2021-08-12 15:43:03 +05:00
|
|
|
|
dataSource={items}
|
2021-07-30 16:14:56 +05:00
|
|
|
|
size={'small'}
|
|
|
|
|
bordered
|
|
|
|
|
pagination={false}
|
2021-08-12 15:43:03 +05:00
|
|
|
|
onRowAdd={onAdd}
|
|
|
|
|
onRowEdit={onEdit}
|
|
|
|
|
onRowDelete={onDelete}
|
2021-07-30 16:14:56 +05:00
|
|
|
|
/>
|
2021-08-12 15:43:03 +05:00
|
|
|
|
{DataListSectionTypes}
|
2021-07-28 17:45:41 +05:00
|
|
|
|
</LoaderPortal>)
|
|
|
|
|
}
|