'use client' import { useEffect, useState, useContext } from 'react' import { useRecoilValue } from 'recoil' import { floorPlanObjectState } from '@/store/floorPlanObjectAtom' import { SessionContext } from '@/app/SessionProvider' import { useMessage } from '@/hooks/useMessage' import { useCanvasMenu } from '@/hooks/common/useCanvasMenu' import SingleDatePicker from '../common/datepicker/SingleDatePicker' import EstimateFileUploader from './EstimateFileUploader' import { useAxios } from '@/hooks/useAxios' import { globalLocaleStore } from '@/store/localeAtom' import { isNotEmptyArray, isObjectNotEmpty } from '@/util/common-utils' import dayjs from 'dayjs' import { useCommonCode } from '@/hooks/common/useCommonCode' import Select from 'react-select' import { useEstimateController } from '@/hooks/floorPlan/estimate/useEstimateController' export default function Estimate({ params }) { const [objectNo, setObjectNo] = useState('') //물건번호 const [planNo, setPlanNo] = useState('') //플랜번호 const [files, setFiles] = useState([]) // 보내는 첨부파일 const [showContentCode, setShowContentCode] = useState('ATTR001') //견적특이사항 접고 펼치기 const [hidden, setHidden] = useState(false) //공통코드 const { findCommonCode } = useCommonCode() const [honorificCodeList, setHonorificCodeList] = useState([]) //경칭 공통코드 const [startDate, setStartDate] = useState(new Date()) const singleDatePickerProps = { startDate, setStartDate, } const { session } = useContext(SessionContext) const objectRecoil = useRecoilValue(floorPlanObjectState) //견적서 상세데이터 const { state, setState } = useEstimateController(params.pid) //견적특이사항 상세 데이터 LIST //견적특이사항 List const [specialNoteList, setSpecialNoteList] = useState([]) const globalLocaleState = useRecoilValue(globalLocaleStore) const { get, post } = useAxios(globalLocaleState) const { getMessage } = useMessage() const { setMenuNumber } = useCanvasMenu() const fileUploadProps = { // objectNo: '', // planNo: params.pid, // category: '10', uploadFiles: files, setUploadFiles: setFiles, } useEffect(() => { setMenuNumber(5) setObjectNo(objectRecoil.floorPlanObjectNo) setPlanNo(params.pid) // 공통코드 const code1 = findCommonCode(200800) if (code1 != null) { setHonorificCodeList(code1) } }, []) useEffect(() => { //견적특이사항 API호출 //여러개 선택하면 구분자로 (、) let url = `/api/estimate/special-note-list` get({ url: url }).then((res) => { if (isNotEmptyArray(res)) { if (state?.estimateOption) { res.map((row) => { let estimateOption = state?.estimateOption?.split('、') row.text = false estimateOption.map((row2) => { if (row2 === row.code) { row.text = true } }) }) setSpecialNoteList(res) } } }) }, [state?.estimateOption]) //견적일 set useEffect(() => { let estimateDate = dayjs(startDate).format('YYYY-MM-DD') setState({ estimateDate: estimateDate }) }, [startDate]) useEffect(() => { //선택된 견적특이사항 setState if (isNotEmptyArray(specialNoteList)) { const liveCheckedData = specialNoteList.filter((row) => row.text === true) const data = [] for (let ele of liveCheckedData) { data.push(ele.code) } const newData = data.join('、') setState({ estimateOption: newData }) } }, [specialNoteList]) // 견적특이사항 remark 보여주기 const settingShowContent = (code, event) => { setShowContentCode(code) event.stopPropagation() } // 첨부파일 state에 넣기 useEffect(() => { // console.log(files) if (files.length > 0) { files.map((row) => { setState({ fileList: row.data }) }) } else { console.log('첨부파일 없음') setState({ fileList: [] }) } }, [files]) return (
{/* 물건번호, 견적서번호, 등록일, 변경일시 시작 */} {/*
*/}
{getMessage('estimate.detail.objectNo')}
{objectNo} (Plan No: {planNo})
{getMessage('estimate.detail.docNo')}
{state.docNo}
{getMessage('estimate.detail.drawingEstimateCreateDate')}
{state?.drawingEstimateCreateDate ? `${dayjs(state.drawingEstimateCreateDate).format('YYYY.MM.DD')}` : ''}
{getMessage('estimate.detail.lastEditDatetime')}
{state?.lastEditDatetime ? `${dayjs(state.lastEditDatetime).format('YYYY.MM.DD HH:mm')}` : ''}
{/* 물건번호, 견적서번호, 등록일, 변경일시 끝 */} {/* 기본정보 시작 */}

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

{/* 1차 판매점명 */} {/* 견적일 */} {/* 2차 판매점명 */} {/* 담당자 */} {/* 안건명 */} {/* 물건정보에서 입력한 메모 */} {/* 주문분류 */} {/* 지붕재・사양시공 최대4개*/} {/* 비고 */}
{getMessage('estimate.detail.saleStoreId')} {getMessage('estimate.detail.estimateDate')} *
{getMessage('estimate.detail.otherSaleStoreId')} {getMessage('estimate.detail.receiveUser')} *
{ //담당자 charger setState({ charger: e.target.value }) }} />
{getMessage('estimate.detail.objectName')} *
{ //안건명 objectName setState({ objectName: e.target.value }) }} />
{getMessage('estimate.detail.objectRemarks')} {state?.objectRemarks}
{getMessage('estimate.detail.estimateType')} *
{ setState({ estimateType: e.target.value }) }} />
{ setState({ estimateType: e.target.value }) }} />
{getMessage('estimate.detail.roofCns')} {state?.roofMaterialIdMulti?.split('、').map((row, index) => { //지붕재 let roofList = row let roofListLength = state?.roofMaterialIdMulti?.split('、').length let style = 'mb5' if (roofListLength == index + 1) { style = '' } //사양시공 let constructSpecificationMulti = state?.constructSpecificationMulti?.split('、') return ( <>
) })}
{getMessage('estimate.detail.remarks')}
{ //비고 setState({ remarks: e.target.value }) }} />
{/* 파일첨부 시작 */}

{getMessage('estimate.detail.header.fileList1')}

{getMessage('estimate.detail.header.fileList1')}
{/* 첨부파일 목록 시작 */}
{getMessage('estimate.detail.header.fileList2')}
{/* 첨부파일 목록 끝 */} {/* 파일첨부 끝 */} {/* 견적특이사항 시작 */}

{getMessage('estimate.detail.header.specialEstimate')}

{getMessage('estimate.detail.header.specialEstimateProductInfo')}
{/* 견적 특이사항 코드영역시작 */}
{/* SpecialNoteList반복문 */} {specialNoteList.map((row) => { return (
{ settingShowContent(row.code, event) }} >
{ setSpecialNoteList((specialNote) => specialNote.map((temp) => (temp.code === row.code ? { ...temp, text: !temp.text } : temp)), ) settingShowContent(row.code, event) }} />
) })}
{/* 견적특이사항 선택한 내용?영역시작 */}
{specialNoteList.map((row) => { if (row.code === showContentCode) { return (
{row.codeNm}
{row.remarks}
) } })}
{/* 견적특이사항 선택한 내용?영역끝 */}
{/* 견적 특이사항 코드영역 끝 */} {/* 견적특이사항 영역끝 */} {/* 제품정보 시작 */}

{getMessage('estimate.detail.header.specialEstimateProductInfo')}

{getMessage('estimate.detail.sepcialEstimateProductInfo.totPcs')}
74
{getMessage('estimate.detail.sepcialEstimateProductInfo.vol')}
8300
{getMessage('estimate.detail.sepcialEstimateProductInfo.netAmt')}
6,798,900
{getMessage('estimate.detail.sepcialEstimateProductInfo.vat')}
679,890
{getMessage('estimate.detail.sepcialEstimateProductInfo.totPrice')}
7,478,790
{/* YJOD면 아래영역 숨김 */}
{getMessage('estimate.detail.sepcialEstimateProductInfo.pkgUnitPrice')} *
{getMessage('estimate.detail.sepcialEstimateProductInfo.pkgWeight')} {getMessage('estimate.detail.sepcialEstimateProductInfo.calcFormula1')} {getMessage('estimate.detail.sepcialEstimateProductInfo.pkgPrice')} {getMessage('estimate.detail.sepcialEstimateProductInfo.calcFormula2')}
{/* 제품정보 끝 */} {/* 가격표시영역시작 */}
{getMessage('estimate.detail.header.showPrice')}
  • {getMessage('estimate.detail.showPrice.description1')}
  • {getMessage('estimate.detail.showPrice.description2')}
  • {getMessage('estimate.detail.showPrice.description3')}
  • {getMessage('estimate.detail.showPrice.description4')}
{/* 가격표시영역끝 */} {/* html테이블시작 */}
{/* html테이블끝 */}
{/* 기본정보끝 */} {/*
*/}
) }