214 lines
6.5 KiB
JavaScript
214 lines
6.5 KiB
JavaScript
import { useRecoilState, useRecoilValue } from 'recoil'
|
|
import { useContext, useEffect, useState } from 'react'
|
|
import { GlobalDataContext } from '@/app/GlobalDataProvider'
|
|
import { useMasterController } from '@/hooks/common/useMasterController'
|
|
import { useCommonCode } from '@/hooks/common/useCommonCode'
|
|
|
|
import { selectedModuleState, moduleSelectionInitParamsState, moduleSelectionDataState } from '@/store/selectedModuleOptions'
|
|
|
|
export function useModuleSelection(props) {
|
|
const { managementState, setManagementState, managementStateLoaded } = useContext(GlobalDataContext)
|
|
|
|
const [roughnessCodes, setRoughnessCodes] = useState([]) //면조도 목록
|
|
const [windSpeedCodes, setWindSpeedCodes] = useState([]) //기준풍속 목록
|
|
const [moduleList, setModuleList] = useState([{}]) //모듈 목록
|
|
|
|
const [selectedSurfaceType, setSelectedSurfaceType] = useState({}) //선택된 면조도
|
|
const [installHeight, setInstallHeight] = useState() //설치 높이
|
|
const [standardWindSpeed, setStandardWindSpeed] = useState({}) //기준풍속
|
|
const [verticalSnowCover, setVerticalSnowCover] = useState() //수직적설량
|
|
|
|
const [selectedModules, setSelectedModules] = useRecoilState(selectedModuleState) //선택된 모듈
|
|
const [moduleSelectionInitParams, setModuleSelectionInitParams] = useRecoilState(moduleSelectionInitParamsState) //모듈 기본 데이터 ex) 면조도, 높이등등
|
|
const { getModuleTypeItemList } = useMasterController()
|
|
const { findCommonCode } = useCommonCode()
|
|
|
|
const bindInitData = () => {
|
|
setInstallHeight(managementState?.installHeight)
|
|
setStandardWindSpeed(managementState?.standardWindSpeedId)
|
|
setVerticalSnowCover(managementState?.verticalSnowCover)
|
|
setSelectedSurfaceType(managementState?.surfaceType)
|
|
}
|
|
|
|
//탭별 파라메터 초기화
|
|
useEffect(() => {
|
|
bindInitData()
|
|
const initParams = {
|
|
illuminationTp: managementState?.surfaceTypeValue, //면조도
|
|
instHt: managementState?.installHeight, //설치높이
|
|
stdWindSpeed: managementState?.standardWindSpeedId, //기준풍속
|
|
stdSnowLd: managementState?.verticalSnowCover, //기준적설량
|
|
}
|
|
|
|
if (selectedModules) {
|
|
initParams.moduleTpCd = selectedModules.itemTp
|
|
initParams.moduleItemId = selectedModules.itemId
|
|
}
|
|
|
|
setModuleSelectionInitParams(initParams)
|
|
}, [managementState])
|
|
|
|
useEffect(() => {
|
|
// 113700 면조도
|
|
const roughnessCodeList = findCommonCode('113700')
|
|
roughnessCodeList.forEach((obj) => {
|
|
obj.name = obj.clCodeNm
|
|
obj.id = obj.clCode
|
|
})
|
|
setRoughnessCodes(roughnessCodeList)
|
|
|
|
// 202000 풍속
|
|
const windCodeList = findCommonCode('202000')
|
|
windCodeList.forEach((obj) => {
|
|
obj.name = obj.clCodeNm
|
|
obj.id = obj.clCode
|
|
})
|
|
setWindSpeedCodes(windCodeList)
|
|
|
|
//지붕재 선택
|
|
const roofsIds = props.addedRoofs.filter((obj) => obj.roofMatlCd).map((obj) => obj.roofMatlCd)
|
|
|
|
if (roofsIds.length === 0) {
|
|
return
|
|
}
|
|
|
|
//새로고침시 데이터 날아가는거 방지
|
|
if (managementState === null) {
|
|
setManagementState(managementStateLoaded)
|
|
} else {
|
|
bindInitData()
|
|
}
|
|
|
|
getModuleData(roofsIds)
|
|
}, [])
|
|
|
|
const getModuleData = async (roofsIds) => {
|
|
const list = await getModuleTypeItemList(roofsIds)
|
|
if (list.data.length > 0) {
|
|
//selectbox에 이름을 넣는다
|
|
list.data.forEach((item) => {
|
|
item.name = item.itemNm
|
|
})
|
|
//셀렉트박스 데이터 초기화
|
|
setModuleList(list.data)
|
|
}
|
|
}
|
|
|
|
const handleChangeModule = (option) => {
|
|
//선택된 모듈
|
|
setSelectedModules(option) //선택값 저장
|
|
|
|
//init 데이터에 선택된 모듈 추가
|
|
setModuleSelectionInitParams({
|
|
...moduleSelectionInitParams,
|
|
moduleTpCd: option.itemTp,
|
|
moduleItemId: option.itemId,
|
|
})
|
|
}
|
|
|
|
const handleChangeSurfaceType = (option) => {
|
|
setModuleSelectionInitParams({
|
|
...moduleSelectionInitParams,
|
|
illuminationTp: option.clCode,
|
|
})
|
|
|
|
setManagementState({
|
|
...managementState,
|
|
surfaceType: option.clCodeNm,
|
|
surfaceTypeValue: option.clCode,
|
|
})
|
|
}
|
|
|
|
const handleChangeWindSpeed = (option) => {
|
|
setModuleSelectionInitParams({
|
|
...moduleSelectionInitParams,
|
|
stdWindSpeed: option.clCode,
|
|
})
|
|
|
|
setManagementState({
|
|
...managementState,
|
|
standardWindSpeedId: option.clCode,
|
|
})
|
|
}
|
|
|
|
const handleChangeInstallHeight = (option) => {
|
|
setInstallHeight(option)
|
|
setModuleSelectionInitParams({
|
|
...moduleSelectionInitParams,
|
|
instHt: option,
|
|
})
|
|
|
|
setManagementState({
|
|
...managementState,
|
|
installHeight: option,
|
|
})
|
|
}
|
|
|
|
const handleChangeVerticalSnowCover = (option) => {
|
|
setVerticalSnowCover(option)
|
|
setModuleSelectionInitParams({
|
|
...moduleSelectionInitParams,
|
|
stdSnowLd: option,
|
|
})
|
|
|
|
setManagementState({
|
|
...managementState,
|
|
verticalSnowCover: option,
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
// console.log('installHeight', installHeight)
|
|
}, [installHeight])
|
|
|
|
useEffect(() => {
|
|
// console.log('verticalSnowCover', verticalSnowCover)
|
|
}, [verticalSnowCover])
|
|
|
|
//TODO: 설치높이, 기준적설량 debounce 적용해서 추가해야됨
|
|
|
|
// useEffect(() => {
|
|
// getConstructionListData(constructionListParams)
|
|
// }, [constructionListParams])
|
|
|
|
// const getConstructionListData = async (params) => {
|
|
// if (params.trestleMkrCd && params.constMthdCd && params.roofBaseCd) {
|
|
// const optionsList = await getConstructionList(params)
|
|
// console.log('optionsList', optionsList)
|
|
// setConstructionList(optionsList.data)
|
|
// }
|
|
// }
|
|
|
|
//state 배열에 데이터 추가 함수
|
|
// const addRoofTabParams = (key, value, excludeArray = []) => {
|
|
// const index = roofTabParams.findIndex((obj) => obj.roofTab === roofTab)
|
|
// if (index !== -1) {
|
|
// roofTabParams[index][key] = value
|
|
// if (excludeArray.length > 0) {
|
|
// excludeArray.forEach((exclude) => {
|
|
// roofTabParams[index][exclude] = ''
|
|
// })
|
|
// }
|
|
// setRoofTabParams((prev) => [...prev.slice(0, index), roofTabParams[index], ...prev.slice(index + 1)])
|
|
// }
|
|
// }
|
|
|
|
return {
|
|
moduleSelectionInitParams,
|
|
selectedModules,
|
|
roughnessCodes,
|
|
windSpeedCodes,
|
|
managementState,
|
|
moduleList,
|
|
selectedSurfaceType,
|
|
installHeight,
|
|
standardWindSpeed,
|
|
verticalSnowCover,
|
|
handleChangeModule,
|
|
handleChangeSurfaceType,
|
|
handleChangeWindSpeed,
|
|
handleChangeInstallHeight,
|
|
handleChangeVerticalSnowCover,
|
|
}
|
|
}
|