diff --git a/src/components/floor-plan/CanvasMenu.jsx b/src/components/floor-plan/CanvasMenu.jsx index 99694f12..f6f2f481 100644 --- a/src/components/floor-plan/CanvasMenu.jsx +++ b/src/components/floor-plan/CanvasMenu.jsx @@ -38,6 +38,10 @@ import DocDownOptionPop from '../estimate/popup/DocDownOptionPop' import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider' import EstimateCopyPop from '../estimate/popup/EstimateCopyPop' +import { floorPlanObjectState } from '@/store/floorPlanObjectAtom' +import { pwrGnrSimTypeState } from '@/store/simulatorAtom' +import { useAxios } from '@/hooks/useAxios' + export default function CanvasMenu(props) { const { menuNumber, setMenuNumber } = props const pathname = usePathname() @@ -189,6 +193,54 @@ export default function CanvasMenu(props) { return ([2, 3].some((num) => num === canvasSetting?.roofSizeSet) && menu.index === 2) || (menuNumber === 4 && menu.index === 2) } + // 발전시물레이션 Excel/PDF 다운 + const { promisePost } = useAxios(globalLocale) + const objectRecoil = useRecoilValue(floorPlanObjectState) + const pwrGnrSimTypeRecoil = useRecoilValue(pwrGnrSimTypeState) + + const { plans } = usePlan() + const plan = plans.find((plan) => plan.isCurrent === true) + + const handleExcelPdfFileDown = async (donwloadType, drawingFlg) => { + const url = '/api/estimate/excel-download' + + const params = { + objectNo: objectRecoil.floorPlanObjectNo, + planNo: plan?.id, + schDownload: donwloadType, + schDrawingFlg: drawingFlg, + pwrGnrSimType: pwrGnrSimTypeRecoil.type, + } + + const options = { responseType: 'blob' } + await promisePost({ url: url, data: params, option: options }) + .then((resultData) => { + if (resultData) { + let fileName = 'unknow' + const blob = new Blob([resultData.data], { type: resultData.headers['content-type'] || 'application/octet-stream' }) + const fileUrl = window.URL.createObjectURL(blob) + + const link = document.createElement('a') + link.href = fileUrl + + //서버에서 내려오는 파일명 + const contentDisposition = resultData.headers['content-disposition'] + if (contentDisposition) { + fileName = contentDisposition.split('filename=')[1].replace(/['"]/g, '') + } + + link.download = fileName + document.body.appendChild(link) + link.click() + link.remove() + window.URL.revokeObjectURL(fileUrl) + } + }) + .catch((error) => { + alert('File does not exist.') + }) + } + return (