93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
import { useContext } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
|
|
import { useRecoilValue } from 'recoil'
|
|
|
|
import { useAxios } from '@/hooks/useAxios'
|
|
import { useSwal } from '@/hooks/useSwal'
|
|
import { GlobalDataContext } from '@/app/GlobalDataProvider'
|
|
import { QcastContext } from '@/app/QcastProvider'
|
|
import { currentCanvasPlanState } from '@/store/canvasAtom'
|
|
import { loginUserStore } from '@/store/commonAtom'
|
|
import { useTrestle } from '@/hooks/module/useTrestle'
|
|
import { usePlan } from '@/hooks/usePlan'
|
|
|
|
export function useEstimate() {
|
|
const { managementState } = useContext(GlobalDataContext)
|
|
const { setIsGlobalLoading } = useContext(QcastContext)
|
|
const router = useRouter()
|
|
const loginUserState = useRecoilValue(loginUserStore)
|
|
const currentCanvasPlan = useRecoilValue(currentCanvasPlanState)
|
|
|
|
const { promisePost } = useAxios()
|
|
const { swalFire } = useSwal()
|
|
|
|
const { setAllModuleSurfaceIsComplete } = useTrestle()
|
|
const { saveCanvas } = usePlan()
|
|
|
|
/**
|
|
* 도면 견적서 저장
|
|
*
|
|
* @param {Object} estimateParam - 견적서 저장 데이터
|
|
*/
|
|
const saveEstimate = async (estimateParam) => {
|
|
const userId = loginUserState.userId
|
|
const saleStoreId = managementState.saleStoreId
|
|
const objectNo = currentCanvasPlan.objectNo
|
|
const planNo = currentCanvasPlan.planNo
|
|
const slope = estimateParam.roofSurfaceList[0].slope
|
|
const angle = estimateParam.roofSurfaceList[0].angle
|
|
const surfaceType = managementState.surfaceType
|
|
const setupHeight = managementState.installHeight
|
|
const standardWindSpeedId = managementState.standardWindSpeedId
|
|
const snowfall = managementState.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 })
|
|
.then(async () => {
|
|
setAllModuleSurfaceIsComplete(true)
|
|
|
|
// 캔버스 저장
|
|
await saveCanvas(false)
|
|
setIsGlobalLoading(false)
|
|
|
|
/* 견적서 저장이 완료되면 견적서 페이지로 이동 */
|
|
// moveEstimate(planNo, objectNo)
|
|
})
|
|
.catch((error) => {
|
|
setIsGlobalLoading(false)
|
|
swalFire({ text: error.message, icon: 'error' })
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 견적서 페이지로 이동
|
|
*
|
|
* @param {string} planNo - 플랜번호
|
|
* @param {string} objectNo - 물건번호
|
|
*/
|
|
const moveEstimate = (planNo, objectNo) => {
|
|
router.push(`/floor-plan/estimate/5?pid=${planNo}&objectNo=${objectNo}`)
|
|
}
|
|
|
|
return {
|
|
saveEstimate,
|
|
moveEstimate,
|
|
}
|
|
}
|