'use client' import { useState, useContext } from 'react' import { useMessage } from '@/hooks/useMessage' import { useAxios } from '@/hooks/useAxios' import { useRecoilValue } from 'recoil' import { floorPlanObjectState, estimateState } from '@/store/floorPlanObjectAtom' import { usePathname, useSearchParams } from 'next/navigation' import { QcastContext } from '@/app/QcastProvider' export default function DocDownOptionPop({ planNo, setEstimatePopupOpen, docDownPopLockFlg }) { const { setIsGlobalLoading } = useContext(QcastContext) const { getMessage } = useMessage() const { promisePost } = useAxios() const pathName = usePathname() const searchParams = useSearchParams() //EXCEL, PDF 구분 const [schDownload, setSchDownload] = useState('EXCEL') //다운로드 파일 EXCEL const [schUnitPriceFlg, setSchUnitPriceFlg] = useState('0') //견적제출서 표시명 const [schDisplayFlg, setSchDisplayFlg] = useState('0') //가대 중량표 포함(포함:1 미포함 : 0) const [schWeightFlg, setSchWeightFlg] = useState('1') //도면/시뮬레이션 파일 포함 const [schDrawingFlg, setSchDrawingFlg] = useState('1') // recoil 물건번호 const objectRecoil = useRecoilValue(floorPlanObjectState) const estimateRecoilState = useRecoilValue(estimateState) //문서 다운로드 const handleFileDown = async () => { const url = '/api/estimate/excel-download' let sendUnitPriceFlg if (schUnitPriceFlg === '0') { sendUnitPriceFlg = '0' } else if (schUnitPriceFlg === '1') { sendUnitPriceFlg = '1' } else if (schUnitPriceFlg === '2') { sendUnitPriceFlg = '0' } else { sendUnitPriceFlg = '1' } //schDrawingFlg 선택값은 의미없어짐 //가대중량표 포함, 도면/시뮬레이션 파일 포함 선택값에따라 schDrawingFlg에 |구분자로 보냄 //SchDrawingFlg (1 : 견적서,2 : 발전시뮬레이션, 3 : 도면, 4 : 가대) // ex) 1|2|3|4 let defaultSchDrawingFlg = '1' if (schWeightFlg === '1') { defaultSchDrawingFlg = defaultSchDrawingFlg.concat('|', '4') } if (schDrawingFlg === '1') { defaultSchDrawingFlg = defaultSchDrawingFlg.concat('|', '2', '|', '3') } //objectRecoil.floorPlanObjectNo가 비워지는 경우가 있어서 없으면 url에서 뺴오도록 추가 const params = { objectNo: objectRecoil?.floorPlanObjectNo ? objectRecoil.floorPlanObjectNo : searchParams.get('objectNo'), planNo: planNo, schDownload: schDownload, schUnitPriceFlg: sendUnitPriceFlg, schDisplayFlg: schDisplayFlg, schWeightFlg: schWeightFlg, schDrawingFlg: defaultSchDrawingFlg, pwrGnrSimType: 'D', //default 화면에 안보여줌 } const options = { responseType: 'blob' } setIsGlobalLoading(true) await promisePost({ url: url, data: params, option: options }) .then((resultData) => { setIsGlobalLoading(false) 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) //문서 다운받으면 lockFlg = 1 잠금상태로! estimateRecoilState.lockFlg = '1' if (pathName.includes('/floor-plan')) { docDownPopLockFlg() } } }) .catch((error) => { setIsGlobalLoading(false) console.log('::FileDownLoad Error::', error) alert('File does not exist.') }) } return (

{getMessage('estimate.detail.docPopup.title')}

{getMessage('estimate.detail.docPopup.explane')}
{getMessage('estimate.detail.docPopup.schUnitPriceFlg')} *
{ setSchDownload('EXCEL') setSchUnitPriceFlg(e.target.value) }} />
{ setSchDownload('EXCEL') setSchUnitPriceFlg(e.target.value) }} />
{ setSchDownload('PDF') setSchUnitPriceFlg(e.target.value) }} />
{ setSchDownload('PDF') setSchUnitPriceFlg(e.target.value) }} />
{ setSchDownload('EXCEL2') setSchUnitPriceFlg(e.target.value) }} />
{getMessage('estimate.detail.docPopup.schDisplayFlg')} *
{ setSchDisplayFlg(e.target.value) }} />
{ setSchDisplayFlg(e.target.value) }} />
{getMessage('estimate.detail.docPopup.schWeightFlg')} *
{ setSchWeightFlg(e.target.value) }} />
{ setSchWeightFlg(e.target.value) }} />
{getMessage('estimate.detail.docPopup.schDrawingFlg')}
{ setSchDrawingFlg(e.target.value) }} />
{ setSchDrawingFlg(e.target.value) }} />
) }