diff --git a/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx b/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx index 225f37ba5..fc6463844 100644 --- a/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx +++ b/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx @@ -4,6 +4,7 @@ import type { RainyBuilding, TableUpperProps, } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; +import { tableData } from "@/components/lib/func/commom"; import { RainRegForm } from "@/components/ui/form/fcltReg/rainReg/component"; import { BdstReg } from "@/components/ui/modal/bdstReg/component"; import { @@ -71,22 +72,8 @@ export default function Home() { useEffect(() => { if (code.sggCd.length > 0) { - const table = rainRes.map((item) => { - const sggText = code.sggCd.find( - (cd) => cd.val === Number(item.sggCd) - )?.text; - const cityText = code.cityCd.find( - (cd) => cd.val === Number(item.ctpvCd) - )?.text; - const bdstusgText = code.bdstUsgCd.find( - (cd) =>cd.val === item?.reuseBuilding[0]?.bdstUsgCd - ) - - - return { ...item, sggText: sggText, cityText: cityText ,bdsgUsgText:bdstusgText }; - }); - - setbdstTable(table); + + setbdstTable( tableData(rainRes, { code })); } }, [code, rainRes]); const cellClick: (val: number | undefined) => void = (val) => { diff --git a/apps/wr/app/ruseFcltMng/fcltReg/rswtReg/page.tsx b/apps/wr/app/ruseFcltMng/fcltReg/rswtReg/page.tsx index ecb7dff20..05336a773 100644 --- a/apps/wr/app/ruseFcltMng/fcltReg/rswtReg/page.tsx +++ b/apps/wr/app/ruseFcltMng/fcltReg/rswtReg/page.tsx @@ -19,11 +19,14 @@ import { Button} from "@common/components"; import { headMakeColSpan } from "../rainReg/page"; import { useEffect, useState } from "react"; import type { RswtBuilding } from "@/app/store/ruseFcltMng/fcltReg/rswtReg"; +import { tableData } from "@/components/lib/func/commom"; export default function Home() { const { code,rswt,initRswt } = useWrStore((state) => state); const nodeList = headMakeColSpan(rswt.upHeadList); + const [rswtForm, setRswtForm] = useState(); + const [bdstTable, setbdstTable] = useState(); const {rswtRes} = rswt; @@ -37,20 +40,18 @@ export default function Home() { }, [rswt.isInit, initRswt]); useEffect(() => { if (code.sggCd.length > 0) { - console.log(rswtRes) - const table = rswtRes?.map((item) => { - const sggText = code.sggCd.find( - (cd) => cd.val === Number(item.sggCd) - )?.text; - const cityText = code.cityCd.find( - (cd) => cd.val === Number(item.ctpvCd) - )?.text; - return { ...item, sggText: sggText, cityText: cityText }; - }); - - setbdstTable(table); + + setbdstTable( tableData(rswtRes, { code })); } }, [code, rswtRes]); + const cellClick: (val: number | undefined) => void = (val) => { + if ((bdstTable ?? []).length > 0 && val !== undefined) { + { + setRswtForm(rswtRes[val]); + } + } + }; + return ( <> @@ -71,7 +72,6 @@ export default function Home() { - {nodeList} @@ -101,7 +101,11 @@ export default function Home() {
- +
diff --git a/apps/wr/app/store/common/code/index.ts b/apps/wr/app/store/common/code/index.ts index 7125f5b71..c324e34c5 100644 --- a/apps/wr/app/store/common/code/index.ts +++ b/apps/wr/app/store/common/code/index.ts @@ -43,41 +43,39 @@ export const rainFcltCd = [ { val: "9", text: "기타" }, { val: "10", text: "확인불가" }, ]; - -//중수도 필수 원수종류 -export const rswtBdstType :selectArray[]= [ - { text: "숙박업", val: "17" }, - { text: "목욕장업", val: "18" }, - { text: "공장", val: "19" }, - { text: "발전시설", val: "20" }, - { text: "관광단지개발사업", val: "21" }, - { text: "도시개발사업", val: "22" }, - { text: "산업단지개발사업", val: "23" }, - { text: "택지개발사업", val: "24" }, - { text: "대규모점포(대형마트)", val: "25" }, - { text: "대규모점포(전문점)", val: "26" }, - { text: "대규모점포(백화점)", val: "27" }, - { text: "대규모점포(쇼핑센터)", val: "28" }, - { text: "대규모점포(복합쇼핑몰)", val: "29" }, - { text: "물류시설", val: "30" }, - { text: "운수시설(여객자동차터미널)", val: "31" }, - { text: "운수시설(철도시설)", val: "32" }, - { text: "운수시설(공항시설)", val: "33" }, - { text: "운수시설(항만시설)", val: "34" }, - { text: "업무시설(공공업무시설)", val: "35" }, - { text: "업무시설(금융업소)", val: "36" }, - { text: "업무시설(사무소)", val: "37" }, - { text: "업무시설(결혼상담소 등 소개업소)", val: "38" }, - { text: "업무시설(출판사)", val: "39" }, - { text: "업무시설(신문사)", val: "40" }, - { text: "업무시설(오피스텔)", val: "41" }, - { text: "교정시설", val: "42" }, - { text: "방송국", val: "43" }, - { text: "전신전화국", val: "44" }, - { text: "기타", val: "45" }, +// 중수도 필수 원수종류 +export const rswtBdstType: selectArray[] = [ + { text: "숙박업", val: 17 }, + { text: "목욕장업", val: 18 }, + { text: "공장", val: 19 }, + { text: "발전시설", val: 20 }, + { text: "관광단지개발사업", val: 21 }, + { text: "도시개발사업", val: 22 }, + { text: "산업단지개발사업", val: 23 }, + { text: "택지개발사업", val: 24 }, + { text: "대규모점포(대형마트)", val: 25 }, + { text: "대규모점포(전문점)", val: 26 }, + { text: "대규모점포(백화점)", val: 27 }, + { text: "대규모점포(쇼핑센터)", val: 28 }, + { text: "대규모점포(복합쇼핑몰)", val: 29 }, + { text: "물류시설", val: 30 }, + { text: "운수시설(여객자동차터미널)", val: 31 }, + { text: "운수시설(철도시설)", val: 32 }, + { text: "운수시설(공항시설)", val: 33 }, + { text: "운수시설(항만시설)", val: 34 }, + { text: "업무시설(공공업무시설)", val: 35 }, + { text: "업무시설(금융업소)", val: 36 }, + { text: "업무시설(사무소)", val: 37 }, + { text: "업무시설(결혼상담소 등 소개업소)", val: 38 }, + { text: "업무시설(출판사)", val: 39 }, + { text: "업무시설(신문사)", val: 40 }, + { text: "업무시설(오피스텔)", val: 41 }, + { text: "교정시설", val: 42 }, + { text: "방송국", val: 43 }, + { text: "전신전화국", val: 44 }, + { text: "기타", val: 45 }, ]; - const orgwtKndCd = [ { text: "오수(변기 오수 제외)", val: "1" }, { text: "오수", val: "2" }, diff --git a/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx b/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx index f15a170df..568eb6a2e 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx @@ -146,7 +146,7 @@ export const upHeadList: TableUpperProps[] = [ { id: "sggText", title: "시군구" }, { id: "bdstNm", title: "시설명" }, { id: "daddr", title: "위치" }, - { id: "bdstUsgText", title: "건축물용도" }, + { id: "bdsgUsgText", title: "건축물용도" }, // { id: "bdstUsgCd", title: "건축물용도" }, { id: "frstArchPrmsnDt", title: "최초건축허가일" }, { id: "archArea", title: "건축면적" }, diff --git a/apps/wr/app/store/ruseFcltMng/fcltReg/rswtReg/index.tsx b/apps/wr/app/store/ruseFcltMng/fcltReg/rswtReg/index.tsx index 000218b96..3aec87699 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltReg/rswtReg/index.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltReg/rswtReg/index.tsx @@ -1,5 +1,65 @@ import { getFectch } from "@/components/lib/api"; import { upHeadList, type chgBuilding, type TableUpperProps } from "../rainReg"; +import { rswtBdstType } from "@/app/store/common/code"; + +import { z } from "zod"; + +export const rswtZod = z.object({ + bdstInfoPk: z.number().default(0), + ctpvCd: z.number().default(0), + sggCd: z.number().default(0), + daddr: z.string().default(""), + bdstNm: z.string().default(""), + frstArchPrmsnDt: z.coerce.date().default(() => new Date()), + archChgPrmsnDt: z.coerce.date().nullish().default(null), + + archArea: z.number().default(0), + archChgArea: z.number().default(0), + + reuseBuilding: z.array( + z.object({ + bdstRuseFcltPk: z.number().default(0), + bdstInfoFk: z.number().default(0), + instlCmptnDt: z.coerce.date().default(() => new Date()), + instlCst: z.number().default(0), + operMngCd: z.string().nullish().default(""), + + anlOperCst: z.number().default(0), + instlCstSprtYn: z.string().default(""), + instlCstSprtAmt: z.number().default(0), + + grntchBdstCertYn: z.string().default(""), + grntchBdstCertYr: z.string() + .regex(/^\d{4}$/, "4자리 연도를 입력하세요") + .default(""), + grntchBdstCertNo: z.string().default(""), + grntchBdstCertGrd: z.string().default(""), + + crgRdctYn: z.string().default(""), + crgRdctBss: z.string().default(""), + crgRdctAmt: z.number().default(0), + ruseFcltFlg: z.string().default(""), + bdstUsgCd: z.number().default(0), + lawTrgtYn: z.string().default(""), + + rswtrObj: z.object({ + bdstRuseFcltFk: z.number().default(0), + wtrUsqty: z.number().default(0), + oblgTrgtWtrUsqty: z.number().default(0), + orgwtKndCd: z.string().default(""), + filtrTrtmfctProcs: z.string().default(""), + filtrTrtmfctUsgCd: z.string().default(""), + rswtrUsqty: z.number().default(0), + altUswtrUtztnYn: z.string().default(""), + altUswtrKndCd: z.string().default(""), + altUswtrUtztnQnt: z.number().default(0), + altUswtrIdntyMthdCd: z.string().default("") + }).default({}) + }) + ).default([]) +}); + + export type RswtBuilding = { bdstInfoPk: number; @@ -45,6 +105,8 @@ export type rswtrObj = { altUswtrIdntyMthdCd: string; }; + +rswtBdstType const rswtRes: RswtBuilding[] = []; export type rswtFacState = { @@ -71,7 +133,7 @@ export const rswtFacStateExport: rswtFacState = { const initFetch = async (txt: string | undefined) => { return await getFectch( "wr", - `/reuseFc/waterreuseFc/1/20/01` + (txt ? `/${txt}` : "") + `/reuseFc/waterreuseFc/1/20/41` + (txt ? `/${txt}` : "") ); }; export const rswtFacActionsExport: (set: any) => rswtFacSActions = ( diff --git a/apps/wr/components/lib/func/commom.ts b/apps/wr/components/lib/func/commom.ts index 0351f2fc9..d9b2bbdb5 100644 --- a/apps/wr/components/lib/func/commom.ts +++ b/apps/wr/components/lib/func/commom.ts @@ -1,4 +1,5 @@ -import type { selectArray } from "@/app/store/common/code"; +import type { comCodeState, selectArray } from "@/app/store/common/code"; +import type { RainyBuilding } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; @@ -14,3 +15,26 @@ export const getCity = (val: string, sggCd: selectArray[]) => { return data }; + + +// cd text 넣기 + export const tableData = ( data: any,code:comCodeState)=>{ + const chCode = code.code; + + return data?.map((item: { sggCd: string; ctpvCd: string; reuseBuilding: { lawTrgtYn: any , bdstUsgCd:any}[]; }) => { + const sggText = chCode.sggCd.find( + (cd) => cd.val === Number(item.sggCd) + )?.text; + const cityText = chCode.cityCd.find( + (cd) => cd.val === Number(item.ctpvCd) + )?.text; + const bdsgUsgText = chCode.bdstUsgCd.find( + (cd) =>cd.val === item?.reuseBuilding[0]?.bdstUsgCd + )?.text + const lawTrgtYn = item?.reuseBuilding[0]?.lawTrgtYn + return { ...item, sggText: sggText, cityText: cityText ,bdsgUsgText:bdsgUsgText ,lawTrgtYn:lawTrgtYn}; + + }); + } + + \ No newline at end of file diff --git a/apps/wr/components/ui/form/fcltReg/rswtrReg/component.tsx b/apps/wr/components/ui/form/fcltReg/rswtrReg/component.tsx index f563b3c53..13871806a 100644 --- a/apps/wr/components/ui/form/fcltReg/rswtrReg/component.tsx +++ b/apps/wr/components/ui/form/fcltReg/rswtrReg/component.tsx @@ -1,72 +1,75 @@ "use client"; import { + DatePicker, Form, FormField, FormUi, SelectBox, } from "@common/business_components/ui"; -import { Input } from "@common/components/ui"; +import { Button, Input } from "@common/components/ui"; import { zodResolver } from "@hookform/resolvers/zod"; -import { useForm } from "react-hook-form"; +import { useFieldArray, useForm } from "react-hook-form"; import { z } from "zod"; import { useWrStore } from "@/app/store"; import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; +import { + rswtZod, + type RswtBuilding, +} from "@/app/store/ruseFcltMng/fcltReg/rswtReg"; +import { useEffect } from "react"; -const formSchema = z.object({ - facilityName: z.string().min(2).max(50), - instlCmptnDt: z.string(), - instlCst: z.string(), - wtrUsqty: z.string(), - oblgTrgtwtrUsqty: z.string(), - rswtrKndCd: z.string(), - rswrtProcs: z.string(), - utztmUsgCd: z.string(), - instlCstSprtYn: z.string(), - instlCstSprtAmt: z.string(), - grntchCstSprtYn: z.string(), - grntchCstSprtCst: z.string(), - grntchBdstCertYn: z.string(), - grntchBdstCertYr: z.string(), - grntchBdstCertNo: z.string(), - grntchBdstCertGrd: z.string(), -}); +export function RswtrRegForm({ + rswtForm, + isModal, +}: { + rswtForm: RswtBuilding; + isModal: boolean; +}) { + const { rswt, code } = useWrStore((state) => state); -export function RswtrRegForm() { - const { rswt,code } = useWrStore((state) => state); - - const form = useForm>({ - resolver: zodResolver(formSchema), - defaultValues: { - facilityName: "", - instlCmptnDt: "", - instlCst: "", - wtrUsqty: "", - oblgTrgtwtrUsqty: "", - rswtrKndCd: "", - rswrtProcs: "", - utztmUsgCd: "", - instlCstSprtYn: "", - instlCstSprtAmt: "", - grntchCstSprtYn: "", - grntchCstSprtCst: "", - grntchBdstCertYn: "", - grntchBdstCertYr: "", - grntchBdstCertNo: "", - grntchBdstCertGrd: "", - }, + const form = useForm>({ + resolver: zodResolver(rswtZod), }); // 2. Define a submit handler. - function onSubmit(values: z.infer) { + function onSubmit(values: z.infer) { // Do something with the form values. // ✅ This will be type-safe and validated. console.log(values); } - const onSelectValue = (val: string) => { + const onSelectValue = (val: string | number) => { console.log(val); }; + + + function cleanRswtData(raw: any): z.infer { + return { + ...raw, + frstArchPrmsnDt: new Date(raw?.frstArchPrmsnDt), + archChgPrmsnDt: raw?.archChgPrmsnDt ? new Date(raw?.archChgPrmsnDt) : null, + reuseBuilding: (raw?.reuseBuilding || []).map((item: any) => ({ + ...item, + instlCmptnDt: new Date(item?.instlCmptnDt), + operMngCd: item?.operMngCd ?? "", // null → "" + grntchBdstCertYr: typeof item?.grntchBdstCertYr === "string" + ? item?.grntchBdstCertYr + : "", // null → "" + rswtrObj: { + ...item?.rswtrObj + } + })) + }; + } + + +useEffect(() => { + if(rswtZod) + form.reset( cleanRswtData(rswtForm)) + }, [rswtForm]); + + return (
@@ -75,6 +78,9 @@ export function RswtrRegForm() {

○ 중수도 시설 운영정보

+

@@ -84,14 +90,19 @@ export function RswtrRegForm() {
( - field.onChange(date), + }} + selectClass={selectClass} /> )} @@ -101,14 +112,15 @@ export function RswtrRegForm() {
( )} @@ -119,14 +131,15 @@ export function RswtrRegForm() {
( )} @@ -136,14 +149,15 @@ export function RswtrRegForm() {
( )} @@ -160,14 +174,16 @@ export function RswtrRegForm() {
( - + )} @@ -176,20 +192,20 @@ export function RswtrRegForm() {
( )} />
-
@@ -204,15 +220,17 @@ export function RswtrRegForm() {
( )} @@ -221,14 +239,15 @@ export function RswtrRegForm() {
( )} @@ -243,15 +262,17 @@ export function RswtrRegForm() {
( )} @@ -260,10 +281,17 @@ export function RswtrRegForm() {
( - + )} /> @@ -271,14 +299,15 @@ export function RswtrRegForm() {
( )} @@ -287,10 +316,10 @@ export function RswtrRegForm() {
( - + )} />