From 38f70437c695f71bcfbd15b418ed197ff29f9683 Mon Sep 17 00:00:00 2001 From: basssy Date: Wed, 20 Nov 2024 17:09:59 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B2=AC=EC=A0=81=EC=84=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/estimate/Estimate.jsx | 210 ++++++++---------- .../estimate/useEstimateController.js | 47 ++-- src/locales/ja.json | 2 + src/locales/ko.json | 2 + 4 files changed, 111 insertions(+), 150 deletions(-) diff --git a/src/components/estimate/Estimate.jsx b/src/components/estimate/Estimate.jsx index 7eb23fa5..e506b6a2 100644 --- a/src/components/estimate/Estimate.jsx +++ b/src/components/estimate/Estimate.jsx @@ -58,7 +58,7 @@ export default function Estimate({ params }) { const objectRecoil = useRecoilValue(floorPlanObjectState) //견적서 상세데이터 - const { state, setState, addItem, handleEstimateFileDownload } = useEstimateController(params.pid) + const { estimateContextState, setEstimateContextState, addItem, handleEstimateFileDownload } = useEstimateController(params.pid) //견적특이사항 List const [specialNoteList, setSpecialNoteList] = useState([]) @@ -105,9 +105,9 @@ export default function Estimate({ params }) { let url = `/api/estimate/special-note-list` get({ url: url }).then((res) => { if (isNotEmptyArray(res)) { - if (state?.estimateOption) { + if (estimateContextState?.estimateOption) { res.map((row) => { - let estimateOption = state?.estimateOption?.split('、') + let estimateOption = estimateContextState?.estimateOption?.split('、') row.text = false estimateOption.map((row2) => { if (row2 === row.code) { @@ -119,16 +119,16 @@ export default function Estimate({ params }) { } } }) - }, [state?.estimateOption]) + }, [estimateContextState?.estimateOption]) //견적일 set useEffect(() => { let estimateDate = dayjs(startDate).format('YYYY-MM-DD') - setState({ estimateDate: estimateDate }) + setEstimateContextState({ estimateDate: estimateDate }) }, [startDate]) useEffect(() => { - //선택된 견적특이사항 setState + //선택된 견적특이사항 setEstimateContextState if (isNotEmptyArray(specialNoteList)) { const liveCheckedData = specialNoteList.filter((row) => row.text === true) @@ -138,7 +138,7 @@ export default function Estimate({ params }) { } const newData = data.join('、') - setState({ estimateOption: newData }) + setEstimateContextState({ estimateOption: newData }) } }, [specialNoteList]) @@ -148,23 +148,23 @@ export default function Estimate({ params }) { event.stopPropagation() } - // 추가한 첨부파일 state에 넣기 + // 추가한 첨부파일 estimateContextState에 넣기 useEffect(() => { if (isNotEmptyArray(files)) { files.map((row) => { - setState({ fileList: row.data }) + setEstimateContextState({ fileList: row.data }) }) } else { - setState({ fileList: [] }) + setEstimateContextState({ fileList: [] }) } }, [files]) //상세에서 내려온 첨부파일 set 만들기 useEffect(() => { - if (isNotEmptyArray(state.fileList)) { - setOriginFiles(state.fileList) + if (isNotEmptyArray(estimateContextState.fileList)) { + setOriginFiles(estimateContextState.fileList) } - }, [state?.fileList]) + }, [estimateContextState?.fileList]) // 기존첨부파일 삭제 const deleteOriginFile = async (objectNo, no) => { @@ -176,7 +176,7 @@ export default function Estimate({ params }) { await promisePost({ url: 'api/file/fileDelete', data: delParams }).then((res) => { if (res.status === 204) { setOriginFiles(originFiles.filter((file) => file.objectNo === objectNo && file.no !== no)) - setState({ + setEstimateContextState({ fileList: originFiles.filter((file) => file.objectNo === objectNo && file.no !== no), }) } @@ -185,11 +185,11 @@ export default function Estimate({ params }) { //가격표시 option 목록 최초세팅 && 주문분류 변경시 useEffect(() => { - if (state.estimateType !== '') { + if (estimateContextState.estimateType !== '') { const param = { saleStoreId: session.storeId, sapSalesStoreCd: session.custCd, - docTpCd: state?.estimateType, + docTpCd: estimateContextState?.estimateType, } const apiUrl = `/api/estimate/price/store-price-list?${queryStringFormatter(param)}` @@ -201,13 +201,13 @@ export default function Estimate({ params }) { setItemChangeYn(true) } - }, [state?.estimateType]) + }, [estimateContextState?.estimateType]) useEffect(() => { - if (state?.priceCd) { - setShowPriceCd(state.priceCd) + if (estimateContextState?.priceCd) { + setShowPriceCd(estimateContextState.priceCd) } - }, [state?.priceCd]) + }, [estimateContextState?.priceCd]) //가격 표시 option 변경 이벤트 const onChangeStorePriceList = (priceCd) => { @@ -217,7 +217,7 @@ export default function Estimate({ params }) { docTpCd: priceCd, } - //프라이싱 했을때 priceCd setState + //프라이싱 했을때 priceCd setEstimateContextState //화면에 보여지는 값은 showPriceCd로 관리 setShowPriceCd(priceCd) @@ -234,10 +234,10 @@ export default function Estimate({ params }) { const param = { saleStoreId: session.storeId, sapSalesStoreCd: session.custCd, - docTpCd: state.estimateType, + docTpCd: estimateContextState.estimateType, priceCd: showPriceCd, - //itemIdList: state.itemList, //아이템 최초정보로 호출 delFlg 0인거만.. - itemIdList: state.itemList.filter((item) => item.delFlg === '0'), + //itemIdList: estimateContextState.itemList, //아이템 최초정보로 호출 delFlg 0인거만.. + itemIdList: estimateContextState.itemList.filter((item) => item.delFlg === '0'), } if (param.itemIdList.length > 0) { @@ -264,7 +264,7 @@ export default function Estimate({ params }) { //itemId로 비교해서 단가정보만 업데이트 if (data.result.code === 200) { if (isNotEmptyArray(data.data2)) { - state.itemList.map((item) => { + estimateContextState.itemList.map((item) => { let checkYn = false data.data2.map((item2) => { if (item2.itemId === item.itemId) { @@ -278,7 +278,7 @@ export default function Estimate({ params }) { } }) - setState({ + setEstimateContextState({ priceCd: showPriceCd, itemList: updateList, }) @@ -305,7 +305,7 @@ export default function Estimate({ params }) { //주택PKG input 변경 const onChangePkgAsp = (value) => { - if (state.estimateType === 'YJSS') { + if (estimateContextState.estimateType === 'YJSS') { let pkgAsp = Number(value.replace(/[^0-9]/g, '').replaceAll(',', '')) if (isNaN(pkgAsp)) { pkgAsp = 0 @@ -314,10 +314,10 @@ export default function Estimate({ params }) { } //현재 PKG용량값 가져오기 - let totVolKw = state.totVolKw * 1000 + let totVolKw = estimateContextState.totVolKw * 1000 let pkgTotPrice = pkgAsp * totVolKw - setState({ + setEstimateContextState({ pkgAsp: pkgAsp, pkgTotPrice: pkgTotPrice.toFixed(3), }) @@ -339,9 +339,9 @@ export default function Estimate({ params }) { updates.amount = amount updates.itemChangeFlg = '1' updates.partAdd = '0' - updates.saleTotPrice = (Number(amount.replaceAll(',', '')) * state.itemList[index].salePrice.replaceAll(',', '')).toLocaleString() + updates.saleTotPrice = (Number(amount.replaceAll(',', '')) * estimateContextState.itemList[index].salePrice.replaceAll(',', '')).toLocaleString() - updateList = state.itemList.map((item) => { + updateList = estimateContextState.itemList.map((item) => { if (item.dispOrder === dispOrder) { return { ...item, ...updates } } else { @@ -349,7 +349,7 @@ export default function Estimate({ params }) { } }) - setState({ + setEstimateContextState({ itemList: updateList, }) @@ -368,9 +368,9 @@ export default function Estimate({ params }) { let updateList = [] let updates = {} updates.salePrice = salePrice - updates.saleTotPrice = (Number(salePrice.replaceAll(',', '')) * state.itemList[index].amount.replaceAll(',', '')).toLocaleString() + updates.saleTotPrice = (Number(salePrice.replaceAll(',', '')) * estimateContextState.itemList[index].amount.replaceAll(',', '')).toLocaleString() - updateList = state.itemList.map((item) => { + updateList = estimateContextState.itemList.map((item) => { if (item.dispOrder === dispOrder) { return { ...item, ...updates } } else { @@ -378,7 +378,7 @@ export default function Estimate({ params }) { } }) - setState({ + setEstimateContextState({ itemList: updateList, }) @@ -414,12 +414,12 @@ export default function Estimate({ params }) { updates.specialNoteCd = res.spnAttrCds updates.itemGroup = res.itemGroup updates.delFlg = '0' // 삭제플래그 0 - // updates.saleTotPrice = res.salePrice * state.itemList[index].amount + // updates.saleTotPrice = res.salePrice * estimateContextState.itemList[index].amount updates.saleTotPrice = '0' //추가때는 수량을 안받아서 합계를 무조건 0으로 //104671 let bomList = res.itemBomList - updateList = state.itemList.map((item) => { + updateList = estimateContextState.itemList.map((item) => { if (item.dispOrder === dispOrder) { return { ...item, ...updates } } else if (item.paDispOrder === dispOrder) { @@ -431,18 +431,18 @@ export default function Estimate({ params }) { //paDispOrder if (bomList) { bomList.map((bomItem, index) => { - let newItemDispOrder = Math.max(...state.itemList.map((item) => item.dispOrder)) + let newItemDispOrder = Math.max(...estimateContextState.itemList.map((item) => item.dispOrder)) bomItem.dispOrder = index + 1 + newItemDispOrder bomItem.delFlg = '0' bomItem.objectNo = objectNo bomItem.planNo = planNo }) - setState({ + setEstimateContextState({ itemList: [...updateList, ...bomList], }) } else { - setState({ + setEstimateContextState({ itemList: updateList, }) } @@ -455,7 +455,7 @@ export default function Estimate({ params }) { const removeItem = () => { const array = [...selection] let delList = [] - state.itemList.filter((row) => { + estimateContextState.itemList.filter((row) => { array.map((row2) => { if (row2 === row.dispOrder) { delList.push({ ...row }) @@ -466,7 +466,7 @@ export default function Estimate({ params }) { }) }) - const updateList = state.itemList.map((item) => { + const updateList = estimateContextState.itemList.map((item) => { const isDeleted = delList.some((row) => item.delFlg === '1' || item.dispOrder === row.dispOrder) return { ...item, @@ -485,7 +485,7 @@ export default function Estimate({ params }) { return alert(getMessage('estimate.detail.save.requiredItem')) } - setState({ + setEstimateContextState({ itemList: updateList, }) @@ -501,8 +501,8 @@ export default function Estimate({ params }) { let vatPrice = 0 let totPrice = 0 let addPkgPrice = 0 - if (state.estimateType === 'YJOD') { - state.itemList.map((item) => { + if (estimateContextState.estimateType === 'YJOD') { + estimateContextState.itemList.map((item) => { if (item.delFlg === '0') { const amount = Number(item.amount.replace(/[^0-9]/g, '').replaceAll(',', '')) const price = Number(item.saleTotPrice.replaceAll(',', '')) @@ -521,7 +521,7 @@ export default function Estimate({ params }) { vatPrice = supplyPrice * 0.1 totPrice = supplyPrice + vatPrice - setState({ + setEstimateContextState({ totAmount: totAmount, totVolKw: totVolKw.toFixed(3), supplyPrice: supplyPrice.toFixed(3), @@ -530,7 +530,7 @@ export default function Estimate({ params }) { }) } else { //YJSS - state.itemList.map((item) => { + estimateContextState.itemList.map((item) => { if (item.delFlg === '0') { const amount = Number(item.amount.replace(/[^0-9]/g, '').replaceAll(',', '')) const price = Number(item.saleTotPrice.replaceAll(',', '')) @@ -556,7 +556,7 @@ export default function Estimate({ params }) { vatPrice = supplyPrice * 0.1 totPrice = supplyPrice + vatPrice - setState({ + setEstimateContextState({ totAmount: totAmount, totVolKw: totVolKw.toFixed(3), supplyPrice: supplyPrice.toFixed(3), @@ -567,21 +567,22 @@ export default function Estimate({ params }) { setItemChangeYn(false) } - }, [itemChangeYn, state.itemList]) + }, [itemChangeYn, estimateContextState.itemList]) //안건명 인풋 변경 const handleBlurObjectName = (e) => { - setState({ objectName: e.target.value }) + setEstimateContextState({ objectName: e.target.value }) } //담당자 인풋 변경 const handleBlurCharger = (e) => { - setState({ charger: e.target.value }) + setEstimateContextState({ charger: e.target.value }) } - useEffect(() => { - console.log('수정날짜시간???????????', state.lastEditDatetime) - }, [state]) + //비고 인풋 변경 + const handleBlurRemarks = (e) => { + setEstimateContextState({ remarks: e.target.value }) + } return (
@@ -598,18 +599,21 @@ export default function Estimate({ params }) {
{getMessage('estimate.detail.docNo')}
-
{state.docNo}
+
{estimateContextState.docNo}
{getMessage('estimate.detail.drawingEstimateCreateDate')}
- {state?.drawingEstimateCreateDate ? `${dayjs(state.drawingEstimateCreateDate).format('YYYY.MM.DD')}` : ''} + {estimateContextState?.drawingEstimateCreateDate + ? `${dayjs(estimateContextState.drawingEstimateCreateDate).format('YYYY.MM.DD')}` + : ''}
{getMessage('estimate.detail.lastEditDatetime')}
- {/*
{state?.lastEditDatetime ? `${dayjs(state.lastEditDatetime).format('YYYY.MM.DD HH:mm')}` : ''}
*/} -
{state?.lastEditDatetime ? `${dayjs(state?.lastEditDatetime).format('HH:mm:ss')}` : ''}
+
+ {estimateContextState?.lastEditDatetime ? `${dayjs(estimateContextState.lastEditDatetime).format('YYYY.MM.DD HH:mm')}` : ''} +
@@ -635,7 +639,7 @@ export default function Estimate({ params }) { {/* 1차 판매점명 */} {getMessage('estimate.detail.saleStoreId')} - {state?.firstSaleStoreName} + {estimateContextState?.firstSaleStoreName} {/* 견적일 */} {getMessage('estimate.detail.estimateDate')} * @@ -649,23 +653,14 @@ export default function Estimate({ params }) { {/* 2차 판매점명 */} {getMessage('estimate.detail.otherSaleStoreId')} - {state?.agencySaleStoreName} + {estimateContextState?.agencySaleStoreName} {/* 담당자 */} {getMessage('estimate.detail.receiveUser')} *
- { - // //담당자 charger - // setState({ charger: e.target.value }) - // }} - onBlur={handleBlurCharger} - /> +
@@ -677,16 +672,7 @@ export default function Estimate({ params }) {
- { - // //안건명 objectName - // setState({ objectName: e.target.value }) - // }} - onBlur={handleBlurObjectName} - /> +
{ - setState({ estimateType: e.target.value }) + setEstimateContextState({ estimateType: e.target.value }) }} /> - +
@@ -761,16 +747,16 @@ export default function Estimate({ params }) { {/* 지붕재・사양시공 최대4개*/} {getMessage('estimate.detail.roofCns')} - {state?.roofMaterialIdMulti?.split('、').map((row, index) => { + {estimateContextState?.roofMaterialIdMulti?.split('、').map((row, index) => { //지붕재 let roofList = row - let roofListLength = state?.roofMaterialIdMulti?.split('、').length + let roofListLength = estimateContextState?.roofMaterialIdMulti?.split('、').length let style = 'mb5' if (roofListLength == index + 1) { style = '' } //사양시공 - let constructSpecificationMulti = state?.constructSpecificationMulti?.split('、') + let constructSpecificationMulti = estimateContextState?.constructSpecificationMulti?.split('、') return ( <> @@ -792,15 +778,7 @@ export default function Estimate({ params }) { {getMessage('estimate.detail.remarks')}
- { - //비고 - setState({ remarks: e.target.value }) - }} - /> +
@@ -815,9 +793,9 @@ export default function Estimate({ params }) { { - setState({ + setEstimateContextState({ fileFlg: e.target.checked ? '1' : '0', }) }} @@ -959,28 +937,28 @@ export default function Estimate({ params }) {
{getMessage('estimate.detail.sepcialEstimateProductInfo.totAmount')}
-
{convertNumberToPriceDecimal(state?.totAmount)}
+
{convertNumberToPriceDecimal(estimateContextState?.totAmount)}
{getMessage('estimate.detail.sepcialEstimateProductInfo.totVolKw')}
-
{convertNumberToPriceDecimal(state?.totVolKw)}
+
{convertNumberToPriceDecimal(estimateContextState?.totVolKw)}
{getMessage('estimate.detail.sepcialEstimateProductInfo.supplyPrice')}
-
{convertNumberToPriceDecimal(state?.supplyPrice)}
+
{convertNumberToPriceDecimal(estimateContextState?.supplyPrice)}
{getMessage('estimate.detail.sepcialEstimateProductInfo.vatPrice')}
-
{convertNumberToPriceDecimal(state?.vatPrice)}
+
{convertNumberToPriceDecimal(estimateContextState?.vatPrice)}
{getMessage('estimate.detail.sepcialEstimateProductInfo.totPrice')}
-
{convertNumberToPriceDecimal(state?.totPrice)}
+
{convertNumberToPriceDecimal(estimateContextState?.totPrice)}
{/* YJOD면 아래영역 숨김 */} -
+
@@ -1001,7 +979,7 @@ export default function Estimate({ params }) { { onChangePkgAsp(e.target.value) }} @@ -1009,9 +987,9 @@ export default function Estimate({ params }) { - + - +
{getMessage('estimate.detail.sepcialEstimateProductInfo.pkgWeight')}{convertNumberToPriceDecimal(state?.totVolKw)}{convertNumberToPriceDecimal(estimateContextState?.totVolKw)} {getMessage('estimate.detail.sepcialEstimateProductInfo.pkgPrice')}{convertNumberToPriceDecimal(state?.pkgTotPrice)}{convertNumberToPriceDecimal(estimateContextState?.pkgTotPrice)}
@@ -1120,8 +1098,8 @@ export default function Estimate({ params }) { - {state?.itemList.length > 0 && - state.itemList.map((item, index) => { + {estimateContextState?.itemList.length > 0 && + estimateContextState.itemList.map((item, index) => { if (item.delFlg === '0') { return ( @@ -1209,7 +1187,7 @@ export default function Estimate({ params }) { className="input-light al-r" value={convertNumberToPriceDecimal(item?.salePrice.replaceAll(',', ''))} disabled={ - state?.estimateType === 'YJSS' + estimateContextState?.estimateType === 'YJSS' ? item?.paDispOrder ? true : item.pkgMaterialFlg !== '1' diff --git a/src/hooks/floorPlan/estimate/useEstimateController.js b/src/hooks/floorPlan/estimate/useEstimateController.js index de5fe873..01575518 100644 --- a/src/hooks/floorPlan/estimate/useEstimateController.js +++ b/src/hooks/floorPlan/estimate/useEstimateController.js @@ -9,27 +9,9 @@ import { useMessage } from '@/hooks/useMessage' import { useRouter } from 'next/navigation' import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider' -const reducer = (prevState, nextState) => { - return { ...prevState, ...nextState } -} - // Constants const ESTIMATE_API_ENDPOINT = '/api/estimate' // API 엔드포인트 정의 -const defaultEstimateData = { - estimateDate: new Date(), //견적일 - charger: '', //담당자 - objectName: '', //안건명 - objectNameOmit: '', //경칭코드 - estimateType: '', //주문분류 - remarks: '', //비고 - estimateOption: '', //견적특이사항 - itemList: [], - fileList: [], - fileFlg: '0', //후일 자료 제출 (체크 1 노체크 0) - priceCd: '', -} - // Helper functions const updateItemInList = (itemList, dispOrder, updates) => { return itemList.map((item) => (item.dispOrder === dispOrder ? { ...item, ...updates } : item)) @@ -44,11 +26,10 @@ export const useEstimateController = (planNo) => { const { getMessage } = useMessage() - const { promiseGet, get, post, promisePost } = useAxios(globalLocaleState) + const { promiseGet, post, promisePost } = useAxios(globalLocaleState) const [isLoading, setIsLoading] = useState(false) - const [state, setState] = useReducer(reducer, defaultEstimateData) - const [newState, setNewState] = useState({}) + const { estimateContextState, setEstimateContextState } = useContext(FloorPlanContext) useEffect(() => { if (planNo && !isLoading) { @@ -69,9 +50,7 @@ export const useEstimateController = (planNo) => { item.delFlg = '0' }) } - console.log('조회결과;', res.data) - console.log('수정시간;', res.data.lastEditDatetime) - setState(res.data) + setEstimateContextState(res.data) } } }) @@ -83,17 +62,17 @@ export const useEstimateController = (planNo) => { } const updateItem = (dispOrder, updates) => { - setState({ - itemList: updateItemInList(state.itemList, dispOrder, updates), + setEstimateContextState({ + itemList: updateItemInList(estimateContextState.itemList, dispOrder, updates), }) } const addItem = () => { - let newItemDispOrder = Math.max(...state.itemList.map((item) => item.dispOrder)) + let newItemDispOrder = Math.max(...estimateContextState.itemList.map((item) => item.dispOrder)) newItemDispOrder = (Math.floor(newItemDispOrder / 100) + 1) * 100 - setState({ + setEstimateContextState({ itemList: [ - ...state.itemList, + ...estimateContextState.itemList, { objectNo: objectRecoil.floorPlanObjectNo, planNo: planNo, @@ -115,8 +94,8 @@ export const useEstimateController = (planNo) => { } useEffect(() => { - setEstimateData({ ...state, userId: session.userId, sapSalesStoreCd: session.custCd }) - }, [state]) + setEstimateData({ ...estimateContextState, userId: session.userId, sapSalesStoreCd: session.custCd }) + }, [estimateContextState]) // 첨부파일 다운로드 const handleEstimateFileDownload = async (originFile) => { @@ -206,7 +185,7 @@ export const useEstimateController = (planNo) => { return alert(getMessage('estimate.detail.save.requiredItem')) } - // console.log('최종 정보::;', estimateData) + console.log('최종 정보::;', estimateData) //2. 상세데이터 저장 // return @@ -256,8 +235,8 @@ export const useEstimateController = (planNo) => { } return { - state, - setState, + estimateContextState, + setEstimateContextState, updateItem, addItem, handleEstimateSubmit, diff --git a/src/locales/ja.json b/src/locales/ja.json index 7bda9175..5bc848f6 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -823,6 +823,8 @@ "estimate.detail.objectName": "案件名", "estimate.detail.objectRemarks": "メモ", "estimate.detail.estimateType": "注文分類", + "estimate.detail.estimateType.yjss": "住宅PKG", + "estimate.detail.estimateType.yjod": "積上げ( YJOD )", "estimate.detail.roofCns": "屋根材・仕様施工", "estimate.detail.remarks": "備考", "estimate.detail.fileFlg": "後日資料提出", diff --git a/src/locales/ko.json b/src/locales/ko.json index 54f672a5..6e34ea40 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -833,6 +833,8 @@ "estimate.detail.objectName": "안건명", "estimate.detail.objectRemarks": "메모", "estimate.detail.estimateType": "주문분류", + "estimate.detail.estimateType.yjss": "住宅PKG", + "estimate.detail.estimateType.yjod": "積上げ( YJOD )", "estimate.detail.roofCns": "지붕재・사양시공", "estimate.detail.remarks": "비고", "estimate.detail.fileFlg": "후일자료제출",