moduleSelectionData 수정

This commit is contained in:
김민식 2025-04-08 13:03:23 +09:00
parent 9976ff59d6
commit 468c7fda6f
4 changed files with 76 additions and 64 deletions

View File

@ -77,7 +77,7 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) {
const { trigger: orientationTrigger } = useCanvasPopupStatusController(1)
const { trigger: trestleTrigger } = useCanvasPopupStatusController(2)
const { trigger: placementTrigger } = useCanvasPopupStatusController(3)
const roofsStore = useRecoilValue(roofsState)
const [roofsStore, setRoofsStore] = useRecoilState(roofsState)
// const { initEvent } = useContext(EventContext)
const { manualModuleSetup, autoModuleSetup, manualFlatroofModuleSetup, autoFlatroofModuleSetup, manualModuleLayoutSetup } =
@ -95,6 +95,7 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) {
}),
)
console.log(roofsStore)
setModuleSelectionData({
...moduleSelectionData,
roofConstructions: roofsStore.map((roof) => {
@ -255,6 +256,7 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) {
const trestleProps = {
roofs,
setRoofs,
setRoofsStore,
tabNum,
setTabNum,
moduleSelectionData,

View File

@ -352,8 +352,8 @@ const Placement = forwardRef((props, refs) => {
<tr>
<td>
<div className="color-wrap">
<span className="color-box" style={{ backgroundColor: roofOutlineColor(item.addRoof.index) }}></span>
<span className="name">{item.addRoof.roofMatlNmJp}</span>
<span className="color-box" style={{ backgroundColor: roofOutlineColor(item.addRoof?.index) }}></span>
<span className="name">{item.addRoof?.roofMatlNmJp}</span>
</div>
</td>
{moduleRowColArray[index]?.map((item) => (

View File

@ -6,12 +6,11 @@ import { useMessage } from '@/hooks/useMessage'
import { currentAngleTypeSelector, pitchTextSelector } from '@/store/canvasAtom'
import { roofsState } from '@/store/roofAtom'
import { moduleSelectionDataState, selectedModuleState } from '@/store/selectedModuleOptions'
import { isObjectNotEmpty } from '@/util/common-utils'
import { forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState } from 'react'
import { useRecoilState, useRecoilValue } from 'recoil'
const Trestle = forwardRef((props, ref) => {
const { tabNum, setTabNum, trestleTrigger, roofs, setRoofs, moduleSelectionData, setModuleSelectionData } = props
const { tabNum, setTabNum, trestleTrigger, roofs, setRoofs, moduleSelectionData, setModuleSelectionData, setRoofsStore } = props
const { getMessage } = useMessage()
// const [selectedTrestle, setSelectedTrestle] = useState()
const currentAngleType = useRecoilValue(currentAngleTypeSelector)
@ -66,8 +65,6 @@ const Trestle = forwardRef((props, ref) => {
restoreModuleInstArea()
}, [roofs])
useEffect(() => {}, [moduleSelectionData])
useEffect(() => {
if (flag && moduleSelectionData) {
if (JSON.stringify(tempModuleSelectionData.current) === JSON.stringify(moduleSelectionData)) {
@ -82,7 +79,16 @@ const Trestle = forwardRef((props, ref) => {
setEavesMargin(selectedRoof?.eavesMargin ?? 0)
setRidgeMargin(selectedRoof?.ridgeMargin ?? 0)
setKerabaMargin(selectedRoof?.kerabaMargin ?? 0)
dispatch({ type: 'SET_INITIALIZE', roof: { ...selectedRoof, ...moduleSelectionData } })
setLengthBase(Math.round(selectedRoof?.lenBase ?? 0))
if (moduleSelectionData?.roofConstructions?.length >= selectedRoof.index + 1) {
const { construction, trestle, trestleDetail } = moduleSelectionData?.roofConstructions[selectedRoof.index]
dispatch({
type: 'SET_INITIALIZE',
roof: { common: moduleSelectionData.common, module: moduleSelectionData.module, construction, trestle, trestleDetail, ...selectedRoof },
})
} else {
dispatch({ type: 'SET_INITIALIZE', roof: { ...selectedRoof, ...moduleSelectionData } })
}
}
}, [selectedRoof])
@ -180,33 +186,6 @@ const Trestle = forwardRef((props, ref) => {
},
})
}
const handleChangeRoofMaterial = (index) => {
const newAddedRoofs = roofs.map((roof, i) => {
if (i === selectedRoof.index) {
return {
...selectedRoof,
eavesMargin,
ridgeMargin,
kerabaMargin,
roofIndex: roof.index,
trestle: {
lengthBase: lengthBase,
...selectedRaftBase,
...selectedTrestle,
...selectedConstMthd,
...selectedRoofBase,
},
construction: {
...constructionList.find((data) => data.constTp === trestleState.constTp),
},
trestleDetail: trestleDetail,
}
}
return roof
})
setRoofs(newAddedRoofs)
setSelectedRoof(newAddedRoofs[index])
}
const handleConstruction = (index) => {
if (constructionList[index]?.constPossYn === 'Y') {
@ -227,7 +206,7 @@ const Trestle = forwardRef((props, ref) => {
roofPitch: Math.round(selectedRoof?.roofPchBase ?? 0),
constTp: constructionList[index].constTp,
mixMatlNo: selectedModules.mixMatlNo,
workingWidth: selectedRoof?.length.toString() ?? '',
workingWidth: selectedRoof?.length?.toString() ?? '',
// snowGdPossYn: constructionList[index].snowGdPossYn,
// cvrYn: constructionList[index].cvrYn,
},
@ -240,9 +219,38 @@ const Trestle = forwardRef((props, ref) => {
}
}
const handleChangeRoofMaterial = (index) => {
const newAddedRoofs = roofs.map((roof, i) => {
if (i === selectedRoof.index) {
return {
...selectedRoof,
eavesMargin,
ridgeMargin,
kerabaMargin,
roofIndex: selectedRoof.index,
trestle: {
lengthBase: lengthBase,
...selectedRaftBase,
...selectedTrestle,
...selectedConstMthd,
...selectedRoofBase,
},
construction: {
...constructionList.find((data) => data.constTp === trestleState.constTp),
},
trestleDetail: trestleDetail,
}
}
return roof
})
setRoofs(newAddedRoofs)
setSelectedRoof(newAddedRoofs[index])
console.log(newAddedRoofs)
}
const isComplete = async () => {
const newAddedRoofs = roofs.map((roof, i) => {
if (i === selectedRoof?.roofIndex) {
if (i === selectedRoof?.index) {
return {
...selectedRoof,
eavesMargin,
@ -286,7 +294,7 @@ const Trestle = forwardRef((props, ref) => {
})
const newRoofs = newAddedRoofs.map((roof) => {
const { addRoof, trestle, construction, ...rest } = roof
const { addRoof, construction, trestle, trestleDetail, roofConstructions, ...rest } = roof
return rest
})
if (result) {
@ -321,23 +329,25 @@ const Trestle = forwardRef((props, ref) => {
}),
new Promise((resolve) => {
trestleTrigger({
roofConstruction: newAddedRoofs.map((roof, index) => ({
const roofConstruction = newAddedRoofs.map((roof, index) => ({
roofIndex: roof.index,
addRoof: newRoofs[index],
trestle: {
...roof.trestle,
raftBaseCd: roof.raftBaseCd,
},
construction: {
...constructionList.find((construction) => newAddedRoofs[index].construction.constTp === construction.constTp),
roofIndex: roof.index,
addRoof: newRoofs[index],
trestle: {
...selectedTrestle,
raftBaseCd: roof.raftBaseCd,
},
construction: {
...constructionList.find((construction) => trestleState.constTp === construction.constTp),
roofIndex: roof.index,
setupCover: roof.cvrYn === 'Y',
setupSnowCover: roof.snowGdYn === 'Y',
selectedIndex: roof.index,
},
})),
setupCover: roof.cvrYn === 'Y',
setupSnowCover: roof.snowGdYn === 'Y',
selectedIndex: roof.index,
},
}))
trestleTrigger({
roofConstruction,
})
setRoofsStore(roofConstruction)
resolve()
}),
]
@ -383,7 +393,7 @@ const Trestle = forwardRef((props, ref) => {
<input
type="text"
className="input-origin block"
value={trestleState?.lengthBase}
value={lengthBase}
onChange={(e) => setLengthBase(e.target.value)}
disabled={selectedRoof.lenAuth === 'R'}
/>

View File

@ -23,21 +23,21 @@ const trestleReducer = (state, action) => {
moduleTpCd: action.roof.module?.itemTp ?? '',
roofMatlCd: action.roof?.roofMatlCd ?? '',
raftBaseCd: action.roof?.raftBaseCd ?? null,
trestleMkrCd: action.roof.roofConstructions[action.roof.index].trestle?.trestleMkrCd ?? null,
constMthdCd: action.roof.roofConstructions[action.roof.index].trestle?.constMthdCd ?? null,
constTp: action.roof.roofConstructions[action.roof.index].construction?.constTp ?? null,
roofBaseCd: action.roof.roofConstructions[action.roof.index].trestle?.roofBaseCd ?? null,
trestleMkrCd: action.roof.trestle?.trestleMkrCd ?? null,
constMthdCd: action.roof.trestle?.constMthdCd ?? null,
constTp: action.roof.construction?.constTp ?? null,
roofBaseCd: action.roof.trestle?.roofBaseCd ?? null,
workingWidth: action.roof.workingWidth ?? 0,
lengthBase: action.roof.roofConstructions[action.roof.index].addRoof?.length ?? 0,
lengthBase: action.roof?.length ?? 0,
illuminationTp: action.roof.common.illuminationTp ?? null,
instHt: action.roof.common.instHt ?? null,
stdWindSpeed: action.roof.common.stdWindSpeed ?? null,
stdSnowLd: action.roof.common.stdSnowLd ?? null,
inclCd: action.roof.roofConstructions[action.roof.index].addRoof?.pitch ?? null,
roofPitch: action.roof.roofConstructions[action.roof.index].addRoof?.roofPchBase ?? 0,
eavesMargin: action.roof.roofConstructions[action.roof.index].addRoof?.eavesMargin ?? null,
ridgeMargin: action.roof.roofConstructions[action.roof.index].addRoof?.ridgeMargin ?? null,
kerabaMargin: action.roof.roofConstructions[action.roof.index].addRoof?.kerabaMargin ?? null,
inclCd: action.roof?.pitch ?? null,
roofPitch: action.roof?.roofPchBase ?? 0,
eavesMargin: action.roof?.eavesMargin ?? null,
ridgeMargin: action.roof?.ridgeMargin ?? null,
kerabaMargin: action.roof?.kerabaMargin ?? null,
}
default:
return state