Сохранение выбранных секций добавлено

This commit is contained in:
goodmice 2021-10-14 16:56:29 +05:00
parent 58707c1665
commit 2f6a776eb9
3 changed files with 32 additions and 20 deletions

View File

@ -15,7 +15,7 @@ import {
getOperations getOperations
} from '../../Cluster/functions' } from '../../Cluster/functions'
import ChartTvD from '../ChartTvD' import ChartTvD from '../ChartTvD'
import { DrillParamsService } from '../../../services/api' import { DrillParamsService, WellCompositeService } from '../../../services/api'
import LoaderPortal from '../../../components/LoaderPortal' import LoaderPortal from '../../../components/LoaderPortal'
import WellOperationsTable from '../../Cluster/WellOperationsTable' import WellOperationsTable from '../../Cluster/WellOperationsTable'
import { invokeWebApiWrapperAsync } from '../../../components/factory' import { invokeWebApiWrapperAsync } from '../../../components/factory'
@ -73,6 +73,7 @@ export const WellCompositeSections = ({idWell, statsWells, selectedSections}) =>
let row = { let row = {
key: well.caption + section.id, key: well.caption + section.id,
id: well.id, id: well.id,
sectionId: section.id,
caption: well.caption, caption: well.caption,
sectionType: section.caption, sectionType: section.caption,
sectionWellDepthPlan: section.plan?.wellDepthEnd, sectionWellDepthPlan: section.plan?.wellDepthEnd,
@ -121,8 +122,13 @@ export const WellCompositeSections = ({idWell, statsWells, selectedSections}) =>
}, [statsWells]) }, [statsWells])
useEffect(() => { useEffect(() => {
const selected = rows.filter((row) => selectedSections.some(section => (
section.idWellSrc === row.id && section.idWellSectionType === row.sectionId
)))
}, [selectedSections]) setSelectedWells(selected)
setSelectedWellsKeys(selected.map((row) => row.key))
}, [rows, selectedSections])
const columns = [ const columns = [
makeTextColumn("скв №", "caption", null, null, makeTextColumn("скв №", "caption", null, null,
@ -178,10 +184,17 @@ export const WellCompositeSections = ({idWell, statsWells, selectedSections}) =>
const rowSelection = { const rowSelection = {
selectedRowKeys: selectedWellsKeys, selectedRowKeys: selectedWellsKeys,
onChange: (keys, items) => { onChange: (keys, items) => invokeWebApiWrapperAsync(
async () => {
const selectedSections = items.map((row) => ({idWell, idWellSrc: row.id, idWellSectionType: row.sectionId}))
await WellCompositeService.save(idWell, selectedSections)
setSelectedWells(items) setSelectedWells(items)
setSelectedWellsKeys(keys) setSelectedWellsKeys(keys)
}, },
setShowLoader,
'Не удалось сохранить изменения выбранных секций для композитной скважины'
)
} }
const onParamButtonClick = () => invokeWebApiWrapperAsync( const onParamButtonClick = () => invokeWebApiWrapperAsync(

View File

@ -17,7 +17,6 @@ export const WellCompositeEditor = ({idWell}) => {
const [wellsTree, setWellsTree] = useState([]) const [wellsTree, setWellsTree] = useState([])
const [showLoader, setShowLoader] = useState(false) const [showLoader, setShowLoader] = useState(false)
const [showTabLoader, setShowTabLoader] = useState(false) const [showTabLoader, setShowTabLoader] = useState(false)
const [selectedWells, setSelectedWells] = useState([])
const [selectedIdWells, setSelectedIdWells] = useState([]) const [selectedIdWells, setSelectedIdWells] = useState([])
const [statsWells, setStatsWells] = useState([]) const [statsWells, setStatsWells] = useState([])
const [selectedSections, setSelectedSections] = useState([]) const [selectedSections, setSelectedSections] = useState([])
@ -62,6 +61,11 @@ export const WellCompositeEditor = ({idWell}) => {
) )
}, [idWell]) }, [idWell])
useEffect(() => {
const wellIds = selectedSections.map((value) => value.idWellSrc)
setSelectedIdWells(wellIds)
}, [selectedSections])
useEffect(() => invokeWebApiWrapperAsync( useEffect(() => invokeWebApiWrapperAsync(
async () => { async () => {
const stats = await WellOperationStatService.getWellsStat(selectedIdWells) const stats = await WellOperationStatService.getWellsStat(selectedIdWells)
@ -71,13 +75,6 @@ export const WellCompositeEditor = ({idWell}) => {
'Не удалось загрузить статистику по скважинам/секциям' 'Не удалось загрузить статистику по скважинам/секциям'
), [selectedIdWells]) ), [selectedIdWells])
const onWellChanged = (value) => {
setSelectedWells(value)
setSelectedIdWells(value)
}
const tagRender = (props) => <Tag {...props}>{wellLabels[props.value] ?? props.label}</Tag>
return ( return (
<LoaderPortal show={showLoader}> <LoaderPortal show={showLoader}>
<Row align={'middle'} justify={'space-between'} wrap={false}> <Row align={'middle'} justify={'space-between'} wrap={false}>
@ -89,12 +86,14 @@ export const WellCompositeEditor = ({idWell}) => {
treeDefaultExpandAll treeDefaultExpandAll
treeData={wellsTree} treeData={wellsTree}
treeLine={{showLeafIcon: false}} treeLine={{showLeafIcon: false}}
onChange={onWellChanged} onChange={(value) => setSelectedIdWells(value)}
size={'middle'} size={'middle'}
style={{width: '100%'}} style={{width: '100%'}}
value={selectedWells} value={selectedIdWells}
placeholder={'Выберите скважины'} placeholder={'Выберите скважины'}
tagRender={tagRender} tagRender={(props) => (
<Tag {...props}>{wellLabels[props.value] ?? props.label}</Tag>
)}
/> />
</Col> </Col>
<Col span={6}> <Col span={6}>

View File

@ -43,14 +43,14 @@ export const WellDrillParams = ({idWell}) => {
const onAdd = async (param) => { const onAdd = async (param) => {
param.idWell = idWell param.idWell = idWell
await DrillParamsService.save(idWell, param) await DrillParamsService.insert(idWell, param)
updateParams() updateParams()
} }
const onEdit = async (param) => { const onEdit = async (param) => {
if (!param.id) return if (!param.id) return
param.idWell = idWell param.idWell = idWell
await DrillParamsService.edit(idWell, param) await DrillParamsService.update(idWell, param.id, param)
updateParams() updateParams()
} }