feat: 도면 견적서 저장 api 호출 함수 추가

This commit is contained in:
Daseul Kim 2025-02-04 18:18:53 +09:00
parent 2eedb90cb2
commit 09507122be
3 changed files with 69 additions and 8 deletions

View File

@ -21,6 +21,7 @@ import { selectedModuleState } from '@/store/selectedModuleOptions'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { stepUpListDataState } from '@/store/circuitTrestleAtom' import { stepUpListDataState } from '@/store/circuitTrestleAtom'
import { useEstimate } from '@/hooks/useEstimate'
const ALLOCATION_TYPE = { const ALLOCATION_TYPE = {
AUTO: 'auto', AUTO: 'auto',
@ -31,6 +32,7 @@ export default function CircuitTrestleSetting({ id }) {
const { closePopup } = usePopup() const { closePopup } = usePopup()
const { apply } = useTrestle() const { apply } = useTrestle()
const { swalFire } = useSwal() const { swalFire } = useSwal()
const { saveEstimate } = useEstimate()
const canvas = useRecoilValue(canvasState) const canvas = useRecoilValue(canvasState)
const [makers, setMakers] = useRecoilState(makersState) const [makers, setMakers] = useRecoilState(makersState)
@ -336,8 +338,10 @@ export default function CircuitTrestleSetting({ id }) {
}) })
const result = await apply() const result = await apply()
if (result) {
await saveEstimate(result)
}
removeNotAllocationModules() removeNotAllocationModules()
apply()
} }
const removeNotAllocationModules = () => { const removeNotAllocationModules = () => {

View File

@ -1,18 +1,16 @@
import { useRecoilState, useRecoilValue } from 'recoil' import { useRecoilValue } from 'recoil'
import { canvasState, currentAngleTypeSelector } from '@/store/canvasAtom' import { canvasState, currentAngleTypeSelector } from '@/store/canvasAtom'
import { POLYGON_TYPE } from '@/common/common' import { POLYGON_TYPE } from '@/common/common'
import { moduleSelectionDataState } from '@/store/selectedModuleOptions' import { moduleSelectionDataState } from '@/store/selectedModuleOptions'
import { getDegreeByChon, getTrestleLength } from '@/util/canvas-util' import { getDegreeByChon, getTrestleLength } from '@/util/canvas-util'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { useMasterController } from '@/hooks/common/useMasterController' import { useMasterController } from '@/hooks/common/useMasterController'
import { estimateParamAtom } from '@/store/estimateAtom'
// 회로 및 가대설정 // 회로 및 가대설정
export const useTrestle = () => { export const useTrestle = () => {
const canvas = useRecoilValue(canvasState) const canvas = useRecoilValue(canvasState)
const moduleSelectionData = useRecoilValue(moduleSelectionDataState) //다음으로 넘어가는 최종 데이터 const moduleSelectionData = useRecoilValue(moduleSelectionDataState) //다음으로 넘어가는 최종 데이터
const { getQuotationItem } = useMasterController() const { getQuotationItem } = useMasterController()
const [estimateParam, setEstimateParam] = useRecoilState(estimateParamAtom)
const currentAngleType = useRecoilValue(currentAngleTypeSelector) const currentAngleType = useRecoilValue(currentAngleTypeSelector)
const apply = () => { const apply = () => {
@ -462,7 +460,7 @@ export const useTrestle = () => {
return setEstimateData() return setEstimateData()
} catch (e) { } catch (e) {
return false return null
} }
} }
@ -480,7 +478,7 @@ export const useTrestle = () => {
//견적서 itemList 조회 //견적서 itemList 조회
const res = await getQuotationItem(params) const res = await getQuotationItem(params)
if (!res.data) { if (!res.data) {
return false return null
} }
const itemList = res.data const itemList = res.data
//northArrangement 북면 설치 여부 //northArrangement 북면 설치 여부
@ -540,10 +538,10 @@ export const useTrestle = () => {
} }
}) })
setEstimateParam({ ...estimateParam, itemList, northArrangement, roofSurfaceList, circuitItemList }) const estimateParam = { itemList, northArrangement, roofSurfaceList, circuitItemList }
// 정상적으로 완료 되면 true 반환 // 정상적으로 완료 되면 true 반환
return true return estimateParam
} }
const getNorthArrangement = () => { const getNorthArrangement = () => {

59
src/hooks/useEstimate.js Normal file
View File

@ -0,0 +1,59 @@
import { useContext } from 'react'
import { useRecoilValue } from 'recoil'
import { useAxios } from '@/hooks/useAxios'
import { useSwal } from '@/hooks/useSwal'
import { GlobalDataContext } from '@/app/GlobalDataProvider'
import { currentCanvasPlanState } from '@/store/canvasAtom'
import { loginUserStore } from '@/store/commonAtom'
export function useEstimate() {
const { managementStateLoaded } = useContext(GlobalDataContext)
const loginUserState = useRecoilValue(loginUserStore)
const currentCanvasPlan = useRecoilValue(currentCanvasPlanState)
const { swalFire } = useSwal()
const { promisePost } = useAxios()
/**
* 도면 견적서 저장
*/
const saveEstimate = async (estimateParam) => {
const userId = loginUserState.userId
const saleStoreId = managementStateLoaded.saleStoreId
const objectNo = currentCanvasPlan.objectNo
const planNo = currentCanvasPlan.planNo
const slope = estimateParam.roofSurfaceList[0].slope
const angle = estimateParam.roofSurfaceList[0].angle
const surfaceType = managementStateLoaded.surfaceType
const setupHeight = managementStateLoaded.installHeight
const standardWindSpeedId = managementStateLoaded.standardWindSpeedId
const snowfall = managementStateLoaded.verticalSnowCover
const drawingFlg = '1'
const saveEstimateData = {
...estimateParam,
userId: userId,
saleStoreId: saleStoreId,
objectNo: objectNo,
planNo: planNo,
slope: slope,
angle: angle,
surfaceType: surfaceType,
setupHeight: setupHeight,
standardWindSpeedId: standardWindSpeedId,
snowfall: snowfall,
drawingFlg: drawingFlg,
}
await promisePost({ url: '/api/estimate/save-estimate', data: saveEstimateData }).catch((error) => {
swalFire({ text: error.message, icon: 'error' })
})
}
return {
saveEstimate,
}
}