diff --git a/src/components/floor-plan/modal/basic/BasicSetting.jsx b/src/components/floor-plan/modal/basic/BasicSetting.jsx index 20578b24..6d9f2a42 100644 --- a/src/components/floor-plan/modal/basic/BasicSetting.jsx +++ b/src/components/floor-plan/modal/basic/BasicSetting.jsx @@ -36,7 +36,7 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) { }, []) const placementRef = { - isChidori: useRef('true'), + isChidori: useRef('false'), setupLocation: useRef(null), isMaxSetup: useRef('false'), } diff --git a/src/components/floor-plan/modal/basic/step/Placement.jsx b/src/components/floor-plan/modal/basic/step/Placement.jsx index 8acaff70..e5acf6da 100644 --- a/src/components/floor-plan/modal/basic/step/Placement.jsx +++ b/src/components/floor-plan/modal/basic/step/Placement.jsx @@ -3,9 +3,7 @@ import { forwardRef, useState } from 'react' const Placement = forwardRef((props, refs) => { const { getMessage } = useMessage() - const [isChidori, setIsChidori] = useState('true') - - console.log(refs) + const [isChidori, setIsChidori] = useState('false') const moduleData = { header: [ @@ -107,19 +105,19 @@ const Placement = forwardRef((props, refs) => {
- +
- +
diff --git a/src/components/management/StuffDetail.jsx b/src/components/management/StuffDetail.jsx index eea328d8..3daa3a3a 100644 --- a/src/components/management/StuffDetail.jsx +++ b/src/components/management/StuffDetail.jsx @@ -10,7 +10,7 @@ import { globalLocaleStore } from '@/store/localeAtom' import { isEmptyArray, isNotEmptyArray, isObjectNotEmpty } from '@/util/common-utils' import { useMessage } from '@/hooks/useMessage' import { useForm } from 'react-hook-form' -import { useRecoilValue, useSetRecoilState } from 'recoil' +import { useRecoilValue, useSetRecoilState, useResetRecoilState, useRecoilState } from 'recoil' import { SessionContext } from '@/app/SessionProvider' import FindAddressPop from './popup/FindAddressPop' import PlanRequestPop from './popup/PlanRequestPop' @@ -20,8 +20,12 @@ import StuffPlanQGrid from './StuffPlanQGrid' import { floorPlanObjectState } from '@/store/floorPlanObjectAtom' import { ManagementContext } from '@/app/management/ManagementProvider' import DocDownOptionPop from '../estimate/popup/DocDownOptionPop' +import { stuffSearchState } from '@/store/stuffAtom' export default function StuffDetail() { + const resetStuffRecoil = useResetRecoilState(stuffSearchState) + const stuffSearchParams = useRecoilValue(stuffSearchState) + const setFloorPlanObjectNo = useSetRecoilState(floorPlanObjectState) //견적서 화면용 물건번호리코일 const [estimatePopupOpen, setEstimatePopupOpen] = useState(false) @@ -433,158 +437,160 @@ export default function StuffDetail() { }, [commonCode]) useEffect(() => { - if (isObjectNotEmpty(managementState)) { - // 도도부현API - get({ url: '/api/object/prefecture/list' }).then((res) => { - if (!isEmptyArray(res)) { - setPrefCodeList(res) - } - }) + if (objectNo) { + if (isObjectNotEmpty(managementState)) { + // 도도부현API + get({ url: '/api/object/prefecture/list' }).then((res) => { + if (!isEmptyArray(res)) { + setPrefCodeList(res) + } + }) - //1차점 : X167 T01 - //2차점 : 10X22, 201X112 - let url - let firstList - let otherList - let favList + //1차점 : X167 T01 + //2차점 : 10X22, 201X112 + let url + let firstList + let otherList + let favList - if (session?.storeId === 'T01') { - url = `/api/object/saleStore/${session?.storeId}/firstList?userId=${session?.userId}` - } else { - if (session.storeLvl === '1') { - url = `/api/object/saleStore/${session?.storeId}/list?firstFlg=1&userId=${session?.userId}` + if (session?.storeId === 'T01') { + url = `/api/object/saleStore/${session?.storeId}/firstList?userId=${session?.userId}` } else { - url = `/api/object/saleStore/${session?.storeId}/list?firstFlg=1&userId=${session?.userId}` - } - } - get({ url: url }).then((res) => { - if (!isEmptyArray(res)) { - if (session?.storeId === 'T01') { - firstList = res.filter((row) => row.saleStoreLevel === '1') - firstList.sort((a, b) => (a.saleStoreId !== 'T01') - (b.saleStoreId !== 'T01') || a.saleStoreId - b.saleStoreId) - favList = firstList.filter((row) => row.saleStoreId === 'T01' || row.priority !== 'B') - setSaleStoreList(firstList) - setFavoriteStoreList(favList) - setShowSaleStoreList(favList) - - if (managementState.firstAgentId != null) { - form.setValue('saleStoreId', managementState.firstAgentId) - setSelOptions(managementState.firstAgentId) - } else { - form.setValue('saleStoreId', managementState.saleStoreId) - setSelOptions(managementState.saleStoreId) - } - - //상세데이터의 1차점 아이디로 2차점 목록 조회하기 - - let data = managementState?.firstAgentId ? managementState.firstAgentId : managementState.saleStoreId - url = `/api/object/saleStore/${data}/list?firstFlg=0&userId=${session?.userId}` - - get({ url: url }).then((res) => { - if (!isEmptyArray(res)) { - res.map((row) => { - row.value = row.saleStoreId - row.label = row.saleStoreName - }) - - otherList = res - setOriginOtherSaleStoreList(otherList) - setOtherSaleStoreList(otherList) - } - }) + if (session.storeLvl === '1') { + url = `/api/object/saleStore/${session?.storeId}/list?firstFlg=1&userId=${session?.userId}` } else { - //1차점 셀렉트박스 - if (session?.storeLvl === '1') { - firstList = res - favList = res.filter((row) => row.priority !== 'B') - otherList = res.filter((row) => row.firstAgentYn === 'N') - - setSaleStoreList(firstList) - setFavoriteStoreList(firstList) - setShowSaleStoreList(firstList) - - setOtherSaleStoreList(otherList) - } else { - setSelOptions(res[0].saleStoreId) - form.setValue('saleStoreId', res[0].saleStoreId) - form.setValue('saleStoreLevel', res[0].storeLvl) - setSaleStoreList(res) - setFavoriteStoreList(res) - setShowSaleStoreList(res) - otherList = res.filter((row) => row.firstAgentYn === 'N') - setOtherSaleStoreList(otherList) - } + url = `/api/object/saleStore/${session?.storeId}/list?firstFlg=1&userId=${session?.userId}` } } + get({ url: url }).then((res) => { + if (!isEmptyArray(res)) { + if (session?.storeId === 'T01') { + firstList = res.filter((row) => row.saleStoreLevel === '1') + firstList.sort((a, b) => (a.saleStoreId !== 'T01') - (b.saleStoreId !== 'T01') || a.saleStoreId - b.saleStoreId) + favList = firstList.filter((row) => row.saleStoreId === 'T01' || row.priority !== 'B') + setSaleStoreList(firstList) + setFavoriteStoreList(favList) + setShowSaleStoreList(favList) - //상세데이터가 1차점이면 1차점에 세팅 - //상세데이터가 2차점이면 2차점에 세팅하고 세션으로 1차점 세팅 - if (managementState.saleStoreLevel === '1') { - setSelOptions(managementState.saleStoreId) - form.setValue('saleStoreId', managementState.saleStoreId) - form.setValue('saleStoreLevel', managementState.saleStoreLevel) - } else { - setOtherSelOptions(managementState.saleStoreId) - form.setValue('otherSaleStoreId', managementState.saleStoreId) - form.setValue('otherSaleStoreLevel', managementState.saleStoreLevel) + if (managementState.firstAgentId != null) { + form.setValue('saleStoreId', managementState.firstAgentId) + setSelOptions(managementState.firstAgentId) + } else { + form.setValue('saleStoreId', managementState.saleStoreId) + setSelOptions(managementState.saleStoreId) + } - form.setValue('saleStoreLevel', '1') - } + //상세데이터의 1차점 아이디로 2차점 목록 조회하기 - //설계의뢰No. - form.setValue('planReqNo', managementState.planReqNo) - //담당자 - form.setValue('receiveUser', managementState.receiveUser) + let data = managementState?.firstAgentId ? managementState.firstAgentId : managementState.saleStoreId + url = `/api/object/saleStore/${data}/list?firstFlg=0&userId=${session?.userId}` - //물건구분objectStatusId - setSelectObjectStatusId(managementState.objectStatusId) - form.setValue('objectStatusId', managementState.objectStatusId) + get({ url: url }).then((res) => { + if (!isEmptyArray(res)) { + res.map((row) => { + row.value = row.saleStoreId + row.label = row.saleStoreName + }) - //물건명 - form.setValue('objectName', managementState.objectName) + otherList = res + setOriginOtherSaleStoreList(otherList) + setOtherSaleStoreList(otherList) + } + }) + } else { + //1차점 셀렉트박스 + if (session?.storeLvl === '1') { + firstList = res + favList = res.filter((row) => row.priority !== 'B') + otherList = res.filter((row) => row.firstAgentYn === 'N') - //경칭코드 - setSelHonorificCode(managementState.objectNameOmit) - form.setValue('objectNameOmit', managementState.objectNameOmit) + setSaleStoreList(firstList) + setFavoriteStoreList(firstList) + setShowSaleStoreList(firstList) - //물건명 후리가나 - form.setValue('objectNameKana', managementState.objectNameKana) + setOtherSaleStoreList(otherList) + } else { + setSelOptions(res[0].saleStoreId) + form.setValue('saleStoreId', res[0].saleStoreId) + form.setValue('saleStoreLevel', res[0].storeLvl) + setSaleStoreList(res) + setFavoriteStoreList(res) + setShowSaleStoreList(res) + otherList = res.filter((row) => row.firstAgentYn === 'N') + setOtherSaleStoreList(otherList) + } + } + } - //우편번호 - form.setValue('zipNo', managementState.zipNo) + //상세데이터가 1차점이면 1차점에 세팅 + //상세데이터가 2차점이면 2차점에 세팅하고 세션으로 1차점 세팅 + if (managementState.saleStoreLevel === '1') { + setSelOptions(managementState.saleStoreId) + form.setValue('saleStoreId', managementState.saleStoreId) + form.setValue('saleStoreLevel', managementState.saleStoreLevel) + } else { + setOtherSelOptions(managementState.saleStoreId) + form.setValue('otherSaleStoreId', managementState.saleStoreId) + form.setValue('otherSaleStoreLevel', managementState.saleStoreLevel) - //도도부현 / 주소 - setPrefValue(managementState.prefId) - form.setValue('prefId', managementState.prefId) - form.setValue('prefName', managementState.prefName) - form.setValue('address', managementState.address) - //발전시뮬 - form.setValue('areaId', managementState.areaId) + form.setValue('saleStoreLevel', '1') + } - //기준풍속 - form.setValue('standardWindSpeedId', managementState.standardWindSpeedId) - //수직적설량 - form.setValue('verticalSnowCover', managementState.verticalSnowCover) - //한랭지대책시행 coldRegionFlg 1이면 true - form.setValue('coldRegionFlg', managementState.coldRegionFlg === '1' ? true : false) + //설계의뢰No. + form.setValue('planReqNo', managementState.planReqNo) + //담당자 + form.setValue('receiveUser', managementState.receiveUser) - //면조도구분 surfaceType null로 내려오면 셋팅 안하고 저장할때 필수값 체크하도록 - // form.setValue('surfaceType', 'Ⅱ') - // form.setValue('surfaceType', 'Ⅲ・Ⅳ') - form.setValue('surfaceType', managementState.surfaceType) - //염해지역용아이템사용 saltAreaFlg 1이면 true - form.setValue('saltAreaFlg', managementState.saltAreaFlg === '1' ? true : false) - //설치높이 - form.setValue('installHeight', managementState.installHeight) - //계약조건 null로 내려오면 0으로 디폴트셋팅 - if (managementState.conType === null) { - form.setValue('conType', '0') - } else { - form.setValue('conType', managementState.conType) - } - //메모 - form.setValue('remarks', managementState.remarks) - }) + //물건구분objectStatusId + setSelectObjectStatusId(managementState.objectStatusId) + form.setValue('objectStatusId', managementState.objectStatusId) + + //물건명 + form.setValue('objectName', managementState.objectName) + + //경칭코드 + setSelHonorificCode(managementState.objectNameOmit) + form.setValue('objectNameOmit', managementState.objectNameOmit) + + //물건명 후리가나 + form.setValue('objectNameKana', managementState.objectNameKana) + + //우편번호 + form.setValue('zipNo', managementState.zipNo) + + //도도부현 / 주소 + setPrefValue(managementState.prefId) + form.setValue('prefId', managementState.prefId) + form.setValue('prefName', managementState.prefName) + form.setValue('address', managementState.address) + //발전시뮬 + form.setValue('areaId', managementState.areaId) + + //기준풍속 + form.setValue('standardWindSpeedId', managementState.standardWindSpeedId) + //수직적설량 + form.setValue('verticalSnowCover', managementState.verticalSnowCover) + //한랭지대책시행 coldRegionFlg 1이면 true + form.setValue('coldRegionFlg', managementState.coldRegionFlg === '1' ? true : false) + + //면조도구분 surfaceType null로 내려오면 셋팅 안하고 저장할때 필수값 체크하도록 + // form.setValue('surfaceType', 'Ⅱ') + // form.setValue('surfaceType', 'Ⅲ・Ⅳ') + form.setValue('surfaceType', managementState.surfaceType) + //염해지역용아이템사용 saltAreaFlg 1이면 true + form.setValue('saltAreaFlg', managementState.saltAreaFlg === '1' ? true : false) + //설치높이 + form.setValue('installHeight', managementState.installHeight) + //계약조건 null로 내려오면 0으로 디폴트셋팅 + if (managementState.conType === null) { + form.setValue('conType', '0') + } else { + form.setValue('conType', managementState.conType) + } + //메모 + form.setValue('remarks', managementState.remarks) + }) + } } }, [managementState]) @@ -1267,7 +1273,7 @@ export default function StuffDetail() { if (res.status === 201) { alert(getMessage('stuff.detail.save')) setFloorPlanObjectNo({ floorPlanObjectNo: objectNo }) - router.push(`/management/stuff/detail?objectNo=${res.data.objectNo.toString()}`) + router.push(`/management/stuff/detail?objectNo=${res.data.objectNo.toString()}`, { scroll: false }) } }) } else { @@ -1276,8 +1282,7 @@ export default function StuffDetail() { if (res.status === 201) { setFloorPlanObjectNo({ floorPlanObjectNo: res.data.objectNo }) alert(getMessage('stuff.detail.save')) - // router.refresh() - router.push(`/management/stuff/detail?objectNo=${res.data.objectNo.toString()}`) + router.push(`/management/stuff/detail?objectNo=${res.data.objectNo.toString()}`, { scroll: false }) } }) } @@ -1312,6 +1317,7 @@ export default function StuffDetail() { tempFlg: '1', workNo: null, workName: null, + objectNo: objectNo ? objectNo : '', } //1차점 or 2차점 안고르고 임시저장하면 @@ -1320,16 +1326,27 @@ export default function StuffDetail() { params.saleStoreLevel = session.storeLvl } - await promisePost({ url: '/api/object/save-object', data: params }).then((res) => { - if (res.status === 201) { - alert(getMessage('stuff.detail.tempSave.message1')) - router.push(`${pathname}?objectNo=${res.data.objectNo.toString()}`) - } - }) + const apiUrl = '/api/object/save-object' + if (objectNo) { + await promisePut({ url: apiUrl, data: params }).then((res) => { + if (res.status === 201) { + alert(getMessage('stuff.detail.save')) + router.push(`/management/stuff/tempdetail?objectNo=${res.data.objectNo.toString()}`, { scroll: false }) + } + }) + } else { + await promisePost({ url: apiUrl, data: params }).then((res) => { + if (res.status === 201) { + alert(getMessage('stuff.detail.save')) + router.push(`/management/stuff/tempdetail?objectNo=${res.data.objectNo.toString()}`, { scroll: false }) + } + }) + } } // 물건삭제 const onDelete = () => { + // console.log('검색조건리코일값:::::', stuffSearchParams) const specificationConfirmDate = managementState.specificationConfirmDate if (specificationConfirmDate != null) { alert(getMessage('stuff.detail.delete.message1')) @@ -1337,6 +1354,12 @@ export default function StuffDetail() { if (confirm(getMessage('common.message.data.delete'))) { del({ url: `/api/object/${objectNo}` }).then(() => { setFloorPlanObjectNo({ floorPlanObjectNo: '' }) + // console.log('초기화::::::::::') + // resetStuffRecoil() + // stuffSearchParams.code = 'DELETE' + // stuffSearchParams.schSelSaleStoreId = '' + // stuffSearchParams.schOtherSelSaleStoreId = '' + // console.log('판매점 초기화도') router.push('/management/stuff') }) } diff --git a/src/hooks/module/useModuleBasicSetting.js b/src/hooks/module/useModuleBasicSetting.js index 4f9e829d..2a925350 100644 --- a/src/hooks/module/useModuleBasicSetting.js +++ b/src/hooks/module/useModuleBasicSetting.js @@ -10,6 +10,7 @@ import { useEvent } from '@/hooks/useEvent' import { POLYGON_TYPE, BATCH_TYPE } from '@/common/common' import * as turf from '@turf/turf' +import next from 'next' export function useModuleBasicSetting() { const canvas = useRecoilValue(canvasState) @@ -475,13 +476,6 @@ export function useModuleBasicSetting() { const bbox = turf.bbox(difference) - let surfaceBbox = { - minX: bbox[0], - maxX: bbox[2], - minY: bbox[1], - maxY: bbox[3], - } - let width = maxLengthLine.flowDirection === 'right' || maxLengthLine.flowDirection === 'left' ? 172.2 : 113.4 let height = maxLengthLine.flowDirection === 'right' || maxLengthLine.flowDirection === 'left' ? 113.4 : 172.2 @@ -490,6 +484,7 @@ export function useModuleBasicSetting() { width = moduleSetupSurface.flowDirection === 'south' || moduleSetupSurface.flowDirection === 'north' ? 172.2 : 113.4 height = moduleSetupSurface.flowDirection === 'south' || moduleSetupSurface.flowDirection === 'north' ? 113.4 : 172.2 } + let cols = Math.floor((bbox[2] - bbox[0]) / width) let rows = Math.floor((bbox[3] - bbox[1]) / height) @@ -599,6 +594,7 @@ export function useModuleBasicSetting() { parentId: moduleSetupSurface.parentId, lineCol: col, lineRow: row, + name: 'module', }) tempModule.setViewLengthText(false) canvas?.add(tempModule) @@ -619,6 +615,7 @@ export function useModuleBasicSetting() { parentId: moduleSetupSurface.parentId, lineCol: col, lineRow: row, + name: 'module', }) canvas?.add(tempModule) moduleSetupArray.push(tempModule) @@ -768,76 +765,41 @@ export function useModuleBasicSetting() { return hull } - function calculatePerpendicularLine(hypotenuseStart, hypotenuseEnd, height) { - const { x: x1, y: y1 } = hypotenuseStart - const { x: x2, y: y2 } = hypotenuseEnd + const calcMinXByHeightDistance = (nowSurface, index, reverse) => { + function calculateSlopeIntercept(x1, y1, x2, y2) { + console.log('Intercept', x1, y1, x2, y2) - // 1. 빗변의 기울기 계산 - const slope = (y2 - y1) / (x2 - x1) + const slope = (y2 - y1) / (x2 - x1) + const intercept = y1 - slope * x1 - // 2. 중점 계산 - const xC = (x1 + x2) / 2 - const yC = (y1 + y2) / 2 - - // 3. 수직 기울기의 정규화 인자 계산 - const norm = Math.sqrt(1 + Math.pow(slope, 2)) - - // 4. 수직선의 끝점 계산 - const xOffset = -height / norm - const yOffset = (height * slope) / norm - - const point1 = { x: xC + xOffset, y: yC + yOffset } - const point2 = { x: xC - xOffset, y: yC - yOffset } - - return { point1, point2 } - } - - // 예제 사용 - const hypotenuseStart = { x: 2, y: 3 } - const hypotenuseEnd = { x: 8, y: 9 } - const height = 4 - - const result = calculatePerpendicularLine(hypotenuseStart, hypotenuseEnd, height) - console.log(result) - - const calcMinXByHeightDistance = (surface) => { - let minXIndex = surface.lines.reduce((minIdx, current, index, arr) => { - console.log('reduce', minIdx, current, index, arr) - - return current.x1 < arr[minIdx].x1 ? index : minIdx - }, surface.lines[0].x1) - - console.log('minXIndex', minXIndex) - - function calculateIntersection(diagonalA, lineB) { - // Diagonal A coordinates - const { x1: ax1, y1: ay1, x2: ax2, y2: ay2 } = diagonalA - - // Line B coordinates - const { x2: bx2, y2: by2 } = lineB - - // Calculate slope (m) and intercept (c) for diagonal A - const slopeA = (ay2 - ay1) / (ax2 - ax1) - const interceptA = ay1 - slopeA * ax1 - - // Use fixed y (from lineB's y2) - const yFixed = by2 - - // Calculate x on diagonal A where y = yFixed - const xFixed = (yFixed - interceptA) / slopeA - - // Return the intersection point - return { x: xFixed, y: yFixed } + return { slope, intercept } } - console.log('line', line) + let prevLines = nowSurface.lines[(index - 1 + nowSurface.lines.length) % nowSurface.lines.length] + let nextLines = nowSurface.lines[index] - // Example usage: - const diagonalA = { x1: 490.4, y1: 94.7, x2: 303.7, y2: 654.7 } - const lineB = { x1: 303.7, y1: 654.7, x2: 303.7, y2: 541.3 } + // 선분 정보 + const l1 = prevLines + const l2 = nextLines + const lineLength = 172.2 - const intersection = calculateIntersection(diagonalA, lineB) - console.log(`Intersection point: x = ${intersection.x}, y = ${intersection.y}`) + // l1과 l2의 기울기 및 절편 + let { slope: m1, intercept: b1 } = calculateSlopeIntercept(l1.x1, l1.y1, l1.x2, l1.y2) + let { slope: m2, intercept: b2 } = calculateSlopeIntercept(l2.x1, l2.y1, l2.x2, l2.y2) + + console.log(m1, b1, m2, b2) + + // 가로선 x1 계산 + const x1 = (m2 * lineLength + b2 - b1) / (m1 - m2) + const x2 = x1 + lineLength // 끝점 x2 + + // 가로선 y값 계산 + const y0 = m1 * x1 + b1 + + // 결과 출력 + + console.log({ x1: x1, y1: y0, x2: x2, y2: y0 }) + return { x1: x1, y1: y0, x2: x2, y2: y0 } } return {