From ca30fc9a331d48dac831c1611f3fc2364a563d1d Mon Sep 17 00:00:00 2001 From: leedj312 Date: Fri, 28 Mar 2025 18:00:56 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B1=B4=EC=B6=95=EB=AC=BC=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EA=B0=9C=EB=B0=9C?= =?UTF-8?q?=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruseFcltMng/fcltReg/bdstReg/index.tsx | 88 +++++++++++++++++++ apps/wr/app/store/store.tsx | 9 +- .../ui/form/fcltReg/bdstReg/component.tsx | 84 +++++++++++++++++- .../ui/form/fcltReg/rainReg/component.tsx | 2 +- .../components/ui/modal/bdstReg/component.tsx | 69 ++++++++++----- 5 files changed, 225 insertions(+), 27 deletions(-) create mode 100644 apps/wr/app/store/ruseFcltMng/fcltReg/bdstReg/index.tsx diff --git a/apps/wr/app/store/ruseFcltMng/fcltReg/bdstReg/index.tsx b/apps/wr/app/store/ruseFcltMng/fcltReg/bdstReg/index.tsx new file mode 100644 index 000000000..966d415b3 --- /dev/null +++ b/apps/wr/app/store/ruseFcltMng/fcltReg/bdstReg/index.tsx @@ -0,0 +1,88 @@ +import { getFectch } from "@/components/lib/api"; + +type bdstType={ + bdstInfoPk: number, + ctpvCd: number, + sggCd: number, + daddr: string, + bdstNm: string, + frstArchPrmsnDt: string, + archArea : number +} + + +type TableUpperProps = { + id: string; + title: string; + upName?: string; + upSequnce?: number; + }; + const moUpHeadList: TableUpperProps[] = [ + { id: "cityText", title: "시도" }, + { id: "sggText", title: "시군구" }, + { id: "bdstNm", title: "시설명" }, + { id: "daddr", title: "위치" }, + { id: "frstArchPrmsnDt", title: "최초건축허가일" }, + { id: "archArea", title: "건축면적", }, + { id: "archChgYn", title: "여부", upName: "upChangeRe", upSequnce: 1 }, + { id: "archChgPrmsnDt", title: "허가일", upName: "upChangeRe", upSequnce: 2 }, + { id: "archChgArea", title: "면적", upName: "upChangeRe", upSequnce: 3 }, + ]; + +const bdstBase: bdstType[] = []; + +export type bdstFulType = bdstState & bdstActions; + + +export type bdstState = { + bdst: { + bdstBase: bdstType[]; + moUpHeadList:TableUpperProps[] + }; +}; + +type bdstActions = { + findBdst: (val: string) => Promise; + }; + + + +export const bdstStateExport: bdstState = { + bdst: { + bdstBase: bdstBase, // Updated to match the array type + moUpHeadList:moUpHeadList, + }, +}; + + + + + + + +export const bdstActionsExport: (set: any) => bdstActions = ( + set: any +) => { + return { + findBdst: async(val:string) =>{ + try { + console.log(" val ", val); + // (val!=='' ?"/"+val:'') + const res = await getFectch('wr', "/reuseFc/building/42" +(val!=='' ?"/"+val:'')); + console.log("res ", res) + // 여기서 상태 업데이트 + return set((state: bdstState) => ({ + bdst: { + ...state.bdst, + bdstBase:res, + } + })); + } catch (error) { + console.log('error', error); + } finally { + console.log('finally'); + } + }, + + }; +}; diff --git a/apps/wr/app/store/store.tsx b/apps/wr/app/store/store.tsx index 4a94a03fa..91f795ea4 100644 --- a/apps/wr/app/store/store.tsx +++ b/apps/wr/app/store/store.tsx @@ -30,26 +30,30 @@ import { type htdflFacType, } from "./ruseFcltMng/fcltReg/htdflReg"; import { codeActionExport, comCodeStateExport, getCityCd, getSggCd, type comCodeState, type comCodeType } from "./common/code"; +import { bdstActionsExport, bdstStateExport, type bdstFulType, type bdstState } from "./ruseFcltMng/fcltReg/bdstReg"; export type WrStore = comCodeType& pubFacType & rainFacType & rswtFacType & matDmdType & - htdflFacType; + htdflFacType& + bdstFulType; export const StoreZus = ( initState: comCodeState& rainFacState & pubFacState & rswtFacState & matDmdState & - htdflFacState = { + htdflFacState & + bdstState= { ...comCodeStateExport, ...pubFacStateExport, ...rainFacStateExport, ...rswtFacStateExport, ...matDmdStateExport, ...htdflFacStateExport, + ...bdstStateExport, } ) => { return createStore()((set) => { @@ -63,6 +67,7 @@ export const StoreZus = ( ...matDmdActionsExport(set), ...htdflFacActionsExport(set), ...codeActionExport(set), + ...bdstActionsExport(set) }; }); }; diff --git a/apps/wr/components/ui/form/fcltReg/bdstReg/component.tsx b/apps/wr/components/ui/form/fcltReg/bdstReg/component.tsx index 0a13b41fa..2cafa0973 100644 --- a/apps/wr/components/ui/form/fcltReg/bdstReg/component.tsx +++ b/apps/wr/components/ui/form/fcltReg/bdstReg/component.tsx @@ -2,12 +2,32 @@ import { useWrStore } from "@/app/store"; import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; import { FormField, FormUi, SelectBox } from "@common/business_components"; import { Button, Input } from "@common/components"; +import { useFieldArray } from "react-hook-form"; export default function BdstReg(form: any) { const { code } = useWrStore((state) => { return state; }); + const { fields, append, remove } = useFieldArray({ + control: form.control, + name: "history" + }); + + const plusHist = () => { + append({ + bdstNm: '', + daddr: '', + bdstUsgCd: '' + }); + }; + + const removeLastItem = () => { + if (fields.length > 0) { + remove(fields.length - 1); + } + }; + return ( <> @@ -165,10 +185,68 @@ export default function BdstReg(form: any) {

중축, 개축, 증축

-
- +
+ +
-
+ + {fields.map((field, index) => ( +
+
+ ( + + { + field.onChange(val); + }} + value={field.value} + /> + + )} + /> +
+
+ ( + + + + )} + /> +
+
+ ( + + + + )} + /> +
+
+ ))} +
); } diff --git a/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx b/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx index 98d0e28a9..088c7fd43 100644 --- a/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx +++ b/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx @@ -27,7 +27,6 @@ export function RainRegForm({ data: rainRuseBd[]; isModal: boolean; }) { - console.log(isModal); const formSchema = isModal ? z.object({ ...rainZod, ...bdstZod }) : z.object(rainZod); @@ -35,6 +34,7 @@ export function RainRegForm({ const { rain, code } = useWrStore((state) => state); const { rainFcltCd } = code; useEffect(() => { + // console.log( " data ", data) if (data && data.length > 0) { console.log(data); const selectedOption = rainFcltCd.find( diff --git a/apps/wr/components/ui/modal/bdstReg/component.tsx b/apps/wr/components/ui/modal/bdstReg/component.tsx index d2693cd35..9fbfd4333 100644 --- a/apps/wr/components/ui/modal/bdstReg/component.tsx +++ b/apps/wr/components/ui/modal/bdstReg/component.tsx @@ -4,6 +4,7 @@ import { useWrStore } from "@/app/store"; import { selectClass, type bdstType, + type selectArray, } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; import { ScrollArea, SearchInput, SelectBox, UiTable } from "@common/business_components"; import { Button, Input } from "@common/components"; @@ -11,41 +12,69 @@ import { useEffect, useState } from "react"; import { RainRegForm } from "../../form/fcltReg/rainReg/component"; export function BdstReg() { - const { rain, code, init } = useWrStore((state) => { + const { rain, code, bdst, findBdst } = useWrStore((state) => { return state; }); const [bdstTable, setbdstTable] = useState(); - const [rainBdstForm, setRainBdstForm] = useState<[]>(); + const [rainBdstForm, setRainBdstForm] = useState(); const { bdstObj, rainRuseObj } = rain; - const getCity = (val: string | number) => { - console.log(val); + const [selectSgg, setSelectSgg] = useState() + const [searchTxt, setSearchTxt] = useState() + + const getCity = (val: string ) => { + + + const data = code.sggCd + .filter((item) => String(item.val).substring(0, 2) === val) + .map((item) => ({ ...item, val: String(item.val) })); // Ensure 'val' is a string + setSelectSgg(data); }; const getSgg = (val: string | number) => { console.log(val); }; + + + useEffect(()=>{ + + // console.log("searchTxt ", searchTxt) + findBdst(searchTxt) + },[searchTxt]) + useEffect(() => { if (code.sggCd.length > 0) { - const table = bdstObj.map((item) => { + const table = bdst?.bdstBase?.map((item) => { const sggText = code.sggCd.find( - (cd) => cd.val.toString() === item.sggCd + (cd) => cd.val === Number(item.sggCd) )?.text; const cityText = code.cityCd.find( - (cd) => cd.val.toString() === item.ctpvCd + (cd) => cd.val === Number(item.ctpvCd) )?.text; return { ...item, sggText: sggText, cityText: cityText }; }); + + setbdstTable(table); } - }, [code, bdstObj]); + }, [code, bdst]); - const cellClick = () => {}; - const nodeList = headMakeColSpan(rain.upHeadList); + const tableClick: (val: number | undefined) => void = (val) => { + + console.log("val , " ,val) + console.log("bdst , " ,bdst?.bdstBase[val]) + if(val!==undefined && bdst?.bdstBase.length>0){ + const data =bdst?.bdstBase[val] + console.log("data ", [data]) + setRainBdstForm([data]); + } + } + + const nodeList = headMakeColSpan(bdst.moUpHeadList); return ( <> -
+
{" "} @@ -67,33 +96,31 @@ export function BdstReg() {
+
{nodeList}
-
- +
-
);