견적서 복사

This commit is contained in:
basssy 2024-11-20 11:17:25 +09:00
parent 88a64282eb
commit 6ad0b8f9d4
4 changed files with 147 additions and 64 deletions

View File

@ -1,40 +1,33 @@
'use client' 'use client'
import { useEffect, useState, useContext, use } from 'react' import { useEffect, useState, useContext, useRef } from 'react'
import { useMessage } from '@/hooks/useMessage' import { useMessage } from '@/hooks/useMessage'
import { useAxios } from '@/hooks/useAxios' import { useAxios } from '@/hooks/useAxios'
import { useRecoilValue } from 'recoil'
import { floorPlanObjectState } from '@/store/floorPlanObjectAtom'
import Select, { components } from 'react-select' import Select, { components } from 'react-select'
import { SessionContext } from '@/app/SessionProvider' import { SessionContext } from '@/app/SessionProvider'
import { isEmptyArray } from '@/util/common-utils' import { isEmptyArray, isObjectNotEmpty } from '@/util/common-utils'
import { useEstimateController } from '@/hooks/floorPlan/estimate/useEstimateController' import { useEstimateController } from '@/hooks/floorPlan/estimate/useEstimateController'
import { estimateState } from '@/store/floorPlanObjectAtom'
export default function EstimateCopyPop({ planNo, setEstimateCopyPopupOpen }) { export default function EstimateCopyPop({ planNo, setEstimateCopyPopupOpen }) {
const { getMessage } = useMessage() const { getMessage } = useMessage()
const { get, promisePost } = useAxios() const { get } = useAxios()
const [selOptions, setSelOptions] = useState('') // 1
const { handleEstimateCopy, state } = useEstimateController(planNo) const { handleEstimateCopy, state } = useEstimateController(planNo)
const { session } = useContext(SessionContext) const { session } = useContext(SessionContext)
// recoil
const objectRecoil = useRecoilValue(floorPlanObjectState)
const [saleStoreList, setSaleStoreList] = useState([]) // const [saleStoreList, setSaleStoreList] = useState([]) //
const [favoriteStoreList, setFavoriteStoreList] = useState([]) // const [favoriteStoreList, setFavoriteStoreList] = useState([]) //
const [showSaleStoreList, setShowSaleStoreList] = useState([]) // const [showSaleStoreList, setShowSaleStoreList] = useState([]) //
const estimateRecoilState = useRecoilValue(estimateState)
const [otherSaleStoreList, setOtherSaleStoreList] = useState([]) const [otherSaleStoreList, setOtherSaleStoreList] = useState([])
const [originOtherSaleStoreList, setOriginOtherSaleStoreList] = useState([]) const [originOtherSaleStoreList, setOriginOtherSaleStoreList] = useState([])
const [saleStoreId, setSaleStoreId] = useState('') // 1
const [otherSaleStoreId, setOtherSaleStoreId] = useState('') // 1
const [sendPlanNo, setSendPlanNo] = useState('1') const [sendPlanNo, setSendPlanNo] = useState('1')
const [sendCharger, setSendCharger] = useState('') const [copyReceiveUser, setCopyReceiveUser] = useState('')
const ref = useRef() //2
useEffect(() => { useEffect(() => {
let url let url
@ -47,7 +40,8 @@ export default function EstimateCopyPop({ planNo, setEstimateCopyPopupOpen }) {
if (session.storeLvl === '1') { if (session.storeLvl === '1') {
url = `/api/object/saleStore/${session?.storeId}/list?firstFlg=1&userId=${session?.userId}` url = `/api/object/saleStore/${session?.storeId}/list?firstFlg=1&userId=${session?.userId}`
} else { } else {
url = `/api/object/saleStore/${session?.storeId}/list?firstFlg=1&userId=${session?.userId}` //T01 or 1
// url = `/api/object/saleStore/${session?.storeId}/list?firstFlg=1&userId=${session?.userId}`
} }
} }
@ -60,21 +54,44 @@ export default function EstimateCopyPop({ planNo, setEstimateCopyPopupOpen }) {
}) })
if (session.storeId === 'T01') { if (session.storeId === 'T01') {
console.log('T01:::::::::::', res) firstList = res
//T01
firstList.sort((a, b) => (a.saleStoreId !== 'T01') - (b.saleStoreId !== 'T01') || a.saleStoreId - b.saleStoreId)
favList = firstList.filter((row) => row.saleStoreId === 'T01' || row.priority !== 'B')
setSaleStoreList(firstList)
setFavoriteStoreList(favList)
setShowSaleStoreList(favList)
setSaleStoreId(session?.storeId)
// T01 T01 2 (onSelectionChange..) 2
url = `/api/object/saleStore/${session?.storeId}/list?firstFlg=0&userId=${session?.userId}`
get({ url: url }).then((res) => {
if (!isEmptyArray(res)) {
res.map((row) => {
row.value == row.saleStoreId
row.label = row.saleStoreName
})
otherList = res
setOtherSaleStoreList(otherList)
setOriginOtherSaleStoreList(otherList)
} else {
setOtherSaleStoreList([])
}
})
} else { } else {
if (session.storeLvl === '1') { if (session.storeLvl === '1') {
console.log('T01아닌 1차점', res)
firstList = res firstList = res
favList = res.filter((row) => row.priority !== 'B') favList = res.filter((row) => row.priority !== 'B')
otherList = res.filter((row) => row.firstAgentYn === 'N') otherList = res.filter((row) => row.firstAgentYn === 'N')
setSaleStoreList(firstList) setSaleStoreList(firstList)
setFavoriteStoreList(firstList) setFavoriteStoreList(firstList)
setShowSaleStoreList(firstList) setShowSaleStoreList(firstList)
setSelOptions(firstList[0].saleStoreId) setSaleStoreId(firstList[0].saleStoreId)
setOtherSaleStoreList(otherList) setOtherSaleStoreList(otherList)
} else { } else {
console.log('1차점 아님::::::::', res) //T01 or 1
} }
} }
} }
@ -89,22 +106,73 @@ export default function EstimateCopyPop({ planNo, setEstimateCopyPopupOpen }) {
useEffect(() => { useEffect(() => {
if (state?.charger) { if (state?.charger) {
setSendCharger(state.charger) setCopyReceiveUser(state.charger)
} }
}, [state.charger]) }, [state.charger])
//T01 1
const onInputChange = (key) => {
if (key !== '') {
setShowSaleStoreList(saleStoreList)
} else {
setShowSaleStoreList(favoriteStoreList)
}
}
// 1 // 1
const onSelectionChange = (key) => { const onSelectionChange = (key) => {
if (isObjectNotEmpty(key)) { if (isObjectNotEmpty(key)) {
if (key.saleStoreId === selOptions) { if (key.saleStoreId === saleStoreId) {
return return
} }
} }
if (isObjectNotEmpty(key)) { if (isObjectNotEmpty(key)) {
console.log('KEY::', key) setSaleStoreId(key.saleStoreId)
const url = `/api/object/saleStore/${key.saleStoreId}/list?firstFlg=0&userId=${session?.userId}`
let otherList
get({ url: url }).then((res) => {
if (!isEmptyArray(res)) {
res.map((row) => {
row.value = row.saleStoreId
row.label = row.saleStoreName
})
otherList = res
setOtherSaleStoreList(otherList)
setOtherSaleStoreId('')
} else {
setOtherSaleStoreId('')
setOtherSaleStoreList([])
}
})
} else { } else {
console.log('XXXXXXXXXXX') setSaleStoreId('')
//otherSaleStoreId onSelectionChange2
setOtherSaleStoreList(originOtherSaleStoreList)
handleClear()
}
}
// 2
const onSelectionChange2 = (key) => {
if (isObjectNotEmpty(key)) {
if (key.saleStoreId === otherSaleStoreId) {
return
}
}
if (isObjectNotEmpty(key)) {
setOtherSaleStoreId(key.saleStoreId)
} else {
setOtherSaleStoreId('')
}
}
//2
const handleClear = () => {
if (ref.current) {
ref.current.clearValue()
} }
} }
@ -141,9 +209,19 @@ export default function EstimateCopyPop({ planNo, setEstimateCopyPopupOpen }) {
className="react-select-custom" className="react-select-custom"
classNamePrefix="custom" classNamePrefix="custom"
placeholder="Select" placeholder="Select"
options={showSaleStoreList}
onInputChange={onInputChange}
onChange={onSelectionChange}
getOptionLabel={(x) => x.saleStoreName}
getOptionValue={(x) => x.saleStoreId}
isClearable={true}
isDisabled={false}
value={saleStoreList.filter(function (option) {
return option.saleStoreId === saleStoreId
})}
/> />
</div> </div>
<div className="estimate-copy-id">로그인T01 선택한 1차점 아이디</div> <div className="estimate-copy-id">{saleStoreId}</div>
</div> </div>
)} )}
{session.storeId !== 'T01' && session.storeLvl === '1' && ( {session.storeId !== 'T01' && session.storeLvl === '1' && (
@ -162,32 +240,16 @@ export default function EstimateCopyPop({ planNo, setEstimateCopyPopupOpen }) {
isClearable={false} isClearable={false}
isDisabled={session?.storeLvl !== '1' ? true : session?.storeId !== 'T01' ? true : false} isDisabled={session?.storeLvl !== '1' ? true : session?.storeId !== 'T01' ? true : false}
value={showSaleStoreList.filter(function (option) { value={showSaleStoreList.filter(function (option) {
return option.saleStoreId === selOptions return option.saleStoreId === saleStoreId
})} })}
/> />
</div> </div>
<div className="estimate-copy-id">로그인 1차점 선택한 1차점 아이디</div> <div className="estimate-copy-id">{saleStoreId}</div>
</div>
)}
{session.storeId !== 'T01' && session.storeLvl !== '1' && (
<div className="estimate-copy-info-box">
<div className="estimate-copy-sel">
<Select
id="long-value-select1"
instanceId="long-value-select1"
className="react-select-custom"
classNamePrefix="custom"
placeholder="Select"
/>
</div>
<div className="estimate-copy-id">로그인 1차점 아님 선택한 1차점 아이디</div>
</div> </div>
)} )}
</div> </div>
<div className="estimate-copy-info-item"> <div className="estimate-copy-info-item">
<div className="estimate-copy-info-tit"> <div className="estimate-copy-info-tit">{getMessage('estimate.detail.estimateCopyPopup.label.otherSaleStoreId')}</div>
{getMessage('estimate.detail.estimateCopyPopup.label.otherSaleStoreId')} <span className="red">*</span>
</div>
<div className="estimate-copy-info-box"> <div className="estimate-copy-info-box">
<div className="estimate-copy-sel"> <div className="estimate-copy-sel">
<Select <Select
@ -196,9 +258,19 @@ export default function EstimateCopyPop({ planNo, setEstimateCopyPopupOpen }) {
className="react-select-custom" className="react-select-custom"
classNamePrefix="custom" classNamePrefix="custom"
placeholder="Select" placeholder="Select"
ref={ref}
options={otherSaleStoreList}
onChange={onSelectionChange2}
getOptionLabel={(x) => x.saleStoreName}
getOptionValue={(x) => x.saleStoreId}
isClearable={true}
isDisabled={otherSaleStoreList.length > 0 ? false : true}
value={otherSaleStoreList.filter(function (option) {
return option.saleStoreId === otherSaleStoreId
})}
/> />
</div> </div>
<div className="estimate-copy-id">선택한 2차점 아이디</div> <div className="estimate-copy-id">{otherSaleStoreId}</div>
</div> </div>
</div> </div>
<div className="estimate-copy-info-item"> <div className="estimate-copy-info-item">
@ -209,9 +281,10 @@ export default function EstimateCopyPop({ planNo, setEstimateCopyPopupOpen }) {
<input <input
type="text" type="text"
className="input-light" className="input-light"
required
defaultValue={state?.charger} defaultValue={state?.charger}
onChange={(e) => { onChange={(e) => {
setSendCharger(e.target.value) setCopyReceiveUser(e.target.value)
}} }}
/> />
</div> </div>
@ -226,7 +299,7 @@ export default function EstimateCopyPop({ planNo, setEstimateCopyPopupOpen }) {
type="button" type="button"
className="btn-origin navy" className="btn-origin navy"
onClick={() => { onClick={() => {
handleEstimateCopy(sendPlanNo, sendCharger, selOptions) handleEstimateCopy(sendPlanNo, copyReceiveUser, saleStoreId, otherSaleStoreId)
}} }}
> >
{getMessage('estimate.detail.estimateCopyPopup.copyBtn')} {getMessage('estimate.detail.estimateCopyPopup.copyBtn')}

View File

@ -51,15 +51,15 @@ export const useEstimateController = (planNo) => {
useEffect(() => { useEffect(() => {
if (planNo && !isLoading) { if (planNo && !isLoading) {
if (objectRecoil.floorPlanObjectNo && planNo) { if (objectRecoil.floorPlanObjectNo && planNo) {
fetchSetting() fetchSetting(objectRecoil.floorPlanObjectNo, planNo)
} }
} }
}, []) }, [])
// 상세 조회 // 상세 조회
const fetchSetting = async () => { const fetchSetting = async (objectNo, planNo) => {
try { try {
await get({ url: `/api/estimate/${objectRecoil.floorPlanObjectNo}/${planNo}/detail` }).then((res) => { await get({ url: `/api/estimate/${objectNo}/${planNo}/detail` }).then((res) => {
if (isObjectNotEmpty(res)) { if (isObjectNotEmpty(res)) {
if (res.itemList.length > 0) { if (res.itemList.length > 0) {
res.itemList.map((item) => { res.itemList.map((item) => {
@ -84,7 +84,6 @@ export const useEstimateController = (planNo) => {
} }
const addItem = () => { const addItem = () => {
// const newItemDispOrder = (Math.max(...state.itemList.map((item) => item.dispOrder)) / 100 + 1) * 100
let newItemDispOrder = Math.max(...state.itemList.map((item) => item.dispOrder)) let newItemDispOrder = Math.max(...state.itemList.map((item) => item.dispOrder))
newItemDispOrder = (Math.floor(newItemDispOrder / 100) + 1) * 100 newItemDispOrder = (Math.floor(newItemDispOrder / 100) + 1) * 100
setState({ setState({
@ -191,11 +190,10 @@ export const useEstimateController = (planNo) => {
//2. 상세데이터 저장 //2. 상세데이터 저장
// return // return
await promisePost({ url: `${ESTIMATE_API_ENDPOINT}/save-estimate`, data: estimateData }).then((res) => { await promisePost({ url: `${ESTIMATE_API_ENDPOINT}/save-estimate`, data: estimateData }).then((res) => {
console.log('res::::::::::::', res)
if (res.status === 201) { if (res.status === 201) {
alert(getMessage('estimate.detail.save.alertMsg')) alert(getMessage('estimate.detail.save.alertMsg'))
//어디로 보낼지 //어디로 보낼지
router.push(`/floor-plan/estimate/5/${estimateData.planNo}`) fetchSetting(objectRecoil.floorPlanObjectNo, estimateData.planNo)
} }
}) })
} }
@ -206,25 +204,33 @@ export const useEstimateController = (planNo) => {
* (견적서 번호(estimateData.docNo) 생성된 이후 버튼 활성화 ) * (견적서 번호(estimateData.docNo) 생성된 이후 버튼 활성화 )
* T01관리자 계정 1차판매점에게만 제공 * T01관리자 계정 1차판매점에게만 제공
*/ */
const handleEstimateCopy = async (sendPlanNo, sendCharger, selOptions) => { const handleEstimateCopy = async (sendPlanNo, copyReceiveUser, saleStoreId, otherSaleStoreId) => {
console.log('입력한 값들!@@@@@', sendPlanNo, sendCharger, selOptions) if (saleStoreId === '') {
return alert(getMessage('estimate.detail.productFeaturesPopup.requiredStoreId'))
}
if (copyReceiveUser.trim().length === 0) {
return alert(getMessage('estimate.detail.productFeaturesPopup.requiredReceiveUser'))
}
const params = { const params = {
saleStoreId: session.storeId, saleStoreId: session.storeId,
sapSalesStoreCd: session.custCd, sapSalesStoreCd: session.custCd,
objectNo: objectRecoil.floorPlanObjectNo, objectNo: objectRecoil.floorPlanObjectNo,
planNo: sendPlanNo, planNo: sendPlanNo,
copySaleStoreId: selOptions, copySaleStoreId: otherSaleStoreId ? otherSaleStoreId : saleStoreId,
copyReceiveUser: sendCharger, copyReceiveUser: copyReceiveUser,
userId: session.userId, userId: session.userId,
} }
console.log('전송파람:::', params)
return // return
await promisePost({ url: '/api/estimate/save-estimate-copy', data: params }).then((res) => { await promisePost({ url: '/api/estimate/save-estimate-copy', data: params }).then((res) => {
console.log('복사결과::::::::', res) if (res.status === 201) {
//물건 번호 새로 내려옴 if (isObjectNotEmpty(res.data)) {
//견적서가 복사되었습니다. 복사된 물건정보로 이동합니다. let newObjectNo = res.data.objectNo
// alert(getMessage('estimate.detail.estimateCopyPopup.copy.alertMessage')) alert(getMessage('estimate.detail.estimateCopyPopup.copy.alertMessage'))
router.push(`/management/stuff/detail?objectNo=${newObjectNo.toString()}`, { scroll: false })
}
}
}) })
} }

View File

@ -884,6 +884,8 @@
"estimate.detail.estimateCopyPopup.copy.alertMessage": "見積書がコピーされました. コピーした商品情報に移動します.", "estimate.detail.estimateCopyPopup.copy.alertMessage": "見積書がコピーされました. コピーした商品情報に移動します.",
"estimate.detail.productFeaturesPopup.title": "製品特異事項", "estimate.detail.productFeaturesPopup.title": "製品特異事項",
"estimate.detail.productFeaturesPopup.close": "閉じる", "estimate.detail.productFeaturesPopup.close": "閉じる",
"estimate.detail.productFeaturesPopup.requiredStoreId": "一次販売店は必須です.",
"estimate.detail.productFeaturesPopup.requiredReceiveUser": "担当者は必須です.",
"estimate.detail.save.alertMsg": "保存されている見積書で製品を変更した場合、図面や回路には反映されません.", "estimate.detail.save.alertMsg": "保存されている見積書で製品を変更した場合、図面や回路には反映されません.",
"estimate.detail.save.requiredMsg": "ファイル添付が必須のアイテムがあります。ファイルを添付するか、後日添付をチェックしてください.", "estimate.detail.save.requiredMsg": "ファイル添付が必須のアイテムがあります。ファイルを添付するか、後日添付をチェックしてください.",
"estimate.detail.save.requiredItem": "製品は1つ以上登録する必要があります.", "estimate.detail.save.requiredItem": "製品は1つ以上登録する必要があります.",

View File

@ -894,6 +894,8 @@
"estimate.detail.estimateCopyPopup.copy.alertMessage": "견적서가 복사되었습니다. 복사된 물건정보로 이동합니다.", "estimate.detail.estimateCopyPopup.copy.alertMessage": "견적서가 복사되었습니다. 복사된 물건정보로 이동합니다.",
"estimate.detail.productFeaturesPopup.title": "제품특이사항", "estimate.detail.productFeaturesPopup.title": "제품특이사항",
"estimate.detail.productFeaturesPopup.close": "닫기", "estimate.detail.productFeaturesPopup.close": "닫기",
"estimate.detail.productFeaturesPopup.requiredStoreId": "1차 판매점은 필수값 입니다.",
"estimate.detail.productFeaturesPopup.requiredReceiveUser": "담당자는 필수값 입니다.",
"estimate.detail.save.alertMsg": "저장되었습니다. 견적서에서 제품을 변경할 경우, 도면 및 회로에 반영되지 않습니다.", "estimate.detail.save.alertMsg": "저장되었습니다. 견적서에서 제품을 변경할 경우, 도면 및 회로에 반영되지 않습니다.",
"estimate.detail.save.requiredMsg": "파일첨부가 필수인 아이템이 있습니다. 파일을 첨부하거나 후일첨부를 체크해주십시오.", "estimate.detail.save.requiredMsg": "파일첨부가 필수인 아이템이 있습니다. 파일을 첨부하거나 후일첨부를 체크해주십시오.",
"estimate.detail.save.requiredItem": "제품은 1개이상 등록해야 됩니다.", "estimate.detail.save.requiredItem": "제품은 1개이상 등록해야 됩니다.",