지붕면 할당 조회 및 저장
This commit is contained in:
parent
993e750deb
commit
ee183401d3
@ -272,7 +272,7 @@ export function useCanvasSetting() {
|
||||
// 기본설정(PlacementShapeSetting) 조회 및 초기화
|
||||
const fetchBasicSettings = async () => {
|
||||
try {
|
||||
await get({ url: `/api/canvas-management/canvas-basic-settings/by-object/0/${correntObjectNo}` }).then((res) => {
|
||||
await get({ url: `/api/canvas-management/canvas-basic-settings/by-object/1/${correntObjectNo}` }).then((res) => {
|
||||
|
||||
let roofsRow = {}
|
||||
let roofsArray = {}
|
||||
@ -287,7 +287,7 @@ export function useCanvasSetting() {
|
||||
roofsArray = res.map((item) => {
|
||||
return {
|
||||
roofApply: true,
|
||||
roofSeq: 1,
|
||||
roofSeq: 0,
|
||||
roofMatlCd: item.roofMatlCd,
|
||||
roofWidth: item.roofWidth,
|
||||
roofHeight: item.roofHeight,
|
||||
@ -307,7 +307,7 @@ export function useCanvasSetting() {
|
||||
roofsArray = [
|
||||
{
|
||||
roofApply: true,
|
||||
roofSeq: 1,
|
||||
roofSeq: 0,
|
||||
roofMatlCd: 'ROOF_ID_WA_53A',
|
||||
roofWidth: 265,
|
||||
roofHeight: 235,
|
||||
@ -390,7 +390,7 @@ export function useCanvasSetting() {
|
||||
setCanvasSetting({ ...basicSetting })
|
||||
fetchBasicSettings()
|
||||
} catch (error) {
|
||||
swalFire({ text: getMessage(res.returnMessage), icon: 'error' })
|
||||
swalFire({ text: error.message, icon: 'error' })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'
|
||||
import { canvasState, currentMenuState, currentObjectState } from '@/store/canvasAtom'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useAxios } from '@/hooks/useAxios'
|
||||
import { useSwal } from '@/hooks/useSwal'
|
||||
import { usePolygon } from '@/hooks/usePolygon'
|
||||
import { addedRoofsState, basicSettingState, roofDisplaySelector, roofMaterialsSelector, selectedRoofMaterialSelector } from '@/store/settingAtom'
|
||||
import { correntObjectNoState, addedRoofsState, basicSettingState, roofDisplaySelector, roofMaterialsSelector, selectedRoofMaterialSelector } from '@/store/settingAtom'
|
||||
import { usePopup } from '@/hooks/usePopup'
|
||||
import { POLYGON_TYPE } from '@/common/common'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
@ -14,10 +15,12 @@ import { useCanvasMenu } from '@/hooks/common/useCanvasMenu'
|
||||
import { menuTypeState } from '@/store/menuAtom'
|
||||
import { useRoofFn } from '@/hooks/common/useRoofFn'
|
||||
import { ROOF_MATERIAL_LAYOUT } from '@/components/floor-plan/modal/placementShape/PlacementShapeSetting'
|
||||
import { globalLocaleStore } from '@/store/localeAtom'
|
||||
|
||||
// 지붕면 할당
|
||||
export function useRoofAllocationSetting(id) {
|
||||
const canvas = useRecoilValue(canvasState)
|
||||
const [correntObjectNo, setCorrentObjectNo] = useRecoilState(correntObjectNoState)
|
||||
const roofDisplay = useRecoilValue(roofDisplaySelector)
|
||||
const { drawDirectionArrow, addLengthText, splitPolygonWithLines, splitPolygonWithSeparate } = usePolygon()
|
||||
const [popupId, setPopupId] = useState(uuidv4())
|
||||
@ -35,6 +38,9 @@ export function useRoofAllocationSetting(id) {
|
||||
const [editingLines, setEditingLines] = useState([])
|
||||
const [currentRoofList, setCurrentRoofList] = useState(roofList)
|
||||
|
||||
const globalLocaleState = useRecoilValue(globalLocaleStore)
|
||||
const { get, post } = useAxios(globalLocaleState)
|
||||
|
||||
const { setSurfaceShapePattern } = useRoofFn()
|
||||
|
||||
useEffect(() => {
|
||||
@ -74,8 +80,120 @@ export function useRoofAllocationSetting(id) {
|
||||
swalFire({ text: '할당할 지붕이 없습니다.' })
|
||||
closePopup(id)
|
||||
}
|
||||
|
||||
// console.log('🚀 ~ useEffect ~ roofMaterials >>>>>>>>>>>>> :', roofMaterials)
|
||||
// console.log('🚀 ~ useEffect ~ basicSetting >>>>>>>>>>>>> :', basicSetting)
|
||||
// console.log('🚀 ~ useEffect ~ roofList >>>>>>>>>>>>> :', roofList)
|
||||
// console.log('🚀 ~ useEffect ~ currentRoofList >>>>>>>>>>>>> :', currentRoofList)
|
||||
|
||||
fetchBasicSettings()
|
||||
}, [])
|
||||
|
||||
// 조회 및 초기화
|
||||
const fetchBasicSettings = async () => {
|
||||
try {
|
||||
await get({ url: `/api/canvas-management/canvas-basic-settings/by-object/1/${correntObjectNo}` }).then((res) => {
|
||||
console.log('🚀 ~ useRoofAllocationSetting ~ fetchBasicSettings ~ res >>>>>>>>>>>>>>>>>>>>> :', res)
|
||||
let roofsArray = {}
|
||||
|
||||
if (res.length > 0) {
|
||||
roofsArray = res.map((item) => {
|
||||
return {
|
||||
roofApply: item.roofApply,
|
||||
roofSeq: item.roofSeq,
|
||||
roofMatlCd: item.roofMatlCd,
|
||||
roofWidth: item.roofWidth,
|
||||
roofHeight: item.roofHeight,
|
||||
roofHajebichi: item.roofHajebichi,
|
||||
roofGap: item.roofGap,
|
||||
roofLayout: item.roofLayout,
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
||||
roofsArray = [
|
||||
{
|
||||
roofApply: true,
|
||||
roofSeq: 0,
|
||||
roofMatlCd: 'ROOF_ID_WA_53A',
|
||||
roofWidth: 265,
|
||||
roofHeight: 235,
|
||||
roofHajebichi: 0,
|
||||
roofGap: 'HEI_455',
|
||||
roofLayout: 'P',
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
// 나머지 데이터와 함께 'roofs' 배열을 patternData에 넣음
|
||||
const patternData = {
|
||||
roofs: roofsArray, // 만들어진 roofs 배열
|
||||
}
|
||||
|
||||
console.log('fetchBasicSettings roofsArray', roofsArray)
|
||||
|
||||
// 데이터 설정
|
||||
const selectRoofs = []
|
||||
for (let i = 0; i < roofsArray.length; i++) {
|
||||
roofMaterials?.map((material) => {
|
||||
if (material.roofMatlCd === roofsArray[i].roofMatlCd) {
|
||||
selectRoofs.push({ ...material
|
||||
, selected: roofsArray[i].roofApply
|
||||
, index: roofsArray[i].roofSeq
|
||||
, id: roofsArray[i].roofMatlCd
|
||||
, width: roofsArray[i].roofWidth
|
||||
, length: roofsArray[i].roofHeight
|
||||
, hajebichi: roofsArray[i].roofHajebichi
|
||||
, raft: roofsArray[i].roofGap
|
||||
, layout: roofsArray[i].roofLayout
|
||||
})
|
||||
setCurrentRoofList(selectRoofs)
|
||||
}
|
||||
})
|
||||
}
|
||||
setBasicSetting({ ...basicSetting, roofsData: roofsArray})
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Data fetching error:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 저장
|
||||
const basicSettingSave = async () => {
|
||||
|
||||
const patternData = {
|
||||
objectNo: correntObjectNo,
|
||||
roofSizeSet: basicSetting.roofSizeSet,
|
||||
roofAngleSet: basicSetting.roofAngleSet,
|
||||
roofMaterialsAddList: currentRoofList.map((item) => ({
|
||||
roofApply: item.selected === null || item.selected === undefined ? 'true' : item.selected,
|
||||
roofSeq: item.index === null || item.index === undefined ? 0 : item.index,
|
||||
roofMatlCd: item.roofMatlCd === null || item.roofMatlCd === undefined ? 'ROOF_ID_WA_53A' : item.roofMatlCd,
|
||||
roofWidth: item.width === null || item.width === undefined ? 0 : item.width,
|
||||
roofHeight: item.length === null || item.length === undefined ? 0 : item.length,
|
||||
roofHajebichi: item.hajebichi === null || item.hajebichi === undefined ? 0 : item.hajebichi,
|
||||
roofGap: item.raft === null || item.raft === undefined ? 'HEI_455' : item.raft,
|
||||
roofLayout: item.layout === null || item.layout === undefined ? 'P' : item.layout,
|
||||
})
|
||||
),
|
||||
}
|
||||
|
||||
console.log('🚀 ~ basicSettingSave ~ patternData >>>>>>>>>>>>> :', patternData)
|
||||
|
||||
// HTTP POST 요청 보내기
|
||||
await post({ url: `/api/canvas-management/canvas-basic-settings`, data: patternData })
|
||||
.then((res) => {
|
||||
swalFire({ text: getMessage(res.returnMessage) })
|
||||
|
||||
//Recoil 설정
|
||||
// setCanvasSetting({ ...basicSetting })
|
||||
fetchBasicSettings()
|
||||
})
|
||||
.catch((error) => {
|
||||
swalFire({ text: error.message, icon: 'error' })
|
||||
})
|
||||
}
|
||||
|
||||
const onAddRoofMaterial = () => {
|
||||
if (currentRoofList.length >= 4) {
|
||||
swalFire({ type: 'alert', icon: 'error', text: getMessage('지붕재는 4개까지 선택 가능합니다.') })
|
||||
@ -103,13 +221,17 @@ export function useRoofAllocationSetting(id) {
|
||||
}
|
||||
|
||||
// 선택한 지붕재로 할당
|
||||
const handleSave = () => {
|
||||
const handleSave = () => {
|
||||
|
||||
basicSettingSave()
|
||||
|
||||
// 모두 actualSize 있으면 바로 적용 없으면 actualSize 설정
|
||||
if (checkInnerLines()) {
|
||||
if (checkInnerLines()) {
|
||||
addPopup(popupId, 1, <ActualSizeSetting id={popupId} />)
|
||||
} else {
|
||||
apply()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 지붕재 오른쪽 마우스 클릭 후 단일로 지붕재 변경 필요한 경우
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user