import { forwardRef, use, useContext, useEffect, useImperativeHandle, useState } from 'react' import { useMessage } from '@/hooks/useMessage' import { getDegreeInOrientation } from '@/util/canvas-util' import { numberCheck } from '@/util/common-utils' import { addedRoofsState, basicSettingState } from '@/store/settingAtom' import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil' import QSelectBox from '@/components/common/select/QSelectBox' import { roofsState } from '@/store/roofAtom' import { useModuleBasicSetting } from '@/hooks/module/useModuleBasicSetting' import Swal from 'sweetalert2' export const Orientation = forwardRef((props, ref) => { const { getMessage } = useMessage() const [hasAnglePassivity, setHasAnglePassivity] = useState(false) const basicSetting = useRecoilValue(basicSettingState) const [addedRoofs, setAddedRoofs] = useRecoilState(addedRoofsState) //지붕재 선택 const [roofsStore, setRoofsStore] = useRecoilState(roofsState) const [roofTab, setRoofTab] = useState(0) //지붕재 탭 const { roofs, setRoofs, tabNum, setTabNum, compasDeg, setCompasDeg, selectedModules, roughnessCodes, windSpeedCodes, managementState, setManagementState, moduleList, moduleSelectionData, setModuleSelectionData, setSelectedModules, selectedSurfaceType, setSelectedSurfaceType, installHeight, setInstallHeight, standardWindSpeed, setStandardWindSpeed, verticalSnowCover, setVerticalSnowCover, orientationTrigger, nextStep, currentCanvasPlan, loginUserState, updateObjectDataApi, } = props const [inputCompasDeg, setInputCompasDeg] = useState(compasDeg ?? 0) const [inputInstallHeight, setInputInstallHeight] = useState('0') const [inputMargin, setInputMargin] = useState('0') const [inputVerticalSnowCover, setInputVerticalSnowCover] = useState('0') const [inputRoughness, setInputRoughness] = useState(selectedSurfaceType) const [inputStandardWindSpeed, setInputStandardWindSpeed] = useState(standardWindSpeed) const { restoreModuleInstArea } = useModuleBasicSetting() const moduleData = { header: [ { name: getMessage('module'), width: 150, prop: 'module', type: 'color-box' }, { name: `${getMessage('height')} (mm)`, prop: 'height', }, { name: `${getMessage('width')} (mm)`, prop: 'width' }, { name: `${getMessage('output')} (W)`, prop: 'output' }, ], } useEffect(() => { if (basicSetting.roofSizeSet == '3') { restoreModuleInstArea() } }, []) useEffect(() => { if (moduleSelectionData?.common) { setInputMargin(moduleSelectionData?.common?.margin) } }, [moduleSelectionData]) useEffect(() => { if (selectedModules) { setSelectedModules(moduleList.find((module) => module.itemId === selectedModules.itemId)) } }, [selectedModules]) useEffect(() => { if (selectedSurfaceType) { setInputRoughness(roughnessCodes.find((code) => code.clCode === managementState?.surfaceTypeValue)) } }, [selectedSurfaceType]) useEffect(() => { if (standardWindSpeed) setInputStandardWindSpeed(windSpeedCodes.find((code) => code.clCode === managementState?.standardWindSpeedId)) }, [standardWindSpeed]) useEffect(() => { if (managementState?.installHeight && managementState?.installHeight) { setSelectedSurfaceType(roughnessCodes.find((code) => code.clCode === managementState?.surfaceTypeValue)) setInputInstallHeight(managementState?.installHeight) setStandardWindSpeed(windSpeedCodes.find((code) => code.clCode === managementState?.standardWindSpeedId)) setInputVerticalSnowCover(managementState?.verticalSnowCover) } }, [managementState]) useImperativeHandle(ref, () => ({ handleNextStep, })) const handleNextStep = () => { if (isComplete()) { const common = { illuminationTp: inputRoughness.clCode, illuminationTpNm: inputRoughness.clCodeNm, instHt: inputInstallHeight, stdWindSpeed: inputStandardWindSpeed?.clCode, stdSnowLd: inputVerticalSnowCover, saleStoreNorthFlg: managementState?.saleStoreNorthFlg, moduleTpCd: selectedModules.itemTp, moduleItemId: selectedModules.itemId, margin: inputMargin, } setCompasDeg(inputCompasDeg) setInstallHeight(inputInstallHeight) setVerticalSnowCover(inputVerticalSnowCover) setSelectedSurfaceType(inputRoughness) setStandardWindSpeed(inputStandardWindSpeed) nextStep(inputCompasDeg) setManagementState({ ...managementState, installHeight: inputInstallHeight, verticalSnowCover: inputVerticalSnowCover, standardWindSpeedId: inputStandardWindSpeed?.clCode, surfaceType: inputRoughness.clCodeNm, surfaceTypeValue: inputRoughness.clCode, }) setModuleSelectionData({ ...moduleSelectionData, module: { ...selectedModules, }, common, }) orientationTrigger({ compasDeg: inputCompasDeg, common: common, module: { ...selectedModules, }, margin: inputMargin, }) updateObjectDataApi({ objectNo: currentCanvasPlan.objectNo, //오브젝트_no standardWindSpeedId: inputStandardWindSpeed?.clCode, //기준풍속코드 verticalSnowCover: inputVerticalSnowCover, //적설량 surfaceType: inputRoughness.clCodeNm, //면조도구분 installHeight: inputInstallHeight, //설치높이 userId: loginUserState.userId, //작성자아아디 }) setTabNum(2) } else { if (!selectedModules || !selectedModules.itemId) { Swal.fire({ title: getMessage('module.not.found'), icon: 'warning', }) return } } } const checkDegree = (e) => { if (e === '-0' || e === '-') { setInputCompasDeg('-') return } if (e === '0-') { setInputCompasDeg('-0') return } if (Number(e) >= -180 && Number(e) <= 180) { if (numberCheck(Number(e))) { setInputCompasDeg(Number(e)) } } else { setInputCompasDeg(compasDeg) } } const isComplete = () => { if (!selectedModules || !selectedModules.itemId) return false if (basicSetting && basicSetting.roofSizeSet !== '3') { if (inputInstallHeight <= 0) { return false } if (+inputVerticalSnowCover <= 0) { return false } if (!inputStandardWindSpeed) return false if (!inputRoughness) return false } return true } const handleChangeModule = (e) => { resetRoofs() setSelectedModules(e) } const handleChangeRoughness = (e) => { resetRoofs() setInputRoughness(e) } const handleChangeInstallHeight = (e) => { resetRoofs() setInputInstallHeight(e) } const handleChangeStandardWindSpeed = (e) => { resetRoofs() setInputStandardWindSpeed(e) } const handleChangeVerticalSnowCover = (e) => { resetRoofs() setInputVerticalSnowCover(e) } const resetRoofs = () => { const newRoofs = addedRoofs.map((roof) => { return { ...roof, trestle: { lengthBase: null, trestleMkrCd: null, constMthdCd: null, constTp: null, roofBaseCd: null, roofPchBase: null, }, addRoof: { ...roof.addRoof, lengthBase: null, eavesMargin: null, kerabaMargin: null, ridgeMargin: null, }, construction: { constTp: null, cvrYn: 'N', snowGdPossYn: 'N', cvrChecked: false, snowGdChecked: false, }, } }) // setRoofs(newRoofs) // setAddedRoofs(newRoofs) setRoofsStore(newRoofs) } useEffect(() => { // 컴포넌트가 마운트될 때 selectedModules가 없으면 handleChangeModule 호출 if (moduleList.length > 0 && (!selectedModules || !selectedModules.itemId)) { handleChangeModule(moduleList[0]); } }, [moduleList]); // 빈 의존성 배열로 마운트 시 한 번만 실행 return ( <>
{getMessage('modal.module.basic.setting.orientation.setting.info')}
{Array.from({ length: 180 / 15 }).map((dot, index) => (
= 172 && index === 0 && inputCompasDeg <= 180) || (inputCompasDeg === -180 && index === 0) ? 'act' : ''}`} onClick={() => { if (index === 0) { setInputCompasDeg(180) return } setInputCompasDeg(-15 * index + 180) }} > {index === 0 && 180°} {index === 6 && 90°}
))} {Array.from({ length: 180 / 15 }).map((dot, index) => (
setInputCompasDeg(15 * index * -1)} > {index === 0 && } {index === 6 && -90°}
))}
setHasAnglePassivity(!hasAnglePassivity)} />
checkDegree(e.target.value)} />
° ( -180 〜 180 )
{getMessage('modal.module.basic.setting.module.setting')}
{moduleList && ( handleChangeModule(e)} /> )}
{moduleData.header.map((header) => { return ( ) })} {Array.from({ length: 3 }).map((_, index) => { return selectedModules && selectedModules?.itemList && selectedModules?.itemList?.length >= index + 1 ? ( ) : ( ) })}
{header.name}
{selectedModules.itemList[index].itemNm}
{Number(selectedModules.itemList[index].shortAxis).toFixed(0)} {Number(selectedModules.itemList[index].longAxis).toFixed(0)} {Number(selectedModules.itemList[index].wpOut).toFixed(0)}
{basicSetting && basicSetting.roofSizeSet == '3' && (
{getMessage('modal.module.basic.setting.module.placement.area')}
setInputMargin(e.target.value)} />
m
)}
{basicSetting && basicSetting.roofSizeSet != '3' && (
{getMessage('modal.module.basic.setting.module.surface.type')}
{roughnessCodes.length > 0 && managementState && ( handleChangeRoughness(e)} /> )}
{getMessage('modal.module.basic.setting.module.fitting.height')}
handleChangeInstallHeight(e.target.value)} />
m
{getMessage('modal.module.basic.setting.module.standard.wind.speed')}
{windSpeedCodes.length > 0 && managementState && ( handleChangeStandardWindSpeed(e)} /> )}
{getMessage('modal.module.basic.setting.module.standard.snowfall.amount')}
handleChangeVerticalSnowCover(e.target.value)} />
cm
)}
) })