diff --git a/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx b/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx index d57c99c2..a439481c 100644 --- a/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx +++ b/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx @@ -30,7 +30,8 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set const globalLocale = useRecoilValue(globalLocaleStore) const { basicSetting, setBasicSettings, fetchBasicSettings, basicSettingSave, addedRoofs, setAddedRoofs } = useCanvasSetting() const { findCommonCode } = useCommonCode() - const [raftCodes, setRaftCodes] = useState([]) //서까래 정보 + const [raftCodes, setRaftCodes] = useState([]) // 서까래 정보 + const [currentRoof, setCurrentRoof] = useState(addedRoofs[0]) // 현재 선택된 지붕재 정보 const roofRef = { roofCd: useRef(null), @@ -42,70 +43,61 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set // 데이터를 최초 한 번만 조회 useEffect(() => { - fetchBasicSettings() + //fetchBasicSettings() const raftCodeList = findCommonCode('203800') setRaftCodes(raftCodeList) }, []) useEffect(() => { - if (addedRoofs.length > 0) { + if (currentRoof.roofMatlCd.length > 0) { setBasicSettings({ ...basicSetting, roofsData: { roofApply: true, roofSeq: 0, - roofMatlCd: addedRoofs[0].roofMatlCd, - roofWidth: addedRoofs[0].width, - roofHeight: addedRoofs[0].length, - roofHajebichi: addedRoofs[0].hajebichi, - roofGap: addedRoofs[0].raft, - roofLayout: addedRoofs[0].layout, + roofMatlCd: currentRoof.roofMatlCd, + roofWidth: currentRoof.width, + roofHeight: currentRoof.length, + roofHajebichi: currentRoof.hajebichi, + roofGap: currentRoof.raft, + roofLayout: currentRoof.layout, }, }) } - }, [basicSetting.roofSizeSet, basicSetting.roofAngleSet, addedRoofs]) - - const changeInput = (value, e) => { - const { name } = e.target - setAddedRoofs(addedRoofs.map((roof) => ({ - ...roof, - [name]: Number(value), - }))) - } + }, [basicSetting.roofSizeSet, basicSetting.roofAngleSet, currentRoof]) // Function to update the roofType and corresponding values const handleRoofTypeChange = (value) => { const selectedRoofMaterial = roofMaterials.find((roof) => roof.roofMatlCd === value) - setAddedRoofs([selectedRoofMaterial]) + setCurrentRoof({...selectedRoofMaterial, index: 0}) + } + + const changeInput = (value, e) => { + const { name } = e.target + setCurrentRoof({...currentRoof, [name]: Number(value)}) } const handleRafterChange = (value) => { - setAddedRoofs(addedRoofs.map((roof) => ({ - ...roof, - raft: value, - }))) + setCurrentRoof({...currentRoof, raft: value}) } const handleRoofLayoutChange = (value) => { - setAddedRoofs(addedRoofs.map((roof) => ({ - ...roof, - layout: value, - }))) + setCurrentRoof({...currentRoof, layout: value}) } const handleSaveBtn = () => { const roofInfo = { - ...addedRoofs, + ...currentRoof, roofCd: roofRef.roofCd.current?.value, width: roofRef.width.current?.value, length: roofRef.length.current?.value, hajebichi: roofRef.hajebichi.current?.value, - //raft: roofRef.rafter.current?.value, + raft: roofRef.rafter.current?.value, selected: true, - layout: addedRoofs[0].layout, + layout: currentRoof.layout, index: 0, } - + const newAddedRoofs = [...addedRoofs] if (addedRoofs.length === 1) { newAddedRoofs[0] = { ...roofInfo } @@ -130,12 +122,12 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set roofsData: { roofApply: true, roofSeq: 0, - roofMatlCd: addedRoofs[0].roofMatlCd, - roofWidth: addedRoofs[0].width, - roofHeight: addedRoofs[0].length, - roofHajebichi: addedRoofs[0].hajebichi, - roofGap: addedRoofs[0].raft, - roofLayout: addedRoofs[0].layout, + roofMatlCd: currentRoof.roofMatlCd, + roofWidth: currentRoof.width, + roofHeight: currentRoof.length, + roofHajebichi: currentRoof.hajebichi, + roofGap: currentRoof.raft, + roofLayout: currentRoof.layout, }, }) @@ -248,14 +240,14 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set
{ return { ...roof, name: globalLocale === 'ko' ? roof.roofMatlNm : roof.roofMatlNmJp } })} //value={roofMaterials.find((r) => r.roofMatlCd === basicSetting.roofs[0]?.roofMatlCd)} //title={basicSetting.roofs[0]?.roofMatlNm} - value={basicSetting.roofSizeSet == 3 ? null : addedRoofs[0]?.roofMatlCd} + value={basicSetting.roofSizeSet == 3 ? null : currentRoof.roofMatlCd} onChange={(e) => handleRoofTypeChange(e.roofMatlCd)} //sourceKey="id" //targetKey="id" @@ -280,7 +272,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set })} */}
- {basicSetting && ['R', 'C'].includes(addedRoofs[0]?.widAuth) && ( + {basicSetting && ['R', 'C'].includes(currentRoof.widAuth) && (
W
@@ -289,9 +281,9 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set className="input-origin block" name={`width`} ref={roofRef.width} - value={parseInt(addedRoofs[0]?.width)} + value={parseInt(currentRoof.width)} onChange={(e) => onlyNumberInputChange(e, changeInput)} - readOnly={addedRoofs[0]?.widAuth === 'R'} + readOnly={currentRoof.widAuth === 'R'} disabled={basicSetting.roofSizeSet == 3} />
@@ -305,7 +297,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set
*/}
)} - {basicSetting && ['R', 'C'].includes(addedRoofs[0]?.lenAuth) && ( + {basicSetting && ['R', 'C'].includes(currentRoof.lenAuth) && (
L
@@ -314,9 +306,9 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set className="input-origin block" name={`length`} ref={roofRef.length} - value={parseInt(addedRoofs[0]?.length)} + value={parseInt(currentRoof.length)} onChange={(e) => onlyNumberInputChange(e, changeInput)} - readOnly={addedRoofs[0]?.lenAuth === 'R'} + readOnly={currentRoof.lenAuth === 'R'} disabled={basicSetting.roofSizeSet == 3} />
@@ -330,18 +322,19 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set
*/} )} - {basicSetting && ['C', 'R'].includes(addedRoofs[0]?.raftAuth) && ( + {basicSetting && ['C', 'R'].includes(currentRoof.raftAuth) && (
{getMessage('modal.placement.initial.setting.rafter')} {raftCodes.length > 0 && (
r.clCode === (addedRoofs[0]?.raft === undefined ? addedRoofs[0]?.raftBaseCd : addedRoofs[0]?.raft))?.clCodeNm} - value={addedRoofs[0]?.raft === undefined ? addedRoofs[0]?.raftBaseCd : addedRoofs[0]?.raft} + options={raftCodes} + ref={roofRef.rafter} + title={raftCodes.find((r) => r.clCode === (currentRoof.raft === undefined ? currentRoof.raftBaseCd : currentRoof.raft)).clCodeNm} + value={currentRoof.raft === undefined ? currentRoof.raftBaseCd : currentRoof.raft} onChange={(e) => handleRafterChange(e.clCode)} sourceKey="clCode" - targetKey={addedRoofs[0]?.raft ? 'raft' : 'raftBaseCd'} + targetKey={currentRoof.raft ? 'raft' : 'raftBaseCd'} showKey="clCodeNm" disabled={basicSetting.roofSizeSet == 3} /> @@ -358,7 +351,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set )}
)} - {basicSetting && ['C', 'R'].includes(addedRoofs[0]?.roofPchAuth) && ( + {basicSetting && ['C', 'R'].includes(currentRoof.roofPchAuth) && (
{getMessage('hajebichi')}
@@ -367,9 +360,9 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set className="input-origin block" name={`hajebichi`} ref={roofRef.hajebichi} - value={parseInt(addedRoofs[0]?.hajebichi)} + value={parseInt(currentRoof.hajebichi)} onChange={(e) => onlyNumberInputChange(e, changeInput)} - readOnly={addedRoofs[0]?.roofPchAuth === 'R'} + readOnly={currentRoof.roofPchAuth === 'R'} disabled={basicSetting.roofSizeSet == 3} />
@@ -379,7 +372,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set