중수도 지도점검 업데이트 해야함

This commit is contained in:
leedj312
2025-05-14 14:39:42 +09:00
parent f224369d52
commit 9e4cfa6324
6 changed files with 280 additions and 220 deletions
@@ -15,7 +15,10 @@ import { useEffect, useState } from "react";
import { useForm, useWatch, type UseFormReturn } from "react-hook-form";
import { z } from "zod";
import BdstReg from "../bdstReg/bdstReg";
import { formatCommaNumber, handleCommaNumberChange } from "@/components/lib/func/commom";
import {
formatCommaNumber,
handleCommaNumberChange,
} from "@/components/lib/func/commom";
export default function RainRegForm({
rainForm,
@@ -24,7 +27,9 @@ export default function RainRegForm({
rainForm: customRainBdst;
isModal: boolean;
}) {
const { code, rainBdstReg, rainBdstUpdate, rain } = useWrStore((state) => state);
const { code, rainBdstReg, rainBdstUpdate, rain } = useWrStore(
(state) => state
);
const { rainFcltCd } = code;
const defaultValues: z.infer<typeof rainZod> = rainZod.parse({});
@@ -39,43 +44,47 @@ export default function RainRegForm({
"reuseBuilding.0.rainyObj.filtrTrtmfctYn",
]);
const cleanRainData =(raw: any): z.infer<typeof rainZod> =>{
return {
...raw,
frstArchPrmsnDt: new Date(raw?.frstArchPrmsnDt||null),
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"
const cleanRainData = (raw: any): z.infer<typeof rainZod> => {
return {
...raw,
frstArchPrmsnDt: new Date(raw?.frstArchPrmsnDt || null),
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 → ""
rainObj: {
...item?.rainObj
}
}))
};
rainObj: {
...item?.rainObj,
},
})),
};
};
useEffect(() => {
if (grntchBdstCertYn === "N") {
form.setValue("reuseBuilding.0.grntchBdstCertYr", "");
form.setValue("reuseBuilding.0.grntchBdstCertNo", "");
form.setValue("reuseBuilding.0.grntchBdstCertGrd", "");
} else if (instlCstSprtYn === "N") {
form.setValue("reuseBuilding.0.instlCstSprtAmt", 0);
} else if (filtrTrtmfctYn === "N") {
form.setValue("reuseBuilding.0.rainyObj.filtrTrtmfctCpct", 0);
form.setValue("reuseBuilding.0.rainyObj.filtrTrtmfctPrs", "");
}
useEffect(() =>{
if(grntchBdstCertYn ==='N'){
form.setValue('reuseBuilding.0.grntchBdstCertYr' ,"" )
form.setValue('reuseBuilding.0.grntchBdstCertNo' ,"" )
form.setValue('reuseBuilding.0.grntchBdstCertGrd' ,"" )
}else if(instlCstSprtYn ==='N'){
form.setValue('reuseBuilding.0.instlCstSprtAmt' ,0 )
}else if(filtrTrtmfctYn ==='N'){
form.setValue('reuseBuilding.0.rainyObj.filtrTrtmfctCpct' ,0 )
form.setValue('reuseBuilding.0.rainyObj.filtrTrtmfctPrs' ,"" )
}
},[grntchBdstCertYn,instlCstSprtYn ,filtrTrtmfctYn])
}, [grntchBdstCertYn, instlCstSprtYn, filtrTrtmfctYn]);
// form 값이 변경될 때마다 로그 출력
useEffect(() => {
const subscription = form.watch((value) => {});
const subscription = form.watch((value) => {
});
return () => subscription.unsubscribe();
}, [form]);
@@ -83,26 +92,19 @@ useEffect(() =>{
console.log("form errors:", form.formState.errors);
}, [form.formState.errors]);
const onSubmit =(values: z.infer<typeof rainZod>)=> {
const onSubmit = (values: z.infer<typeof rainZod>) => {
if (isModal) {
rainBdstReg(values ,'41');
rainBdstReg(values, "41");
} else {
rainBdstUpdate(values, '41');
}
}
rainBdstUpdate(values, "41");
}
};
useEffect(() => {
if(rainZod)
form.reset( cleanRainData(rainForm))
if (rainZod) form.reset(cleanRainData(rainForm));
}, [rainForm]);
const inputClass = '!text-lg'
const inputClass = "!text-lg";
return (
<div className="">
@@ -137,7 +139,7 @@ useEffect(() =>{
name="reuseBuilding.0.instlCmptnDt"
render={({ field }) => (
<FormUi label="설치완료일">
<DatePicker
<DatePicker
mode="single"
field={{
value:
@@ -146,7 +148,7 @@ useEffect(() =>{
: new Date(), // Provide a default Date value
onChange: (date) => field.onChange(date),
}}
selectClass={'w-full'}
selectClass={"w-full"}
/>
</FormUi>
)}
@@ -160,11 +162,13 @@ useEffect(() =>{
render={({ field }) => (
<FormUi label="설치비">
<Input
className={selectClass}
placeholder="1,000,000"
type="text"
onChange={(e) => {handleCommaNumberChange(e, field.onChange) }}
value={formatCommaNumber(field.value)}
className={selectClass}
placeholder="1,000,000"
type="text"
onChange={(e) => {
handleCommaNumberChange(e, field.onChange);
}}
value={formatCommaNumber(field.value)}
/>
</FormUi>
)}
@@ -193,7 +197,6 @@ useEffect(() =>{
selectArray={rainFcltCd}
onSelectValue={field.onChange}
value={field.value ?? rainFcltCd[0]?.val}
/>
</FormUi>
)}
@@ -209,7 +212,9 @@ useEffect(() =>{
className={selectClass}
placeholder="1,000,000"
type="text"
onChange={(e) => {handleCommaNumberChange(e, field.onChange) }}
onChange={(e) => {
handleCommaNumberChange(e, field.onChange);
}}
value={formatCommaNumber(field.value)}
/>
</FormUi>
@@ -250,10 +255,11 @@ useEffect(() =>{
className={selectClass}
placeholder="1,000,000"
type="text"
onChange={(e) => {handleCommaNumberChange(e, field.onChange) }}
onChange={(e) => {
handleCommaNumberChange(e, field.onChange);
}}
value={formatCommaNumber(field.value)}
readOnly={filtrTrtmfctYn!=='Y'}
readOnly={filtrTrtmfctYn !== "Y"}
/>
</FormUi>
)}
@@ -268,10 +274,10 @@ useEffect(() =>{
<Input
className={selectClass}
placeholder="1,000,000"
type=""
value={field.value ?? ""}
type=""
value={field.value ?? ""}
onChange={field.onChange}
readOnly={filtrTrtmfctYn!=='Y'}
readOnly={filtrTrtmfctYn !== "Y"}
/>
</FormUi>
)}
@@ -300,7 +306,6 @@ useEffect(() =>{
selectArray={code.yn}
onSelectValue={field.onChange}
value={field.value ?? code.yn[0]?.val}
/>
</FormUi>
)}
@@ -316,9 +321,11 @@ useEffect(() =>{
className={selectClass}
placeholder="1,000,000"
type="text"
onChange={(e) => {handleCommaNumberChange(e, field.onChange) }}
onChange={(e) => {
handleCommaNumberChange(e, field.onChange);
}}
value={formatCommaNumber(field.value)}
readOnly={instlCstSprtYn !== 'Y'}
readOnly={instlCstSprtYn !== "Y"}
/>
</FormUi>
)}
@@ -354,10 +361,14 @@ useEffect(() =>{
name="reuseBuilding.0.grntchBdstCertYr"
render={({ field }) => (
<FormUi label="인증년도">
<Input className={selectClass} placeholder="2024" type="" value={field.value ?? ""}
onChange={field.onChange}
readOnly={grntchBdstCertYn!=='Y'}/>
<Input
className={selectClass}
placeholder="2024"
type=""
value={field.value ?? ""}
onChange={field.onChange}
readOnly={grntchBdstCertYn !== "Y"}
/>
</FormUi>
)}
/>
@@ -374,7 +385,7 @@ useEffect(() =>{
type=""
value={field.value ?? ""}
onChange={field.onChange}
readOnly={grntchBdstCertYn!=='Y'}
readOnly={grntchBdstCertYn !== "Y"}
/>
</FormUi>
)}
@@ -386,10 +397,14 @@ useEffect(() =>{
name="reuseBuilding.0.grntchBdstCertGrd"
render={({ field }) => (
<FormUi label="인증등급">
<Input className={selectClass} placeholder="A" type="" value={field.value ?? ""}
<Input
className={selectClass}
placeholder="A"
type=""
value={field.value ?? ""}
onChange={field.onChange}
readOnly={grntchBdstCertYn!=='Y'}
/>
readOnly={grntchBdstCertYn !== "Y"}
/>
</FormUi>
)}
/>
@@ -1,27 +1,33 @@
import { useWrStore } from "@/app/store";
import { ScrollArea, Title, UiTable } from "@common/business_components/ui";
import { ScrollArea, Title } from "@common/business_components/ui";
import { Button } from "@common/components/ui";
import { useEffect, useState } from "react";
import { headMakeprfmnc } from "@/app/ruseFcltMng/prfmncReg/chkgdnReg/TableHead";
import { GuideDetailsTable } from "@/components/ui/table/chkgdTable/guideDetailTable/guideDetailTable";
import type {
polutionType,
splRuseWaterType,
} from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList";
import type { splRuseWaterType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList";
import type { rswtrPolutionsZode } from "@/app/store/prfmncReg/chkgdnReg/rswrtChkgdn/headList";
import type { z } from "zod";
import React from "react";
export default function ChkgdModal({ type, obj }: { type: string; obj: any }) {
const { rainChkgdn, rainChkDetilUpdate, rainChkGuidUpdate } = useWrStore(
const { rainChkgdn, rainChkGuidUpdate ,rwstUpdatePolAndGuide } = useWrStore(
(state) => state
);
const [guidData, setGuidData] = useState<splRuseWaterType[]>();
const [polutionData, setPolutionData] = useState<Record<string, any[]>>({
"1": [],
"2": [],
"3": [],
"4": [],
"1": [] as z.infer<typeof rswtrPolutionsZode>[],
"2": [] as z.infer<typeof rswtrPolutionsZode>[],
"3": [] as z.infer<typeof rswtrPolutionsZode>[],
"4": [] as z.infer<typeof rswtrPolutionsZode>[],
});
const [upPolutionData, setUpPolutionData] = useState<Record<string, any[]>>({
"1": [] as z.infer<typeof rswtrPolutionsZode>[],
"2": [] as z.infer<typeof rswtrPolutionsZode>[],
"3": [] as z.infer<typeof rswtrPolutionsZode>[],
"4": [] as z.infer<typeof rswtrPolutionsZode>[],
});
const rswtnodeList = headMakeprfmnc(
rainChkgdn?.rswtDetailHeadList,
@@ -80,7 +86,7 @@ export default function ChkgdModal({ type, obj }: { type: string; obj: any }) {
"3": [],
"4": [],
};
obj.rswtrPollution.forEach((item: any) => {
obj.rswtrPollution.forEach((item: z.infer<typeof rswtrPolutionsZode>) => {
const nodeKey = String(item.node);
resultPolution[nodeKey]?.push(item);
});
@@ -106,6 +112,7 @@ export default function ChkgdModal({ type, obj }: { type: string; obj: any }) {
const average = {
utztnUsgCd: "평균",
edit: false,
grssClfgUswtr: total.grssClfgUswtr / onlyData.length,
combResdch: total.combResdch / onlyData.length,
trbt: total.trbt / onlyData.length,
@@ -128,7 +135,6 @@ export default function ChkgdModal({ type, obj }: { type: string; obj: any }) {
}
}, [obj]);
const cellClick = (val: number | undefined, headId: string) => {};
const setChGuidData = (data: splRuseWaterType[]) => {
if (data.length > 0) {
@@ -136,7 +142,7 @@ export default function ChkgdModal({ type, obj }: { type: string; obj: any }) {
}
};
const guidDataUpdate = () => {
const allDataUpdate = () => {
const realGuideDetail = obj.guideDetails;
if (updateData === undefined || updateData.length === 0) return;
@@ -167,18 +173,37 @@ export default function ChkgdModal({ type, obj }: { type: string; obj: any }) {
});
obj.guideDetails = realGuideDetail;
rainChk.map((item: any) => {
if (item.chkgdnPk === obj.chkgdnPk) {
item.guideDetails = realGuideDetail;
}
});
rainChkGuidUpdate(obj);
if(type ==='RNB'){
rainChkGuidUpdate(obj);
}else{
const polution = Object.values(upPolutionData).flat() ;
obj.rswtrPollution = polution;
console.log("obj ", obj)
rwstUpdatePolAndGuide([obj]);
}
};
useEffect(() => {
console.log("/polutionData ", polutionData);
}, [polutionData]);
const getPolutionData = (data: z.infer<typeof rswtrPolutionsZode>[]) => {
console.log("data " ,data)
const getNode = Number(data[0]?.node)
setUpPolutionData((prevPolutionData) => ({
...prevPolutionData,
[getNode]: data,
}));
};
useEffect(() =>{
console.log('upPolutionData ', upPolutionData)
},[upPolutionData])
return (
<>
@@ -197,23 +222,32 @@ export default function ChkgdModal({ type, obj }: { type: string; obj: any }) {
{"○" + "" + `(${"11"})`}
</h3>
<Button className="" onClick={guidDataUpdate}>
<Button className="" onClick={allDataUpdate}>
저장
</Button>
</div>
<ScrollArea className="h-[60vh]">
<div className="card-header">
<h3 className="text-2xl font-medium text-label">
{`연간보급수이용량`}
</h3>
</div>
<GuideDetailsTable
chgRes={guidData}
chgRes={guidData || []}
headList={ruseHeadList}
type={""}
setChGuidData={(data) => {
setChGuidData(data);
}}
/>
<div className="card-header">
<h3 className="text-2xl font-medium text-label">
{type === "RNB" ? `연간빗물 이용량` : "연간중수도 이용량"}
</h3>
</div>
<GuideDetailsTable
chgRes={guidData}
chgRes={guidData || []}
headList={splHeadList}
type={""}
setChGuidData={(data) => {
@@ -221,60 +255,29 @@ export default function ChkgdModal({ type, obj }: { type: string; obj: any }) {
}}
/>
{type !== "RNB" ? (
<div>
<div className="card-header">
<h3 className="text-2xl font-medium text-label">
{"연간이용수질 1분기"}
</h3>
</div>
<GuideDetailsTable
chgRes={polutionData[1]}
headList={rainChkgdn?.rswtDetailHeadList}
type={""}
setChGuidData={(data) => {
setChGuidData(data);
}}
/>
<div className="card-header">
<h3 className="text-2xl font-medium text-label">
{"연간이용수질 2분기"}
</h3>
</div>
<GuideDetailsTable
chgRes={polutionData[2]}
headList={rainChkgdn?.rswtDetailHeadList}
type={""}
setChGuidData={(data) => {
setChGuidData(data);
}}
/>
<div className="card-header">
<h3 className="text-2xl font-medium text-label">
{"연간이용수질 3분기"}
</h3>
</div>
<GuideDetailsTable
chgRes={polutionData[3]}
headList={rainChkgdn?.rswtDetailHeadList}
type={""}
setChGuidData={(data) => {
setChGuidData(data);
}}
/>
<div className="card-header">
<h3 className="text-2xl font-medium text-label">
{"연간이용수질 4분기"}
</h3>
</div>
<GuideDetailsTable
chgRes={polutionData[4]}
headList={rainChkgdn?.rswtDetailHeadList}
type={""}
setChGuidData={(data) => {
setChGuidData(data);
}}
/>
{type !== "RNB" && polutionData !== undefined ? (
<div key={"polutionData"}>
{Object.entries(polutionData).map(([key, value]) => {
const keyNum = Number(key);
return (
<React.Fragment key={`polutionData_fragment_${keyNum}`}>
<div className="card-header">
<h3 className="text-2xl font-medium text-label">
{`연간이용수질 ${keyNum}분기`}
</h3>
</div>
<GuideDetailsTable
chgRes={value}
headList={rainChkgdn?.rswtDetailHeadList}
type={""}
setChGuidData={(data) => {
getPolutionData(data);
}}
/>
</React.Fragment>
);
})}
</div>
) : (
<></>
@@ -3,7 +3,6 @@ import { headMakeprfmnc } from "@/app/ruseFcltMng/prfmncReg/chkgdnReg/TableHead"
import { useWrStore } from "@/app/store";
import type {
} from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn";
import type { splRuseWaterType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList";
import type { TableUpperProps } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
import {
Input,
@@ -13,7 +12,7 @@ import {
TableHeader,
TableRow,
} from "@common/components/ui";
import { use, useEffect, useState } from "react";
import { useEffect, useState } from "react";
export function GuideDetailsTable({
chgRes,
@@ -22,7 +21,7 @@ export function GuideDetailsTable({
setChGuidData,
}: {
chgRes: any[];
headList: TableUpperProps[];
headList: TableUpperProps[];
type: string;
setChGuidData: (chgRes: any[]) => void;
}) {
@@ -58,14 +57,25 @@ export function GuideDetailsTable({
{chgRes.map((data, dataIndex) => (
<TableRow key={dataIndex + "row"}>
{headList.map((head, headIndex) => (
<TableCell key={head.id + headIndex}>
<TableCell key={head.id + headIndex} className="w-36" >
{head.edit ===true && data.edit !==false?
<Input
className={`${head.id !== "utztnUsgCd" ? "text-right" : "text-center"} text-3xl`}
className={`${head.id !== "utztnUsgCd" ? "text-right" : "text-center"} !text-2xl h-10 w-full`}
onChange={(e) =>
(dataIndex, head.id as any, e.target.value)
handleChange(dataIndex, head.id, e.target.value)
}
value={data[head.id as keyof any] || ""}
/>
/> : (
<div
className={`
${head.id !== "utztnUsgCd" ? "text-right" : "text-center"}
!text-2xl w-full h-10
`}
>
{data[head.id as keyof any] || ""}
</div>
)
}
</TableCell>
))}
</TableRow>