👀fix: 플랜 복사 시 모듈 데이터 처리
This commit is contained in:
parent
c453ede3db
commit
b227a7deea
@ -85,5 +85,5 @@ export function useCanvasPopupStatusController(param = 1) {
|
||||
},
|
||||
)
|
||||
|
||||
return { handleModuleSelectionTotal, trigger }
|
||||
return { getModuleSelection, handleModuleSelectionTotal, trigger }
|
||||
}
|
||||
|
||||
@ -575,7 +575,7 @@ export function useCanvasSetting(executeEffect = true) {
|
||||
|
||||
/** 모듈 선택 데이터 초기화 */
|
||||
resetModuleSelectionData()
|
||||
moduleSelectedDataTrigger({ common: {}, module: {}, roofConstructions: [] })
|
||||
// moduleSelectedDataTrigger({ common: {}, module: {}, roofConstructions: [] })
|
||||
const isModuleExist = canvas.getObjects().some((obj) => obj.name === POLYGON_TYPE.MODULE)
|
||||
if (!isModuleExist) {
|
||||
resetSelectedModules()
|
||||
|
||||
@ -9,13 +9,16 @@ import { canvasState, currentCanvasPlanState, plansState, canvasSettingState } f
|
||||
import { useAxios } from '@/hooks/useAxios'
|
||||
import { useMessage } from '@/hooks/useMessage'
|
||||
import { useSwal } from '@/hooks/useSwal'
|
||||
import { SAVE_KEY } from '@/common/common'
|
||||
import { POLYGON_TYPE, SAVE_KEY } from '@/common/common'
|
||||
import { removeImage } from '@/lib/fileAction'
|
||||
import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider'
|
||||
import { useEstimateController } from '@/hooks/floorPlan/estimate/useEstimateController'
|
||||
import { outerLinePointsState } from '@/store/outerLineAtom'
|
||||
import { placementShapeDrawingPointsState } from '@/store/placementShapeDrawingAtom'
|
||||
import { useCanvasSetting } from '@/hooks/option/useCanvasSetting'
|
||||
import { compasDegAtom } from '@/store/orientationAtom'
|
||||
import { moduleSelectionDataState, selectedModuleState } from '@/store/selectedModuleOptions'
|
||||
import { useCanvasPopupStatusController } from './common/useCanvasPopupStatusController'
|
||||
|
||||
/**
|
||||
* 플랜 처리 훅
|
||||
@ -38,7 +41,7 @@ export function usePlan(params = {}) {
|
||||
|
||||
const { swalFire } = useSwal()
|
||||
const { getMessage } = useMessage()
|
||||
const { get, promisePost, promisePut, promiseDel, promiseGet } = useAxios()
|
||||
const { get, post, promisePost, promisePut, promiseDel, promiseGet } = useAxios()
|
||||
|
||||
const { setEstimateContextState } = useEstimateController()
|
||||
|
||||
@ -48,6 +51,14 @@ export function usePlan(params = {}) {
|
||||
const { fetchBasicSettings, basicSettingCopySave } = useCanvasSetting()
|
||||
const [canvasSetting, setCanvasSetting] = useRecoilState(canvasSettingState)
|
||||
|
||||
/**
|
||||
* 플랜 복사 시 모듈이 있을경우 모듈 데이터 복사하기 위한 처리
|
||||
*/
|
||||
const { getModuleSelection } = useCanvasPopupStatusController()
|
||||
const [compasDeg, setCompasDeg] = useRecoilState(compasDegAtom)
|
||||
const [moduleSelectionDataStore, setModuleSelectionDataStore] = useRecoilState(moduleSelectionDataState)
|
||||
const [selectedModules, setSelectedModules] = useRecoilState(selectedModuleState)
|
||||
|
||||
/**
|
||||
* 마우스 포인터의 가이드라인 제거
|
||||
*/
|
||||
@ -191,54 +202,93 @@ export function usePlan(params = {}) {
|
||||
objectNo: objectNo,
|
||||
copyFlg: '0',
|
||||
}
|
||||
try {
|
||||
const res = await promisePost({ url: '/api/object/add-plan', data: planData })
|
||||
let newPlan = {
|
||||
id: res.data.canvasId,
|
||||
objectNo: objectNo,
|
||||
planNo: res.data.planNo,
|
||||
userId: userId,
|
||||
canvasStatus: '',
|
||||
isCurrent: true,
|
||||
bgImageName: null,
|
||||
mapPositionAddress: null,
|
||||
}
|
||||
|
||||
if (isInitPlan) {
|
||||
/* 초기 플랜 생성인 경우 플랜 목록 초기화 */
|
||||
setCurrentCanvasPlan(newPlan)
|
||||
setPlans([newPlan])
|
||||
const res = await promisePost({ url: '/api/object/add-plan', data: planData })
|
||||
let newPlan = {
|
||||
id: res.data.canvasId,
|
||||
objectNo: objectNo,
|
||||
planNo: res.data.planNo,
|
||||
userId: userId,
|
||||
canvasStatus: '',
|
||||
isCurrent: true,
|
||||
bgImageName: null,
|
||||
mapPositionAddress: null,
|
||||
}
|
||||
|
||||
/* 플랜 추가 시 배치면초기설정 정보 조회 */
|
||||
fetchBasicSettings(newPlan.planNo, null)
|
||||
} else {
|
||||
if (isCopy) {
|
||||
/* 복제 플랜 생성인 경우 현재 캔버스 데이터를 복제 */
|
||||
newPlan.canvasStatus = currentCanvasData()
|
||||
newPlan.bgImageName = currentCanvasPlan?.bgImageName ?? null
|
||||
newPlan.mapPositionAddress = currentCanvasPlan?.mapPositionAddress ?? null
|
||||
if (isInitPlan) {
|
||||
/* 초기 플랜 생성인 경우 플랜 목록 초기화 */
|
||||
setCurrentCanvasPlan(newPlan)
|
||||
setPlans([newPlan])
|
||||
|
||||
/* 복제 시 배치면 초기설정 복사 */
|
||||
basicSettingCopySave({
|
||||
...canvasSetting,
|
||||
/* 플랜 추가 시 배치면초기설정 정보 조회 */
|
||||
fetchBasicSettings(newPlan.planNo, null)
|
||||
} else {
|
||||
if (isCopy) {
|
||||
/* 복제 플랜 생성인 경우 현재 캔버스 데이터를 복제 */
|
||||
newPlan.canvasStatus = currentCanvasData()
|
||||
newPlan.bgImageName = currentCanvasPlan?.bgImageName ?? null
|
||||
newPlan.mapPositionAddress = currentCanvasPlan?.mapPositionAddress ?? null
|
||||
|
||||
/* 복제 시 배치면 초기설정 복사 */
|
||||
basicSettingCopySave({
|
||||
...canvasSetting,
|
||||
planNo: newPlan.planNo,
|
||||
selectedRoofMaterial: {
|
||||
...canvasSetting.selectedRoofMaterial,
|
||||
planNo: newPlan.planNo,
|
||||
selectedRoofMaterial: {
|
||||
...canvasSetting.selectedRoofMaterial,
|
||||
planNo: newPlan.planNo,
|
||||
},
|
||||
roofsData: canvasSetting.roofsData.map((roof) => ({
|
||||
...roof,
|
||||
planNo: newPlan.planNo,
|
||||
})),
|
||||
})
|
||||
}
|
||||
setCurrentCanvasPlan(newPlan)
|
||||
setPlans((plans) => [...plans.map((plan) => ({ ...plan, isCurrent: false })), newPlan])
|
||||
},
|
||||
roofsData: canvasSetting.roofsData.map((roof) => ({
|
||||
...roof,
|
||||
planNo: newPlan.planNo,
|
||||
})),
|
||||
})
|
||||
|
||||
swalFire({ text: getMessage('plan.message.save') })
|
||||
/**
|
||||
* 방위 데이터 복사
|
||||
*/
|
||||
const sourceDegree = await getModuleSelection(1)
|
||||
console.log('🚀 ~ sourceDegree:', sourceDegree)
|
||||
const degreeData = {
|
||||
objectNo,
|
||||
planNo: parseInt(newPlan.planNo),
|
||||
popupType: 1,
|
||||
popupStatus: sourceDegree.popupStatus,
|
||||
}
|
||||
console.log('🚀 ~ postObjectPlan ~ degreeData:', degreeData)
|
||||
await post({ url: `/api/v1/canvas-popup-status`, data: degreeData })
|
||||
/** 리코일 세팅 */
|
||||
setCompasDeg(sourceDegree.popupStatus)
|
||||
|
||||
/**
|
||||
* 모듈 선택 데이터 복사
|
||||
*/
|
||||
const moduleSelectionData = await getModuleSelection(2)
|
||||
console.log('🚀 ~ moduleSelectionData:', moduleSelectionData)
|
||||
const moduleStatus = moduleSelectionData.popupStatus.replace(/"/g, '\"')
|
||||
const moduleData = {
|
||||
objectNo,
|
||||
planNo: parseInt(newPlan.planNo),
|
||||
popupType: 2,
|
||||
popupStatus: moduleStatus,
|
||||
}
|
||||
console.log('🚀 ~ postObjectPlan ~ moduleData:', moduleData)
|
||||
await post({ url: `/api/v1/canvas-popup-status`, data: moduleData })
|
||||
const copyData = JSON.parse(moduleStatus)
|
||||
console.log('🚀 ~ postObjectPlan ~ copyData:', copyData)
|
||||
|
||||
/** 리코일 세팅 */
|
||||
setModuleSelectionDataStore(copyData)
|
||||
if (copyData.module) setSelectedModules(copyData.module)
|
||||
const roofSurfaceList = canvas.getObjects().filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE)
|
||||
const modules = canvas.getObjects().filter((obj) => obj.name === POLYGON_TYPE.MODULE)
|
||||
roofSurfaceList.forEach((surface) => {
|
||||
surface.modules = modules.filter((module) => module.surfaceId === surface.id)
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
swalFire({ text: error.response.data.message, icon: 'error' })
|
||||
setCurrentCanvasPlan(newPlan)
|
||||
setPlans((plans) => [...plans.map((plan) => ({ ...plan, isCurrent: false })), newPlan])
|
||||
|
||||
swalFire({ text: getMessage('plan.message.save') })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user