로그인 사용자 건축물 등록 시도코드 적용/ 하수처리장 지도PopUp data 오류 슈ㅜ정/지도점검 오류 수정
This commit is contained in:
@@ -55,12 +55,14 @@ export default function MapFeaturePopup() {
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
console.log(' layerNm ' , layerNm)
|
||||
if (isFeatureCd && layerNm) {
|
||||
if (layerNm === "tb_wr_bdst_ruse_fclt") {
|
||||
setIsDetail(isFeatureCd);
|
||||
} else if (layerNm === "tb_il_swage_prcs_fclt") {
|
||||
pbnMapDetaile(isFeatureCd).then((res) => {
|
||||
setIsDetail(res);
|
||||
console.log('res', res)
|
||||
setIsDetail([res]);
|
||||
});
|
||||
} else if (layerNm === "tb_wr_rnwtr_utztn_fclt") {
|
||||
rainMapDetile(isFeatureCd).then((res) => {
|
||||
|
||||
@@ -255,12 +255,14 @@ export default function Page() {
|
||||
if (selFcltDiv === "RNB") {
|
||||
if (updateRainDetail && updateRainDetail.length > 0) {
|
||||
rainChkDetilUpdate(updateRainDetail, searchYear);
|
||||
setUpdateRainDetail([])
|
||||
} else {
|
||||
toast.error("수정을 원하는 행을 선택하고 저장버튼을 눌러주세요 ");
|
||||
}
|
||||
} else {
|
||||
if (updateRswtDetail && updateRswtDetail.length > 0) {
|
||||
rswtChkDetilsUpdate(updateRswtDetail, searchYear);
|
||||
setUpdateRSwtDetail([])
|
||||
} else {
|
||||
toast.error("수정을 원하는 행을 선택하고 저장버튼을 눌러주세요 ");
|
||||
}
|
||||
|
||||
@@ -1,201 +1,266 @@
|
||||
import { getFetch } from "@/components/lib/api";
|
||||
import { TEST_UUID, type customRainBdst } from "../rainReg";
|
||||
import { TEST_UUID, type customRainBdst } from "../rainReg";
|
||||
import type { customHtdflBdst } from "../htdflReg";
|
||||
import type { customRswtBdst } from "../rswtReg";
|
||||
import type { TableUpperProps } from "@/app/store/common/type/header";
|
||||
import type { SelectDataType } from "@common/business_components/ui";
|
||||
|
||||
const moUpHeadList: TableUpperProps[] = [
|
||||
{ id: "cityText", title: "시도" },
|
||||
{ id: "sggText", title: "시군구" },
|
||||
{ id: "bdstNm", title: "시설명" },
|
||||
{ id: "daddr", title: "위치" },
|
||||
{ id: "frstArchPrmsnDt", title: "최초건축허가일" },
|
||||
{ id: "archArea", title: "건축면적(㎡)" },
|
||||
];
|
||||
|
||||
const moUpHeadList: TableUpperProps[] = [
|
||||
{ id: "cityText", title: "시도" },
|
||||
{ id: "sggText", title: "시군구" },
|
||||
{ id: "bdstNm", title: "시설명" },
|
||||
{ id: "daddr", title: "위치" },
|
||||
{ id: "frstArchPrmsnDt", title: "최초건축허가일" },
|
||||
{ id: "archArea", title: "건축면적(㎡)", },
|
||||
];
|
||||
const bdstChgHeadList: TableUpperProps[] = [
|
||||
{ id: "bdstChgNm", title: "구분" },
|
||||
{ id: "archChgPrmsnDt", title: "허가일" },
|
||||
{ id: "archChgArea", title: "변경면적(㎡)" },
|
||||
];
|
||||
|
||||
const bdstBase: any[] = [];
|
||||
|
||||
const bdstChgHeadList: TableUpperProps[] = [
|
||||
{ id: "bdstChgNm", title: "구분" },
|
||||
{ id: "archChgPrmsnDt", title: "허가일" },
|
||||
{ id: "archChgArea", title: "변경면적(㎡)" },
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
const bdstBase:any[] = [];
|
||||
|
||||
|
||||
const isRainBdst = (data: any): data is customRainBdst=> {
|
||||
const isRainBdst = (data: any): data is customRainBdst => {
|
||||
return data.reuseBuilding?.[0]?.rainyObj !== undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const isHtdflBdst = (data: any): data is customHtdflBdst=> {
|
||||
const isHtdflBdst = (data: any): data is customHtdflBdst => {
|
||||
return data.reuseBuilding?.[0]?.htdflObj !== undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const isRswtBdst = (data: any): data is customRswtBdst =>{
|
||||
const isRswtBdst = (data: any): data is customRswtBdst => {
|
||||
return data.reuseBuilding?.[0]?.rswtrObj !== undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const makeRstr = (
|
||||
data: customRainBdst | customHtdflBdst | customRswtBdst
|
||||
) => {
|
||||
data.rgtr = TEST_UUID;
|
||||
|
||||
|
||||
export const makeRstr =(data:customRainBdst|customHtdflBdst|customRswtBdst) =>{
|
||||
data.rgtr = TEST_UUID;
|
||||
|
||||
let chData
|
||||
if(isRainBdst(data)){
|
||||
let chData;
|
||||
if (isRainBdst(data)) {
|
||||
chData = data.reuseBuilding.map((item) => ({
|
||||
...item,
|
||||
rgtr : TEST_UUID,
|
||||
rainyObj:{
|
||||
rgtr: TEST_UUID,
|
||||
rainyObj: {
|
||||
...item.rainyObj,
|
||||
rgtr:TEST_UUID
|
||||
}
|
||||
rgtr: TEST_UUID,
|
||||
},
|
||||
}));
|
||||
|
||||
data.reuseBuilding=chData;
|
||||
}else if(isHtdflBdst(data)){
|
||||
data.reuseBuilding = chData;
|
||||
} else if (isHtdflBdst(data)) {
|
||||
chData = data.reuseBuilding.map((item) => ({
|
||||
...item,
|
||||
rgtr : TEST_UUID,
|
||||
htdflObj:{
|
||||
rgtr: TEST_UUID,
|
||||
htdflObj: {
|
||||
...item.htdflObj,
|
||||
rgtr:TEST_UUID
|
||||
}
|
||||
rgtr: TEST_UUID,
|
||||
},
|
||||
}));
|
||||
|
||||
data.reuseBuilding=chData;
|
||||
}else if (isRswtBdst(data)){
|
||||
data.reuseBuilding = chData;
|
||||
} else if (isRswtBdst(data)) {
|
||||
chData = data.reuseBuilding.map((item) => ({
|
||||
...item,
|
||||
rgtr : TEST_UUID,
|
||||
rswtrObj:{
|
||||
rgtr: TEST_UUID,
|
||||
rswtrObj: {
|
||||
...item.rswtrObj,
|
||||
rgtr:TEST_UUID
|
||||
}
|
||||
rgtr: TEST_UUID,
|
||||
},
|
||||
}));
|
||||
data.reuseBuilding=chData;
|
||||
data.reuseBuilding = chData;
|
||||
}
|
||||
|
||||
|
||||
if('chgBuilding' in data && Array.isArray(data.chgBuilding) && data.chgBuilding.length > 0){
|
||||
const chRgtr = data.chgBuilding.map((item) =>({...item, rgtr:TEST_UUID, mdfr: item.mdfr ?? null }))
|
||||
data.chgBuilding =chRgtr;
|
||||
}
|
||||
return data;
|
||||
|
||||
if (
|
||||
"chgBuilding" in data &&
|
||||
Array.isArray(data.chgBuilding) &&
|
||||
data.chgBuilding.length > 0
|
||||
) {
|
||||
const chRgtr = data.chgBuilding.map((item) => ({
|
||||
...item,
|
||||
rgtr: TEST_UUID,
|
||||
mdfr: item.mdfr ?? null,
|
||||
}));
|
||||
data.chgBuilding = chRgtr;
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
export const makeMdfr =(data:customRainBdst|customHtdflBdst|customRswtBdst) =>{
|
||||
data.mdfr = TEST_UUID;
|
||||
let chData
|
||||
if(isRainBdst(data)){
|
||||
chData = data.reuseBuilding.map((item) => ({
|
||||
...item,
|
||||
mdfr : TEST_UUID,
|
||||
rainyObj:{
|
||||
...item.rainyObj,
|
||||
mdfr:TEST_UUID
|
||||
}
|
||||
}));
|
||||
if(data?.chgBuilding.length>0){
|
||||
const chRgtr = data.chgBuilding.map((item) =>({...item, rgtr:TEST_UUID, mdfr: item.mdfr ?? null }))
|
||||
data.chgBuilding =chRgtr;
|
||||
}
|
||||
|
||||
data.reuseBuilding=chData
|
||||
}else if(isHtdflBdst(data)){
|
||||
chData = data.reuseBuilding.map((item) => ({
|
||||
export const makeMdfr = (
|
||||
data: customRainBdst | customHtdflBdst | customRswtBdst
|
||||
) => {
|
||||
data.mdfr = TEST_UUID;
|
||||
let chData;
|
||||
if (isRainBdst(data)) {
|
||||
chData = data.reuseBuilding.map((item) => ({
|
||||
...item,
|
||||
mdfr: TEST_UUID,
|
||||
rainyObj: {
|
||||
...item.rainyObj,
|
||||
mdfr: TEST_UUID,
|
||||
},
|
||||
}));
|
||||
if (data?.chgBuilding.length > 0) {
|
||||
const chRgtr = data.chgBuilding.map((item) => ({
|
||||
...item,
|
||||
mdfr : TEST_UUID,
|
||||
htdflObj:{
|
||||
...item.htdflObj,
|
||||
mdfr:TEST_UUID
|
||||
}
|
||||
rgtr: TEST_UUID,
|
||||
mdfr: item.mdfr ?? null,
|
||||
}));
|
||||
data.reuseBuilding=chData;
|
||||
}else if (isRswtBdst(data)){
|
||||
chData = data.reuseBuilding.map((item) => ({
|
||||
...item,
|
||||
mdfr : TEST_UUID,
|
||||
rswtrObj:{
|
||||
...item.rswtrObj,
|
||||
mdfr:TEST_UUID
|
||||
}
|
||||
}));
|
||||
data.reuseBuilding=chData;
|
||||
data.chgBuilding = chRgtr;
|
||||
}
|
||||
|
||||
if('chgBuilding' in data && Array.isArray(data.chgBuilding) && data.chgBuilding.length > 0){
|
||||
const chMdfr = data.chgBuilding.map((item) =>({...item, mdfr:TEST_UUID, archChgArea: item.archChgArea ?? '' }))
|
||||
data.chgBuilding =chMdfr;
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
data.reuseBuilding = chData;
|
||||
} else if (isHtdflBdst(data)) {
|
||||
chData = data.reuseBuilding.map((item) => ({
|
||||
...item,
|
||||
mdfr: TEST_UUID,
|
||||
htdflObj: {
|
||||
...item.htdflObj,
|
||||
mdfr: TEST_UUID,
|
||||
},
|
||||
}));
|
||||
data.reuseBuilding = chData;
|
||||
} else if (isRswtBdst(data)) {
|
||||
chData = data.reuseBuilding.map((item) => ({
|
||||
...item,
|
||||
mdfr: TEST_UUID,
|
||||
rswtrObj: {
|
||||
...item.rswtrObj,
|
||||
mdfr: TEST_UUID,
|
||||
},
|
||||
}));
|
||||
data.reuseBuilding = chData;
|
||||
}
|
||||
|
||||
if (
|
||||
"chgBuilding" in data &&
|
||||
Array.isArray(data.chgBuilding) &&
|
||||
data.chgBuilding.length > 0
|
||||
) {
|
||||
const chMdfr = data.chgBuilding.map((item) => ({
|
||||
...item,
|
||||
mdfr: TEST_UUID,
|
||||
archChgArea: item.archChgArea ?? "",
|
||||
}));
|
||||
data.chgBuilding = chMdfr;
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export type bdstFulType = bdstState & bdstActions;
|
||||
|
||||
|
||||
export type bdstState = {
|
||||
bdst: {
|
||||
bdstBase: any[];
|
||||
moUpHeadList:TableUpperProps[]
|
||||
bdstChgHeadList:TableUpperProps[]
|
||||
moUpHeadList: TableUpperProps[];
|
||||
bdstChgHeadList: TableUpperProps[];
|
||||
userCityCd: SelectDataType[];
|
||||
userSggCd: SelectDataType[];
|
||||
};
|
||||
};
|
||||
|
||||
type bdstActions = {
|
||||
findBdst: (sggCd:string, searchTxt:string, flag:string) => void ;
|
||||
};
|
||||
|
||||
|
||||
const findBdstInfo = async(sggCd:string, searchTxt:string ,flg:string)=>{
|
||||
return await getFetch('wr', `/reuseFc/building/${flg}/${sggCd}`+(searchTxt?`/${searchTxt}`:'' ))
|
||||
|
||||
}
|
||||
|
||||
findBdst: (sggCd: string, searchTxt: string, flag: string) => void;
|
||||
setUserCitySggCd: (
|
||||
laeSeCd: string,
|
||||
cityCd: SelectDataType[],
|
||||
sggCd: SelectDataType[]) => void;
|
||||
setUserSggCd: ( userCityCd: string,sggCd: SelectDataType[]) => void;
|
||||
};
|
||||
|
||||
const findBdstInfo = async (sggCd: string, searchTxt: string, flg: string) => {
|
||||
return await getFetch(
|
||||
"wr",
|
||||
`/reuseFc/building/${flg}/${sggCd}` + (searchTxt ? `/${searchTxt}` : "")
|
||||
);
|
||||
};
|
||||
|
||||
export const bdstStateExport: bdstState = {
|
||||
bdst: {
|
||||
bdstBase: bdstBase, // Updated to match the array type
|
||||
moUpHeadList:moUpHeadList,
|
||||
bdstChgHeadList:bdstChgHeadList,
|
||||
userCityCd: [],
|
||||
userSggCd: [],
|
||||
moUpHeadList: moUpHeadList,
|
||||
bdstChgHeadList: bdstChgHeadList,
|
||||
},
|
||||
};
|
||||
|
||||
export const bdstActionsExport: (set: any) => bdstActions = (
|
||||
set: any
|
||||
) => {
|
||||
export const bdstActionsExport: (set: any) => bdstActions = (set: any) => {
|
||||
return {
|
||||
|
||||
findBdst: async(sggCd:string, searchTxt:string ,flg:string ) =>{
|
||||
try{
|
||||
|
||||
const bdst = await findBdstInfo(sggCd, searchTxt, flg);
|
||||
const makeBdst = bdst.map((item:any) => {
|
||||
return {
|
||||
...item,
|
||||
reuseBuilding:[]
|
||||
};
|
||||
})
|
||||
return set((state:bdstState) =>({
|
||||
...state,
|
||||
bdst:{
|
||||
...state.bdst,
|
||||
bdstBase:makeBdst
|
||||
}
|
||||
|
||||
}))
|
||||
}catch(error1){
|
||||
console.log("error ", error1)
|
||||
|
||||
}finally{
|
||||
|
||||
}
|
||||
findBdst: async (sggCd: string, searchTxt: string, flg: string) => {
|
||||
try {
|
||||
const bdst = await findBdstInfo(sggCd, searchTxt, flg);
|
||||
const makeBdst = bdst.map((item: any) => {
|
||||
return {
|
||||
...item,
|
||||
reuseBuilding: [],
|
||||
};
|
||||
});
|
||||
return set((state: bdstState) => ({
|
||||
...state,
|
||||
bdst: {
|
||||
...state.bdst,
|
||||
bdstBase: makeBdst,
|
||||
},
|
||||
}));
|
||||
} catch (error1) {
|
||||
console.log("error ", error1);
|
||||
} finally {
|
||||
}
|
||||
},
|
||||
setUserCitySggCd: (
|
||||
laeSeCd: string,
|
||||
cityCd: SelectDataType[],
|
||||
sggCd: SelectDataType[]
|
||||
) => {
|
||||
let city = [...cityCd];
|
||||
let sgg = [...sggCd]
|
||||
console.log('sgg ', sgg)
|
||||
if (laeSeCd === "0" && cityCd.length > 0) {
|
||||
city = city;
|
||||
sgg = [{ val: "0", text: "전체" }]
|
||||
} else if (laeSeCd.length === 2 && cityCd.length > 0) {
|
||||
city = cityCd.filter((item) => item.val === laeSeCd);
|
||||
sgg = sggCd.filter((item) => item.val.slice(0, 2) === laeSeCd);
|
||||
sggCd.unshift({ val: "0", text: "전체" });
|
||||
|
||||
} else if (
|
||||
laeSeCd.length === 5 &&
|
||||
cityCd.length > 0 &&
|
||||
sggCd.length > 0
|
||||
) {
|
||||
city = cityCd.filter((item) => item.val === laeSeCd.slice(0, 2));
|
||||
sgg = sggCd.filter((item) => item.val === laeSeCd);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return set((state: bdstState) => ({
|
||||
|
||||
|
||||
...state,
|
||||
bdst: {
|
||||
...state.bdst,
|
||||
userCityCd: city,
|
||||
userSggCd: sgg,
|
||||
},
|
||||
}));
|
||||
},setUserSggCd( userCityCd: string,sggCd: SelectDataType[]){
|
||||
|
||||
|
||||
const sgg = sggCd.filter((item) => item.val.slice(0, 2) === userCityCd);
|
||||
|
||||
return set((state: bdstState) => ({
|
||||
...state,
|
||||
bdst: {
|
||||
...state.bdst,
|
||||
userSggCd: sgg,
|
||||
},
|
||||
}));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -37,7 +37,11 @@ export const tableData = (data: any, code: comCodeState) => {
|
||||
(item: {
|
||||
sggCd: string;
|
||||
ctpvCd: string;
|
||||
reuseBuilding: { lawTrgtYn: string; bdstUsgCd: string ,grntchBdstCertGrd:string}[];
|
||||
reuseBuilding: {
|
||||
lawTrgtYn: string;
|
||||
bdstUsgCd: string;
|
||||
grntchBdstCertGrd: string;
|
||||
}[];
|
||||
}) => {
|
||||
let returnData = {};
|
||||
const sggText = chCode.sggCd.find(
|
||||
@@ -47,15 +51,13 @@ export const tableData = (data: any, code: comCodeState) => {
|
||||
(cd) => cd.val === String(item.ctpvCd).trim()
|
||||
)?.text;
|
||||
if (item?.reuseBuilding?.length > 0) {
|
||||
|
||||
const bdsgUsgText = chCode?.bdstTotalUsgType?.find(
|
||||
(cd) => cd.val === item?.reuseBuilding[0]?.bdstUsgCd
|
||||
)?.text;
|
||||
|
||||
const lawTrgtYn = item?.reuseBuilding[0]?.lawTrgtYn;
|
||||
|
||||
|
||||
const grntchBdstCertGrdText =chCode?.bdstGrntchClass?.find(
|
||||
const grntchBdstCertGrdText = chCode?.bdstGrntchClass?.find(
|
||||
(cd) => cd.val === item?.reuseBuilding[0]?.grntchBdstCertGrd
|
||||
)?.text;
|
||||
|
||||
@@ -65,7 +67,7 @@ export const tableData = (data: any, code: comCodeState) => {
|
||||
cityText: cityText ?? "없음",
|
||||
bdsgUsgText: bdsgUsgText,
|
||||
lawTrgtYn: lawTrgtYn,
|
||||
grntchBdstCertGrdText:grntchBdstCertGrdText
|
||||
grntchBdstCertGrdText: grntchBdstCertGrdText,
|
||||
};
|
||||
} else {
|
||||
returnData = {
|
||||
@@ -160,13 +162,13 @@ export const formatCommaNumber = (
|
||||
};
|
||||
|
||||
//내가 쓰는 값이 숫자이냐 아니냐
|
||||
export const isNumeric =(value: string) => {
|
||||
if(value&&value.length>0){
|
||||
export const isNumeric = (value: string) => {
|
||||
if (value && value.length > 0) {
|
||||
return value?.trim() !== "" && !isNaN(Number(value));
|
||||
}else{
|
||||
return false
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getCityOrSgg = (ref: RefObject<ReturnType>) => {
|
||||
let con;
|
||||
@@ -219,11 +221,15 @@ export const formatPhoneNumber = (tel: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const confirmToast = (content: string, saveFunc: () => void, contentClass?:string) => {
|
||||
export const confirmToast = (
|
||||
content: string,
|
||||
saveFunc: () => void,
|
||||
contentClass?: string
|
||||
) => {
|
||||
toast(
|
||||
(t) => (
|
||||
<span className="flex flex-col items-center">
|
||||
<div className={`mb-6 ${contentClass}`} >{content}</div>
|
||||
<div className={`mb-6 ${contentClass}`}>{content}</div>
|
||||
<div className="flex flex-row space-x-2">
|
||||
<Button
|
||||
size={"sm"}
|
||||
@@ -289,8 +295,7 @@ export const formatYyyymmdd = (val: string | undefined) => {
|
||||
* @param value 입력 문자열
|
||||
* @param digits 소수점 자릿수 (기본 0 = 정수 반올림)
|
||||
*/
|
||||
export const formatArchArea =(value: string, digits: number=0 ) => {
|
||||
|
||||
export const formatArchArea = (value: string, digits: number = 0) => {
|
||||
// "확인불가" 등 숫자 아님 → 그대로 반환
|
||||
const cleaned = value.replace(/,/g, "");
|
||||
const num = parseFloat(cleaned);
|
||||
@@ -304,23 +309,83 @@ export const formatArchArea =(value: string, digits: number=0 ) => {
|
||||
|
||||
// 다시 천 단위 콤마 찍어서 반환
|
||||
return Number(rounded).toLocaleString();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const codeToText = ( val:string, codeName:string ) =>{
|
||||
|
||||
if(val===''|| val===undefined){
|
||||
return ''
|
||||
export const codeToText = (val: string, codeName: string) => {
|
||||
if (val === "" || val === undefined) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return lwCds[codeName]?.find((cd) => cd.val ===val)?.text
|
||||
}
|
||||
return lwCds[codeName]?.find((cd) => cd.val === val)?.text;
|
||||
};
|
||||
|
||||
export const textToCode = (text:string, codeName:string) =>{
|
||||
if(text===''|| text===undefined){
|
||||
return ''
|
||||
export const textToCode = (text: string, codeName: string) => {
|
||||
if (text === "" || text === undefined) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return lwCds[codeName]?.find((cd) => cd.text ===text)?.val
|
||||
return lwCds[codeName]?.find((cd) => cd.text === text)?.val;
|
||||
};
|
||||
|
||||
// export const handleLaeSeCdChange = (
|
||||
// laeSeCd: string,
|
||||
// cityCd: SelectDataType[],
|
||||
// sggCd: SelectDataType[]
|
||||
// ): { isCityCd: SelectDataType[]; isSggCd: SelectDataType[] } => {
|
||||
// if (laeSeCd.length !== 5 && cityCd.length > 0) {
|
||||
// const city =
|
||||
// laeSeCd === "0" ? cityCd : cityCd.filter((item) => item.val === laeSeCd);
|
||||
|
||||
// const sgg = sggCd.filter((item) => item.val.slice(0, 2) === laeSeCd);
|
||||
// sgg.unshift({ text: "전체", val: "0" });
|
||||
|
||||
// return { isCityCd: city, isSggCd: sgg };
|
||||
// } else if (laeSeCd.length === 5 && cityCd.length > 0 && sggCd.length > 0) {
|
||||
// const city = cityCd.filter((item) => item.val === laeSeCd.slice(0, 2));
|
||||
|
||||
// const sgg = sggCd.filter((item) => item.val === laeSeCd);
|
||||
// sgg.unshift({ text: "전체", val: "0" });
|
||||
|
||||
// return { isCityCd: city, isSggCd: sgg };
|
||||
// }
|
||||
|
||||
// // 기본 반환값 (조건에 안 맞을 때)
|
||||
// return { isCityCd: [], isSggCd: [] };
|
||||
// };
|
||||
|
||||
|
||||
|
||||
|
||||
export function handleLaeSeCdChange(
|
||||
laeSeCd: string,
|
||||
cityCd: SelectDataType[] = [],
|
||||
sggCd: SelectDataType[] = []
|
||||
): { isCityCd: SelectDataType[]; isSggCd: SelectDataType[] } {
|
||||
const isAll = laeSeCd === "0"; // 전체
|
||||
const isSgg = laeSeCd.length === 5; // 시군구 코드
|
||||
const prefix = isAll ? "" : laeSeCd.slice(0, 2); // 시 코드(앞 2자리)
|
||||
|
||||
// 시 리스트: 전체면 전부, SGG 선택이면 해당 시만, 시 선택이면 그 시만
|
||||
const isCityCd = isAll
|
||||
? cityCd
|
||||
: isSgg
|
||||
? cityCd.filter(city => city.val === prefix)
|
||||
: cityCd.filter(city => city.val === laeSeCd);
|
||||
|
||||
// 시군구 리스트: 전체면 비움(+ 전체만), 아니면 prefix로 필터
|
||||
const sggInCity = isAll
|
||||
? []
|
||||
: sggCd.filter(s => s.val.slice(0, 2) === prefix);
|
||||
|
||||
// 선택된 SGG가 있으면 맨 위로(옵션)
|
||||
const sggOrdered = isSgg
|
||||
? [...sggInCity].sort((a, b) =>
|
||||
a.val === laeSeCd ? -1 : b.val === laeSeCd ? 1 : 0
|
||||
)
|
||||
: sggInCity;
|
||||
|
||||
return {
|
||||
isCityCd,
|
||||
isSggCd: [{ text: "전체", val: "0" }, ...sggOrdered],
|
||||
};
|
||||
}
|
||||
@@ -22,12 +22,10 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) {
|
||||
const [useSggCd, setUserSggCd] = useState<SelectDataType[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
let city = [] as SelectDataType[];
|
||||
if (laeSeCd.length === 2 && code.cityCd.length > 0) {
|
||||
const city = code.cityCd.filter((item) => item.val === laeSeCd);
|
||||
const sgg = code.sggCd.filter((item) => item.val.slice(0, 2) === laeSeCd);
|
||||
sgg.unshift({ text: "전체", val: "0" });
|
||||
city = code.cityCd.filter((item) => item.val === laeSeCd);
|
||||
setUserCityCd(city); // Fix: Ensure city is of type SelectDataType[]
|
||||
setUserSggCd(sgg);
|
||||
if (city[0]?.val) {
|
||||
// 여기 중요
|
||||
queueMicrotask(() => {
|
||||
@@ -43,15 +41,21 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) {
|
||||
code.cityCd.length > 0 &&
|
||||
code.sggCd.length > 0
|
||||
) {
|
||||
const city = code.cityCd.filter(
|
||||
(item) => item.val === laeSeCd.slice(0, 2)
|
||||
);
|
||||
const sgg = code.sggCd.filter((item) => item.val === laeSeCd);
|
||||
setUserSggCd(sgg);
|
||||
city = code.cityCd.filter((item) => item.val === laeSeCd.slice(0, 2));
|
||||
setUserCityCd(city);
|
||||
form.setValue("ctpvCd", Number(city[0]?.val));
|
||||
form.setValue("sggCd", Number(sgg[0]?.val));
|
||||
} else if (
|
||||
laeSeCd === "0" &&
|
||||
code.cityCd.length > 0 &&
|
||||
code.sggCd.length > 0
|
||||
) {
|
||||
setUserCityCd(code.cityCd);
|
||||
}
|
||||
if (city.length > 0)
|
||||
form.setValue("ctpvCd", Number(city[0]?.val), {
|
||||
shouldDirty: true,
|
||||
shouldTouch: true,
|
||||
shouldValidate: true,
|
||||
});
|
||||
}, [form, laeSeCd, code.cityCd, code.sggCd]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -70,11 +74,34 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) {
|
||||
const userCtpvCd = form.watch("ctpvCd");
|
||||
const userSggCd = form.watch("sggCd");
|
||||
|
||||
useEffect(() => {
|
||||
const city = String(userCtpvCd);
|
||||
|
||||
if (city && city === "0") {
|
||||
setUserSggCd([{ text: "전체", val: "0" }]);
|
||||
|
||||
form.setValue("sggCd", 0, {
|
||||
shouldDirty: true,
|
||||
shouldTouch: true,
|
||||
shouldValidate: true,
|
||||
});
|
||||
} else if (city && city.length === 2) {
|
||||
const sgg = code.sggCd.filter((item) => item.val.slice(0, 2) === city);
|
||||
setUserSggCd(sgg);
|
||||
form.setValue("sggCd", Number(sgg[0]?.val), {
|
||||
shouldDirty: true,
|
||||
shouldTouch: true,
|
||||
shouldValidate: true,
|
||||
});
|
||||
}
|
||||
}, [userCtpvCd]);
|
||||
|
||||
useEffect(() => {
|
||||
const strCtpvCd = String(userCtpvCd);
|
||||
|
||||
if (strCtpvCd && strCtpvCd !== "0") {
|
||||
const city = returnCodeText(strCtpvCd, "cityCd");
|
||||
|
||||
form?.setValue("daddr", city);
|
||||
} else if (strCtpvCd === "0") {
|
||||
form?.setValue("daddr", "");
|
||||
@@ -93,6 +120,7 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) {
|
||||
String(form.getValues("ctpvCd")),
|
||||
"cityCd"
|
||||
);
|
||||
if(ctpvCdText!=='전체')
|
||||
form?.setValue("daddr", ctpvCdText);
|
||||
}
|
||||
}, [userSggCd]);
|
||||
@@ -111,6 +139,7 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) {
|
||||
render={({ field }) => (
|
||||
<FormUi label="시도">
|
||||
<SelectBox
|
||||
key={`sgg-${String(userCtpvCd)}`}
|
||||
className="col-span-3"
|
||||
label={""}
|
||||
selectClass={selectClass}
|
||||
@@ -118,11 +147,7 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) {
|
||||
onSelectValue={(val) => {
|
||||
field.onChange(Number(val));
|
||||
}}
|
||||
value={
|
||||
typeof field.value !== "undefined"
|
||||
? field.value
|
||||
: useCityCd[0]?.val
|
||||
}
|
||||
value={field.value??useCityCd[0]?.val}
|
||||
/>
|
||||
</FormUi>
|
||||
)}
|
||||
@@ -136,13 +161,14 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) {
|
||||
<FormUi label="시군구">
|
||||
<SelectBox
|
||||
className="col-span-3"
|
||||
key={`sgg-${String(userSggCd)}`}
|
||||
label={""}
|
||||
selectClass={`w-full min-h-[2.9rem] ${selectClass}`}
|
||||
selectArray={useSggCd}
|
||||
onSelectValue={(val) => {
|
||||
field.onChange(Number(val));
|
||||
}}
|
||||
value={field.value}
|
||||
value={field.value??useSggCd[0]?.val}
|
||||
/>
|
||||
</FormUi>
|
||||
)}
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
} from "@common/business_components";
|
||||
import { Button, Input, Label } from "@common/components";
|
||||
import { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
export type objSearchType = {
|
||||
sgg: string | number;
|
||||
@@ -68,7 +69,12 @@ export function BdstReg<T extends MoType>({
|
||||
data = objSearch.sgg;
|
||||
}
|
||||
//RNB(빗물), RST(중수도), HTB(온배수)
|
||||
findBdst(String(data), searchTxt || "", moType);
|
||||
if(data){
|
||||
|
||||
findBdst(String(data), searchTxt || "", moType);
|
||||
}else{
|
||||
toast.error("시도 또는 시군구를 선택하여 주십시오.");
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -88,33 +94,41 @@ export function BdstReg<T extends MoType>({
|
||||
}, [bdst]);
|
||||
|
||||
useEffect(() => {
|
||||
let city = [] as SelectDataType[];
|
||||
if (laeSeCd.length === 2 && code.cityCd.length > 0) {
|
||||
const city = code.cityCd.filter((item) => item.val === laeSeCd);
|
||||
const sgg = code.sggCd.filter((item) => item.val.slice(0, 2) === laeSeCd);
|
||||
sgg.unshift({ text: "전체", val: "0" });
|
||||
city = code.cityCd.filter((item) => item.val === laeSeCd);
|
||||
setUserCityCd(city); // Fix: Ensure city is of type SelectDataType[]
|
||||
setObjSearch({ ...objSearch, city: String(city[0]?.val) });
|
||||
setUserSggCd(sgg);
|
||||
} else if (
|
||||
laeSeCd.length === 5 &&
|
||||
code.cityCd.length > 0 &&
|
||||
code.sggCd.length > 0
|
||||
) {
|
||||
const city = code.cityCd.filter(
|
||||
(item) => item.val === laeSeCd.slice(0, 2)
|
||||
);
|
||||
city = code.cityCd.filter((item) => item.val === laeSeCd.slice(0, 2));
|
||||
setUserCityCd(city);
|
||||
const sgg = code.sggCd.filter((item) => item.val === laeSeCd);
|
||||
setUserSggCd(sgg);
|
||||
setObjSearch({ city: String(city[0]?.val), sgg: String(sgg[0]?.val) });
|
||||
} else if (
|
||||
laeSeCd === "0" &&
|
||||
code.cityCd.length > 0 &&
|
||||
code.sggCd.length > 0
|
||||
) {
|
||||
setUserCityCd(code.cityCd);
|
||||
}
|
||||
if (city.length > 0)
|
||||
setObjSearch({ ...objSearch, city: Number(city[0]?.val) ?? "0" });
|
||||
}, [laeSeCd, code.cityCd, code.sggCd]);
|
||||
|
||||
useEffect(() => {
|
||||
const city = String(objSearch.city);
|
||||
if (city === "0") {
|
||||
setUserSggCd([{ text: "전체", val: "0" }]);
|
||||
setObjSearch({ ...objSearch, sgg: "0" });
|
||||
} else if (city.length === 2) {
|
||||
const sgg = code.sggCd.filter((item) => item.val.slice(0, 2) === city);
|
||||
//sgg.unshift({ text: "전체", val: "0" });
|
||||
setUserSggCd(sgg);
|
||||
setObjSearch({ ...objSearch, sgg: Number(sgg[0]?.val) });
|
||||
}
|
||||
}, [objSearch.city]);
|
||||
|
||||
const tableClick: (val: number | undefined, headId: string) => void = (
|
||||
val
|
||||
) => {
|
||||
@@ -136,21 +150,23 @@ export function BdstReg<T extends MoType>({
|
||||
className="col-span-3 h-full"
|
||||
label={"시도"}
|
||||
selectClass={selectClass}
|
||||
key={`city-${String(objSearch.city)}`}
|
||||
selectArray={useCityCd}
|
||||
onSelectValue={(val) => {
|
||||
setObjSearch({ ...objSearch, city: String(val) });
|
||||
setObjSearch({ ...objSearch, city: Number(val) });
|
||||
}}
|
||||
value={objSearch.city || useCityCd[0]?.val}
|
||||
value={objSearch.city ?? useCityCd[0]?.val}
|
||||
></SelectBox>
|
||||
<SelectBox
|
||||
className="col-span-3 h-full"
|
||||
label={"시군구"}
|
||||
key={`sgg-${String(objSearch.sgg)}`}
|
||||
selectClass={selectClass}
|
||||
selectArray={useSggCd || []}
|
||||
onSelectValue={(val) => {
|
||||
if (val) setObjSearch({ ...objSearch, sgg: String(val) });
|
||||
if (val) setObjSearch({ ...objSearch, sgg: Number(val) });
|
||||
}}
|
||||
value={objSearch.sgg || useSggCd[0]?.val}
|
||||
value={objSearch.sgg ?? useSggCd[0]?.val}
|
||||
>
|
||||
{" "}
|
||||
</SelectBox>
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user