하수재이용 등록 수정
This commit is contained in:
@@ -77,10 +77,9 @@ export default function CoSttn() {
|
||||
useEffect(() => {
|
||||
if (!coSttn.isInit) {
|
||||
|
||||
console.log('coSttn.isInit ', coSttn.isInit)
|
||||
coSttnInit("1", "13", "0");
|
||||
}
|
||||
}, [coSttn.isInit, coSttnInit, objSearch]);
|
||||
}, [coSttn.isInit, coSttnInit]);
|
||||
|
||||
useEffect(() => {
|
||||
if (coSttnRes?.length > 0 && code.cityCd.length > 0) {
|
||||
|
||||
@@ -12,20 +12,28 @@ import {
|
||||
import { Button } from "@common/components";
|
||||
import { useWrStore } from "../../../store";
|
||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@common/components";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import ListDiv from "@common/business_components/ui/list_div";
|
||||
import { tableData } from "@/components/lib/func/commom";
|
||||
import type {
|
||||
customPbnst,
|
||||
fcBizType,
|
||||
PbnstRegArrrayType,
|
||||
pubHasuType,
|
||||
} from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import {
|
||||
pbnstRegZod,
|
||||
pbnstRegArrayZod,
|
||||
fcBizSchema,
|
||||
} from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import { PbnstMngForm } from "@/components/ui/form/fcltReg/pbnstReg/mngReg/mngRegForm";
|
||||
import { PbnstBuseForm } from "@/components/ui/form/fcltReg/pbnstReg/buseReg/bugRegForm";
|
||||
import { PbnstRegModal } from "@/components/ui/modal/fcltReg/pbnstRegModal/pbnstRegModal";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
import { ToastFormUi } from "@/components/ui/toast/toastFromUi";
|
||||
import toast, { Toaster } from "react-hot-toast";
|
||||
import { writeRgtrAndMdfr } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg";
|
||||
import { useFieldArray, useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
|
||||
export default function PublicReuseFaciltyInsert() {
|
||||
const {
|
||||
@@ -34,9 +42,9 @@ export default function PublicReuseFaciltyInsert() {
|
||||
searchFclts,
|
||||
pubHasuInit,
|
||||
pbnstRegClick,
|
||||
getSwtrmtFcltNm,
|
||||
pbnstMngData,
|
||||
pbnstRuseFcltUpdate,
|
||||
pubHasuSearch,
|
||||
pbnstRuseBizUpdate,
|
||||
} = useWrStore((state) => state);
|
||||
const { pubFacHeadList, pbnstHasuRes, pbnstRes } = pbnst;
|
||||
@@ -47,53 +55,69 @@ export default function PublicReuseFaciltyInsert() {
|
||||
data: pubHasuType;
|
||||
}>({ isModal: false, data: {} as pubHasuType });
|
||||
|
||||
const [indexMng, setIndexMng] = useState<number>(0);
|
||||
const [indexBiz, setIndexBiz] = useState<number>(0);
|
||||
const [searchTxt, setSearchTxt] = useState<string>();
|
||||
const [bdstTable, setbdstTable] = useState<pubHasuType[]>();
|
||||
const [selectRow, setSelectRow] = useState<pubHasuType>();
|
||||
|
||||
// const form = useForm<z.infer<typeof pbnstRegArrayZod>>({
|
||||
// resolver: zodResolver(pbnstRegArrayZod),
|
||||
// defaultValues: pbnstRegArrayZod.parse([]),
|
||||
// mode: "onChange",
|
||||
// });
|
||||
|
||||
const form = useForm<{
|
||||
items: z.infer<typeof pbnstRegZod>[];
|
||||
}>({
|
||||
resolver: zodResolver(z.object({ items: pbnstRegArrayZod })),
|
||||
defaultValues: { items: pbnstRegArrayZod.parse([]) },
|
||||
mode:"onChange"
|
||||
});
|
||||
const {
|
||||
fields: items,
|
||||
append,
|
||||
remove,
|
||||
} = useFieldArray({
|
||||
control: form.control,
|
||||
name: `items`,
|
||||
});
|
||||
useEffect(() => {
|
||||
if (!pbnst.isInit) {
|
||||
pubHasuInit("1", "11");
|
||||
}
|
||||
}, [pbnst.isInit, pubHasuInit]);
|
||||
|
||||
const onSubmit = async (valuse: { items: PbnstRegArrrayType }) => {
|
||||
|
||||
const data = writeRgtrAndMdfr(valuse.items);
|
||||
let bizs = [] as fcBizType[];
|
||||
data.forEach((fclt) => {
|
||||
bizs = [...bizs, ...fclt.fcBizs];
|
||||
});
|
||||
|
||||
const saveRuseData = async ()=>{
|
||||
const data = writeRgtrAndMdfr(pbnst.pbnstMngRegData)
|
||||
let bizs =[] as fcBizType[]
|
||||
data.forEach((fclt) =>{
|
||||
bizs = [
|
||||
...bizs,
|
||||
...fclt.fcBizs
|
||||
]
|
||||
})
|
||||
await pbnstRuseFcltUpdate(data);
|
||||
|
||||
|
||||
await pbnstRuseFcltUpdate(data)
|
||||
|
||||
await pbnstRuseBizUpdate(bizs)
|
||||
|
||||
}
|
||||
|
||||
await pbnstRuseBizUpdate(bizs);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if(code.sggCd.length){
|
||||
if(searchFclts){
|
||||
if (code.sggCd.length) {
|
||||
if (searchFclts) {
|
||||
setbdstTable(tableData(searchFclts, { code }));
|
||||
}else if (code.sggCd.length > 0 && pbnstHasuRes.length > 0) {
|
||||
} else if (code.sggCd.length > 0 && pbnstHasuRes.length > 0) {
|
||||
setbdstTable(tableData(pbnstHasuRes, { code }));
|
||||
}
|
||||
}
|
||||
}, [code, pbnstHasuRes,searchFclts]);
|
||||
}, [code, pbnstHasuRes, searchFclts]);
|
||||
|
||||
const cellClick = (val: number | undefined) => {
|
||||
if (val === undefined) return;
|
||||
const selectRow = pbnstHasuRes?.[val];
|
||||
setSelectRow(pbnstHasuRes?.[val])
|
||||
if (selectRow) {
|
||||
setIsRuseReg({ ...isRuseReg, data: selectRow });
|
||||
//setIsRuseReg({ ...isRuseReg, data: selectRow });
|
||||
pbnstRegClick(selectRow);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -101,6 +125,51 @@ export default function PublicReuseFaciltyInsert() {
|
||||
setCurrentTab(value);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (pbnst.pbnstRes) {
|
||||
form.reset({ items: pbnstRegArrayZod.parse(pbnst.pbnstRes) });
|
||||
}
|
||||
}, [pbnst.pbnstRes]);
|
||||
useEffect(() => {
|
||||
if (indexMng) {
|
||||
setIndexBiz(0);
|
||||
}
|
||||
}, [indexMng]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("form errors:", form.formState.errors);
|
||||
}, [form.formState.errors]);
|
||||
|
||||
const appendPbnstRuseFclt = useCallback(() => {
|
||||
if (pbnstRes && pbnstRes.length > 0) {
|
||||
const lastPbnst = pbnstRes[pbnstRes.length - 1];
|
||||
console.log('lastPbnst.swtrmtFcltFk ', lastPbnst)
|
||||
if(lastPbnst){
|
||||
append(
|
||||
pbnstRegZod.parse({
|
||||
pbnstRuseFcltPk: String(lastPbnst.pbnstRuseFcltPk) + String(pbnstRes.length + 1),
|
||||
ruseUtztnFcltNm: "",
|
||||
fcBizs: [fcBizSchema.parse({pbnstRuseFcltFk:String(lastPbnst.pbnstRuseFcltPk) + String(pbnstRes.length + 1),cycl:1})] as fcBizType[],
|
||||
})
|
||||
);
|
||||
setIsRuseReg({ ...isRuseReg, isModal: true })
|
||||
}
|
||||
} else {
|
||||
if(selectRow){
|
||||
append(
|
||||
pbnstRegZod.parse({
|
||||
pbnstRuseFcltPk: String(selectRow.bscFctCd)+'1',
|
||||
ruseUtztnFcltNm: "",
|
||||
regDt: null,
|
||||
mdfcnDt: null,
|
||||
fcBizs: [fcBizSchema.parse({pbnstRuseFcltFk:String(selectRow.bscFctCd)+'1',cycl:1})] as fcBizType[],
|
||||
})
|
||||
);
|
||||
setIsRuseReg({ ...isRuseReg, isModal: true })
|
||||
}
|
||||
}
|
||||
},[pbnstRegZod,pbnstRes,append,selectRow])
|
||||
|
||||
return (
|
||||
<>
|
||||
<ContentsDiv>
|
||||
@@ -123,8 +192,8 @@ export default function PublicReuseFaciltyInsert() {
|
||||
size={"sm"}
|
||||
onClick={(e) => {
|
||||
searchTxt && searchTxt?.length > 0
|
||||
? getSwtrmtFcltNm(searchTxt)
|
||||
: pubHasuInit("1", "11")
|
||||
? pubHasuSearch("1", "11", searchTxt)
|
||||
: pubHasuInit("1", "11");
|
||||
}}
|
||||
>
|
||||
조회
|
||||
@@ -134,12 +203,13 @@ export default function PublicReuseFaciltyInsert() {
|
||||
className=""
|
||||
onClick={() => {
|
||||
pbnstMngData([] as customPbnst[]);
|
||||
isRuseReg.data.bscFctCd
|
||||
? setIsRuseReg({ ...isRuseReg, isModal: true })
|
||||
: ToastFormUi({
|
||||
body: "하수리시시설을 테이블을 선택하고 등록버튼을 눌러주세요",
|
||||
title: "재이용시설 등록",
|
||||
});
|
||||
if(!selectRow){
|
||||
toast.error("하수리시시설을 테이블을 선택하고 등록버튼을 눌러주세요")
|
||||
return
|
||||
}else{
|
||||
appendPbnstRuseFclt()
|
||||
|
||||
}
|
||||
}}
|
||||
>
|
||||
신규등록
|
||||
@@ -177,15 +247,34 @@ export default function PublicReuseFaciltyInsert() {
|
||||
<TabsTrigger className="!text-xl" value="buse">
|
||||
차수별정보
|
||||
</TabsTrigger>
|
||||
<Button size={"sm"} onClick={ saveRuseData}className="!justify-end">
|
||||
<Button
|
||||
size={"sm"}
|
||||
onClick={form.handleSubmit(onSubmit)}
|
||||
className="!justify-end"
|
||||
>
|
||||
저장
|
||||
</Button>
|
||||
</TabsList>
|
||||
<TabsContent className="max-h-full" value="mng">
|
||||
<PbnstMngForm formType="update" />
|
||||
<PbnstMngForm
|
||||
formType="update"
|
||||
form={form}
|
||||
setIndexMng={(index: number) => {
|
||||
setIndexMng(index);
|
||||
}}
|
||||
indexMng={indexMng}
|
||||
/>
|
||||
</TabsContent>
|
||||
<TabsContent className="max-h-full" value="buse">
|
||||
<PbnstBuseForm formType="update" />
|
||||
<PbnstBuseForm
|
||||
formType="update"
|
||||
form={form}
|
||||
setIndexBiz={(index: number) => {
|
||||
setIndexBiz(index);
|
||||
}}
|
||||
indexMng={indexMng}
|
||||
indexBiz={indexBiz}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</ScrollArea>
|
||||
@@ -193,12 +282,14 @@ export default function PublicReuseFaciltyInsert() {
|
||||
<UiModal
|
||||
body={
|
||||
<PbnstRegModal
|
||||
form={form}
|
||||
data={isRuseReg.data || ({} as customPbnst)}
|
||||
></PbnstRegModal>
|
||||
}
|
||||
bodyClass="w-[68vw] max-w-none h-[90vh]"
|
||||
open={isRuseReg.isModal}
|
||||
onOpenChange={(open) => {
|
||||
remove(form.getValues("items").length - 1)
|
||||
setIsRuseReg({ data: {} as pubHasuType, isModal: open });
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -134,6 +134,8 @@ export default function prfmncPrfmncReg() {
|
||||
}
|
||||
const tableData = [...inUsageData, ...outUsageData, usageTotalObj];
|
||||
setPbnstRuseFcltPk(prfmncRes[index].pbnstRuseFcltPk);
|
||||
|
||||
console.log(' tableData ' ,tableData)
|
||||
setInputData(tableData);
|
||||
} else {
|
||||
setInputData([]);
|
||||
|
||||
@@ -70,7 +70,7 @@ export default function PbnstPrfmncSttn() {
|
||||
const inSubtotal = subTotalObj;
|
||||
const outSubtotal = subTotalObj;
|
||||
|
||||
|
||||
console.log(' prfList ', prfList)
|
||||
const prfFilter = prfList?.filter((e) => e.ym.slice(0, 4) === year)
|
||||
if (prfList && prfFilter.length > 0) {
|
||||
prfList?.forEach((prfItem) => {
|
||||
@@ -191,7 +191,7 @@ export default function PbnstPrfmncSttn() {
|
||||
fill: element.fill
|
||||
};
|
||||
return config;
|
||||
}, {} as Record<string, { label: string; color: string; }>) satisfies ChartConfig;
|
||||
}, {} as Record<string, { label: string; fill?: string }>) satisfies ChartConfig;
|
||||
setChartConfig(newChartConfig);
|
||||
}, [chartData]);
|
||||
|
||||
@@ -209,6 +209,7 @@ export default function PbnstPrfmncSttn() {
|
||||
if (rawData) {
|
||||
rawData.forEach((item) => {
|
||||
item.prfList.filter((e) => e.ym.slice(0, 4) === year) .forEach((element) => {
|
||||
|
||||
wshwtr += element.wshwtr; //세척수
|
||||
coolUswtr += element.coolUswtr; //냉각수
|
||||
cleanUswtr += element.cleanUswtr; //청소수
|
||||
@@ -567,7 +568,7 @@ export default function PbnstPrfmncSttn() {
|
||||
<SearchInput
|
||||
className={"text-2xl"}
|
||||
label="시설명"
|
||||
textValue={swtrmtFcltNm}
|
||||
textValue={swtrmtFcltNm ?? ""}
|
||||
setText={(e) => {
|
||||
setSwtrmtFcltNm(e);
|
||||
}} />
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
putFectch,
|
||||
} from "@/components/lib/api";
|
||||
import type { pubHasuType } from "../../ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import type { DemandCompType } from "@common/business_components/ui";
|
||||
import type { DemandCompType } from "@common/business_components/ui/sdmInsertForm/form";
|
||||
export type comFcltState = {
|
||||
searchFclts: pubHasuType;
|
||||
demandCompList: DemandCompType[];
|
||||
@@ -24,9 +24,9 @@ export const searchActions: (set: any) => comFcltActions = (set: any) => {
|
||||
getSwtrmtFcltNm: async (searchNm: string) => {
|
||||
const fcltNm = await getFetch(
|
||||
"common",
|
||||
`/prcsFclt/info/1/20/${searchNm}`
|
||||
`/prcsFclt/info/1/11/${searchNm}`
|
||||
);
|
||||
const fcltNmCd: pubHasuType[] = fcltNm.map((item: any) => ({
|
||||
const searchFclts: pubHasuType[] = fcltNm.map((item: any) => ({
|
||||
bscFctCd: item.bscFctCd,
|
||||
sido: item.sido,
|
||||
gugun: item.gugun,
|
||||
@@ -36,7 +36,7 @@ export const searchActions: (set: any) => comFcltActions = (set: any) => {
|
||||
}));
|
||||
set((state: comFcltState) => ({
|
||||
...state,
|
||||
searchFclts: fcltNmCd,
|
||||
searchFclts: searchFclts,
|
||||
}));
|
||||
},
|
||||
getDemandCompList: async (searchNm: string, cnt: number) => {
|
||||
@@ -44,9 +44,10 @@ export const searchActions: (set: any) => comFcltActions = (set: any) => {
|
||||
fetchType.WR,
|
||||
`/reuseFc/request/${searchNm}/${cnt}`
|
||||
);
|
||||
|
||||
console.log(coList);
|
||||
set((state: comFcltState) => {
|
||||
state.demandCompList = coList;
|
||||
return state;
|
||||
return state.demandCompList = [...coList];
|
||||
});
|
||||
},
|
||||
regDemandCompany: async (data: DemandCompType) => {
|
||||
|
||||
@@ -19,14 +19,11 @@ export const pbnstMngUpHeadListExport: TableUpperProps[] = [
|
||||
{
|
||||
id: "bgngDt",
|
||||
title: "시작일",
|
||||
upSequnce: 1,
|
||||
type: "date",
|
||||
},
|
||||
{
|
||||
id: "endDt",
|
||||
title: "종료일",
|
||||
upName: "upChangeRe",
|
||||
upSequnce: 2,
|
||||
type: "date",
|
||||
},
|
||||
];
|
||||
@@ -72,6 +69,7 @@ export type formDetailType = {
|
||||
id: string;
|
||||
lable: string;
|
||||
type?: string;
|
||||
option?:string
|
||||
};
|
||||
|
||||
export const wasteWaterFcltINfo: formDetailType[] = [
|
||||
@@ -102,7 +100,7 @@ export const businessMoneyInfo: formDetailType[] = [
|
||||
{ id: "lcep", lable: "지방비", type: "number" },
|
||||
{ id: "cusrAlotm", lable: "민간투자비", type: "number" },
|
||||
{ id: "etc", lable: "기타" },
|
||||
{ id: "totalMoney", lable: "합계", type: "number" },
|
||||
{ id: "totalMoney", lable: "합계", type: "number" ,option:"readOnly" },
|
||||
];
|
||||
|
||||
export const businessSttnInfo: formDetailType[] = [
|
||||
|
||||
@@ -68,6 +68,7 @@ type pubFacActions = {
|
||||
getpbnstInsertIndex: (data: pbnstInsertIndex) => void;
|
||||
pbnstRuseFcltUpdate: (ruseRes: customPbnst[]) => void;
|
||||
pbnstRuseBizUpdate: (ruseRes: fcBizType[]) => void;
|
||||
pubHasuSearch :(page: string, sggOrCity: string , searchTxt:string) => void
|
||||
};
|
||||
export type pubFacType = pubFacState & pubFacActions;
|
||||
|
||||
@@ -78,14 +79,14 @@ export const pubFacStateExport: pubFacState = {
|
||||
pbnstMngUpHeadList: pbnstMngUpHeadList,
|
||||
pbnstMngNm: pbnstMngNm,
|
||||
pbnstOrgwtHeadList: pbnstOrgwtHeadList,
|
||||
pbnstHasuRes: [],
|
||||
pbnstResObj: null, // 초기값을 null로 변경
|
||||
pbnstRes: [], // 초기값을 null로 변경
|
||||
pbnstBizCycle: [{ text: "없음", val: "1" }],
|
||||
selectLabel: selectLabel,
|
||||
pplInstlsHeadLisat: pplInstlsHeadLisat,
|
||||
pbnstDemandHeadList: pbnstDemandHeadList,
|
||||
fcOrgwtsHeadList: fcOrgwtsHeadList,
|
||||
selectLabel: selectLabel,
|
||||
pbnstResObj: null, // 초기값을 null로 변경
|
||||
pbnstHasuRes: [],
|
||||
pbnstRes: [], // 초기값을 null로 변경
|
||||
pbnstBizCycle: [{ text: "없음", val: "1" }],
|
||||
pbnstMngRegData: [],
|
||||
pbnsUpdateIndex: {} as pbnstInsertIndex,
|
||||
dmdComList: [],
|
||||
@@ -97,11 +98,15 @@ const checkWrRegList = async () => {
|
||||
return wrRegList;
|
||||
};
|
||||
|
||||
const hasuListFetch = async (page: string, sggOrCity: string) => {
|
||||
const hasuListFetch = async (page: string, sggOrCity: string, searchTxt?:string) => {
|
||||
const checkWrRegListRes = await checkWrRegList();
|
||||
let url = `/prcsFclt/ruseInfo/${page ? page : 1}/10/A/${sggOrCity ? sggOrCity : "11"}/0/1/SW`;
|
||||
if(searchTxt){
|
||||
url= url +`/${searchTxt}`
|
||||
|
||||
}
|
||||
const rainRes = await postFectch(
|
||||
`/prcsFclt/ruseInfo/${page ? page : 1}/10/A/${sggOrCity ? sggOrCity : "11"}/0/1/SW`,
|
||||
url,
|
||||
checkWrRegListRes,
|
||||
fetchType.COMMON
|
||||
);
|
||||
@@ -143,12 +148,12 @@ export const writeRgtrAndMdfr = (data: customPbnst[]) => {
|
||||
});
|
||||
return item;
|
||||
});
|
||||
pbnst.fcOpers = pbnst.fcOpers.map((oper) => {
|
||||
pbnst.fcOpers = pbnst?.fcOpers?.map((oper) => {
|
||||
oper.rgtr = TEST_UUID;
|
||||
oper.mdfr = TEST_UUID;
|
||||
return oper;
|
||||
});
|
||||
pbnst.fcFiles = pbnst.fcFiles.map((file) => {
|
||||
pbnst.fcFiles = pbnst.fcFiles?.map((file) => {
|
||||
file.rgtr = TEST_UUID;
|
||||
file.mdfr = TEST_UUID;
|
||||
return file;
|
||||
@@ -176,8 +181,22 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => {
|
||||
} catch (errorHasu) {
|
||||
console.log(errorHasu);
|
||||
}
|
||||
},
|
||||
},pubHasuSearch : async(page: string, sggOrCity: string , searchTxt:string)=> {
|
||||
|
||||
try{
|
||||
const pbnstHasuRes = await hasuListFetch(page, sggOrCity,searchTxt);
|
||||
return set((state: pubFacState) => ({
|
||||
...state,
|
||||
pbnst: {
|
||||
...state.pbnst,
|
||||
pbnstHasuRes: pbnstHasuRes,
|
||||
isInit: false,
|
||||
},
|
||||
}));
|
||||
} catch (errorHasu) {
|
||||
console.log(errorHasu);
|
||||
}
|
||||
},
|
||||
pbnstRegClick: async (pubHasuRes: pubHasuType) => {
|
||||
try {
|
||||
const pbnstRes = await initFetch(pubHasuRes.bscFctCd);
|
||||
@@ -213,10 +232,9 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => {
|
||||
pbnstInsert: async (pbnstRes: customPbnst) => {
|
||||
try {
|
||||
|
||||
console.log( ' pbnstRes ' , pbnstRes)
|
||||
const response = await postFectch(
|
||||
`/reuseFc/pubFc`,
|
||||
JSON.stringify( writeRgtrAndMdfr([pbnstRes]))
|
||||
JSON.stringify( pbnstRes)
|
||||
);
|
||||
|
||||
return set((state: pubFacState) => ({
|
||||
|
||||
@@ -58,67 +58,8 @@ export type PbnstDemandComType = {
|
||||
splyCpct: number | 0;
|
||||
splyFmYn:string|'Y'
|
||||
dmdInfoFk:string|''
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export type fcBizType = z.infer<typeof fcBizSchema>;
|
||||
export type fcOrgwtType = z.infer<typeof fcOrgwtSchema>;
|
||||
export type ppInstlType = z.infer<typeof pplInstlSchema>;
|
||||
|
||||
export type operType = z.infer<typeof fcOperSchema>;
|
||||
export type fcFileType = z.infer<typeof fcFileSchema>;
|
||||
|
||||
|
||||
const pplInstlSchema = z.object({
|
||||
ruseFcltBizFk: z.number().nullish(),
|
||||
choose:z.boolean().default(false),
|
||||
pdmt: z.string().default(''),
|
||||
ppMqlt: z.string().default(""),
|
||||
cpct: z.number().default(0),
|
||||
});
|
||||
const fcFileSchema = z.object({
|
||||
ruseFcltFk: z.number().nullish(),
|
||||
fileTkn: z.string(),
|
||||
filePath: z.string(),
|
||||
fileKnd: z.string(),
|
||||
regDt: z.date().default(new Date()).nullish(),
|
||||
rgtr: z.string().nullish(),
|
||||
mdfcnDt: z.date().default(new Date()).nullish(),
|
||||
mdfr: z.string().nullish(),
|
||||
});
|
||||
|
||||
export const fcOperSchema = z.object({
|
||||
pbnstRuseFcltOperInfoPk: z.number().nullish(),
|
||||
pbnstRuseFcltFk: z.string().nullish(),
|
||||
operMthd: z.string(),
|
||||
rprtvBzenty: z.string(),
|
||||
bgngDt: z.date().default(new Date()),
|
||||
endDt: z.date().default(new Date()),
|
||||
regDt: z.date().nullish(),
|
||||
rgtr: z.string().default(""),
|
||||
mdfcnDt: z.date().nullish(),
|
||||
mdfr: z.string().default(""),
|
||||
choose: z.boolean().default(false),
|
||||
});
|
||||
|
||||
const fcOrgwtSchema = z.object({
|
||||
pbnstRuseFcltBizFk: z.string().nullish(),
|
||||
swtrmtFcltFk: z.number().default(0),
|
||||
orgwtWtritQnt: z.number(),
|
||||
tmsYn: z.enum(["Y", "N"] ).default("N"),
|
||||
dschgFmYn: z.enum(["Y", "N"] ).default("N"),
|
||||
dtlPstnExpln: z.string().default(''),
|
||||
regDt: z.date().nullish(),
|
||||
rgtr: z.string().default(''),
|
||||
mdfcnDt: z.date().nullish(),
|
||||
mdfr: z.string().default(''),
|
||||
choose: z.boolean().default(false),
|
||||
});
|
||||
|
||||
|
||||
|
||||
const pubHasuZod = z.object({
|
||||
choose: z.boolean().default(false),
|
||||
bscFctCd: z.string(),
|
||||
@@ -130,97 +71,141 @@ const pubHasuZod = z.object({
|
||||
addr:z.string().nullish()
|
||||
});
|
||||
|
||||
const demandInfoList = z.object({
|
||||
|
||||
})
|
||||
|
||||
|
||||
export type pubHasuType = z.infer<typeof pubHasuZod>;
|
||||
const zDate = z.preprocess((v) => (v ? new Date(v as string) : undefined), z.date()).nullish() ;
|
||||
const zDateNullish = zDate.nullish();
|
||||
const zDateDefaultNow = zDate.default(new Date());
|
||||
|
||||
const zNum = z.preprocess((v) => (v !== null && v !== undefined ? Number(v) : v), z.number());
|
||||
const zNumNullish = zNum.nullish();
|
||||
const zNumDefaultZero = zNum.default(0).nullish();
|
||||
|
||||
const pplInstlSchema = z.object({
|
||||
ruseFcltBizFk: zNumNullish,
|
||||
choose: z.boolean().default(false),
|
||||
pdmt: z.string().default(''),
|
||||
ppMqlt: z.string().default(""),
|
||||
cpct: zNumDefaultZero,
|
||||
});
|
||||
|
||||
const fcFileSchema = z.object({
|
||||
ruseFcltFk: z.string().nullish(),
|
||||
fileTkn: z.string(),
|
||||
filePath: z.string(),
|
||||
fileKnd: z.string(),
|
||||
regDt: zDateDefaultNow.nullish(),
|
||||
rgtr: z.string().nullish(),
|
||||
mdfcnDt: zDateDefaultNow.nullish(),
|
||||
mdfr: z.string().nullish(),
|
||||
});
|
||||
|
||||
export const fcOperSchema = z.object({
|
||||
pbnstRuseFcltOperInfoPk: zNumNullish,
|
||||
pbnstRuseFcltFk: z.string().nullish(),
|
||||
operMthd: z.string(),
|
||||
rprtvBzenty: z.string(),
|
||||
bgngDt: zDateDefaultNow,
|
||||
endDt: zDateDefaultNow,
|
||||
regDt: zDateNullish,
|
||||
rgtr: z.string().default(""),
|
||||
mdfcnDt: zDateNullish,
|
||||
mdfr: z.string().default(""),
|
||||
choose: z.boolean().default(false),
|
||||
});
|
||||
|
||||
const fcOrgwtSchema = z.object({
|
||||
pbnstRuseFcltBizFk:zNumNullish,
|
||||
swtrmtFcltFk: z.string().nullish(),
|
||||
orgwtWtritQnt: zNum,
|
||||
tmsYn: z.enum(["Y", "N"]).default("N"),
|
||||
dschgFmYn: z.enum(["Y", "N"]).default("N"),
|
||||
dtlPstnExpln: z.string().default(''),
|
||||
regDt: zDateNullish,
|
||||
rgtr: z.string().default(''),
|
||||
mdfcnDt: zDateNullish,
|
||||
mdfr: z.string().default(''),
|
||||
choose: z.boolean().default(false),
|
||||
});
|
||||
|
||||
const dmdColist = z.object({
|
||||
dmdInfoFk:z.string().default(''),
|
||||
dmdInfoFk: z.string().default(''),
|
||||
dmdCoNm: z.string().default(''),
|
||||
daddr: z.string(),
|
||||
useUsgCd: z.string().default(""),
|
||||
splyBgngDay: z.date().default(new Date()),
|
||||
splyEndDay: z.date().default(new Date()),
|
||||
splyCpct: z.number().default(0),
|
||||
splyBgngDay: zDateDefaultNow,
|
||||
splyEndDay: zDateDefaultNow,
|
||||
splyCpct: zNumDefaultZero,
|
||||
splyFmYn: z.string().default('Y'),
|
||||
rgtr: z.string().nullish(),
|
||||
mdfr: z.string().nullish(),
|
||||
pbnstRuseFcltBizPk: z.number(),
|
||||
pbnstRuseFcltBizPk: zNumDefaultZero,
|
||||
pbnstRuseFcltFk: z.string().nullish(),
|
||||
//telno:z.string().default('')
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
export const fcBizSchema = z.object({
|
||||
pbnstRuseFcltBizPk: z.number().nullish(),
|
||||
pbnstRuseFcltBizPk: zNumNullish,
|
||||
pbnstRuseFcltFk: z.string().nullish(),
|
||||
superkey: z.string().default("").nullish(),
|
||||
cycl: z.number().default(1),
|
||||
cycl: zNum.default(1),
|
||||
seCd: z.string().default(""),
|
||||
bizMthdCd: z.string().default(""),
|
||||
instlAprvSncnDt: z.date().default(new Date()),
|
||||
bizCmcnDay: z.date().default(new Date()),
|
||||
gvsbs: z.number().default(0),
|
||||
lcep: z.number().default(0),
|
||||
cusrAlotm: z.number().default(0),
|
||||
instlAprvSncnDt: zDateDefaultNow,
|
||||
bizCmcnDay: zDateDefaultNow,
|
||||
gvsbs: zNumDefaultZero,
|
||||
lcep: zNumDefaultZero,
|
||||
cusrAlotm: zNumDefaultZero,
|
||||
etc: z.string().default(''),
|
||||
totalMoney: z.number().default(0).nullish(),
|
||||
rprcsFcltCpct: z.number().default(0),
|
||||
totalMoney: zNumNullish.default(0),
|
||||
rprcsFcltCpct: zNumDefaultZero,
|
||||
majorPrcsMsrcCd: z.string().default(""),
|
||||
addr: z.string().default(''),
|
||||
rprcsMthdCd: z.string().default(""),
|
||||
inoutYn: z.enum(["Y", "N"]).default("Y"),
|
||||
mainSplyPumpCpct: z.number().nullish(),
|
||||
erctWtrOcrnCpct: z.number().nullish(),
|
||||
mainSplyPumpCpct: zNumNullish,
|
||||
erctWtrOcrnCpct: zNumNullish,
|
||||
erctUswtrLinkSpt: z.string().nullish(),
|
||||
erctUswtrFcltCpct: z.number().nullish(),
|
||||
erctUswtrFcltCpct: zNumNullish,
|
||||
erctUswtrPrcsMeth: z.string().nullish(),
|
||||
erctUswtrPrcsMsrcCd: z.string().nullish(),
|
||||
wwtEmsnFcltPrmsnYn: z.enum(["Y", "N"]).default("Y"),
|
||||
tmsInstlYn: z.enum(["Y", "N"]).default("Y"),
|
||||
pbnstDrngInflwExclYn: z.enum(["Y", "N"]).default("Y"),
|
||||
bod: z.number().default(0),
|
||||
grssClfg: z.number().default(0),
|
||||
combResdch: z.number().default(0),
|
||||
trbt: z.number().default(0),
|
||||
clIonQnt: z.number().default(0),
|
||||
smll: z.number().default(0),
|
||||
crmty: z.number().default(0),
|
||||
tph: z.number().default(0),
|
||||
tn: z.number().default(0),
|
||||
ph: z.number().default(0),
|
||||
cdtnv: z.number().default(0),
|
||||
designCst: z.number().nullish(),
|
||||
cstrnSpvsCst: z.number().nullish(),
|
||||
fcltSbsdCst: z.number().nullish(),
|
||||
wstCst: z.number().nullish(),
|
||||
cnstCmcnCst: z.number().nullish(),
|
||||
mntrgEqpmntInstlCst: z.number().nullish(),
|
||||
gisDbCst: z.number().nullish(),
|
||||
elpwrMtrngCst: z.number().nullish(),
|
||||
mchnCst: z.number().nullish(),
|
||||
archCst: z.number().nullish(),
|
||||
pplCst: z.number().nullish(),
|
||||
ruseFcltCst: z.number().nullish(),
|
||||
designCstClcln: z.number().nullish(),
|
||||
cstrnSpvsCstClcln: z.number().nullish(),
|
||||
fcltSbsdCstClcln: z.number().nullish(),
|
||||
wstCstClcln: z.number().nullish(),
|
||||
cnstCmcnCstClcln: z.number().nullish(),
|
||||
mntrgEqpmntInstlCstClcln: z.number().default(0),
|
||||
gisDbCstClcln: z.number().nullish(),
|
||||
elpwrMtrngCstClcln: z.number().nullish(),
|
||||
mchnCstClcln: z.number().nullish(),
|
||||
archCstClcln: z.number().nullish(),
|
||||
pplCstClcln: z.number().nullish(),
|
||||
ruseFcltCstClcln: z.number().nullish(),
|
||||
wwtEmsnFcltPrmsnYn: z.string().default("Y"),
|
||||
tmsInstlYn: z.string().default("Y"),
|
||||
pbnstDrngInflwExclYn: z.string().default("Y"),
|
||||
bod: zNumDefaultZero,
|
||||
grssClfg: zNumDefaultZero,
|
||||
combResdch: zNumDefaultZero,
|
||||
trbt: zNumDefaultZero,
|
||||
clIonQnt: zNumDefaultZero,
|
||||
smll: zNumDefaultZero,
|
||||
crmty: zNumDefaultZero,
|
||||
tph: zNumDefaultZero,
|
||||
tn: zNumDefaultZero,
|
||||
ph: zNumDefaultZero,
|
||||
cdtnv: zNumDefaultZero,
|
||||
designCst: zNumNullish,
|
||||
cstrnSpvsCst: zNumNullish,
|
||||
fcltSbsdCst: zNumNullish,
|
||||
wstCst: zNumNullish,
|
||||
cnstCmcnCst: zNumNullish,
|
||||
mntrgEqpmntInstlCst: zNumNullish,
|
||||
gisDbCst: zNumNullish,
|
||||
elpwrMtrngCst: zNumNullish,
|
||||
mchnCst: zNumNullish,
|
||||
archCst: zNumNullish,
|
||||
pplCst: zNumNullish,
|
||||
ruseFcltCst: zNumNullish,
|
||||
designCstClcln: zNumNullish,
|
||||
cstrnSpvsCstClcln: zNumNullish,
|
||||
fcltSbsdCstClcln: zNumNullish,
|
||||
wstCstClcln: zNumNullish,
|
||||
cnstCmcnCstClcln: zNumNullish,
|
||||
mntrgEqpmntInstlCstClcln: zNumDefaultZero,
|
||||
gisDbCstClcln: zNumNullish,
|
||||
elpwrMtrngCstClcln: zNumNullish,
|
||||
mchnCstClcln: zNumNullish,
|
||||
archCstClcln: zNumNullish,
|
||||
pplCstClcln: zNumNullish,
|
||||
ruseFcltCstClcln: zNumNullish,
|
||||
fcOrgwts: z.array(fcOrgwtSchema).nullish(),
|
||||
pplInstls: z.array(pplInstlSchema).nullish(),
|
||||
fcDemands: z.array(dmdColist).default([]).nullish(),
|
||||
@@ -230,18 +215,30 @@ export const fcBizSchema = z.object({
|
||||
mdfcnDt: z.string().nullish(),
|
||||
mdfr: z.string().nullish(),
|
||||
});
|
||||
|
||||
export const pbnstRegZod = z.object({
|
||||
pbnstRuseFcltPk: z.string().default(''),
|
||||
swtrmtFcltFk: z.string().default(""),
|
||||
ruseUtztnFcltNm: z.string().default(""),
|
||||
fcltCpct: z.number().default(0),
|
||||
ruseCpct: z.number().default(0),
|
||||
splyExtraCpct: z.number().default(0),
|
||||
regDt: z.date().default(new Date()),
|
||||
fcltCpct: zNumDefaultZero,
|
||||
ruseCpct: zNumDefaultZero,
|
||||
splyExtraCpct: zNumDefaultZero,
|
||||
regDt: zDateDefaultNow,
|
||||
rgtr: z.string().default("test"),
|
||||
mdfcnDt: z.date().default(new Date()),
|
||||
mdfcnDt: zDateDefaultNow,
|
||||
mdfr: z.string().default("test"),
|
||||
fcFiles: z.array(fcFileSchema).default([]),
|
||||
fcFiles: z.array(fcFileSchema).default([]).nullish(),
|
||||
fcBizs: z.array(fcBizSchema).default([]),
|
||||
fcOpers: z.array(fcOperSchema).default([]),
|
||||
fcOpers: z.array(fcOperSchema).default([]).nullish(),
|
||||
});
|
||||
|
||||
export const pbnstRegArrayZod = z.array(pbnstRegZod)
|
||||
|
||||
export type PbnstRegArrrayType = z.infer<typeof pbnstRegArrayZod>
|
||||
|
||||
export type fcBizType = z.infer<typeof fcBizSchema>;
|
||||
export type fcOrgwtType = z.infer<typeof fcOrgwtSchema>;
|
||||
export type ppInstlType = z.infer<typeof pplInstlSchema>;
|
||||
export type operType = z.infer<typeof fcOperSchema>;
|
||||
export type fcFileType = z.infer<typeof fcFileSchema>;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
fcBizSchema,
|
||||
type customPbnst,
|
||||
type fcBizType,
|
||||
type PbnstDemandComType,
|
||||
type PbnstRegArrrayType,
|
||||
type ppInstlType,
|
||||
} from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
|
||||
@@ -39,22 +39,29 @@ import {
|
||||
Input,
|
||||
Label,
|
||||
} from "@common/components";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useFieldArray, useForm } from "react-hook-form";
|
||||
import { useFieldArray, useForm, type UseFormReturn } from "react-hook-form";
|
||||
import MngRegFormDetail from "../mngReg/mngRegFormDetail/mngRegFormDetail";
|
||||
import { safeDate } from "@/components/lib/func/commom";
|
||||
import SearchInputText from "@/components/ui/searchInput/searchInput";
|
||||
import SdmInsertForm, {
|
||||
type DemandCompType,
|
||||
} from "@common/business_components/ui/sdmInsertForm";
|
||||
import SdmInsertForm from "@common/business_components/ui/sdmInsertForm";
|
||||
import type { DemandCompType } from "@common/business_components/ui/sdmInsertForm/form";
|
||||
import RuseMngTableForm from "@/components/ui/table/pbnstReg/ruseMngTableForm/ruseMngTableForm";
|
||||
|
||||
export function PbnstBuseForm({
|
||||
formType,
|
||||
firstBizData,
|
||||
indexMng = 0,
|
||||
indexBiz = 0,
|
||||
setIndexBiz,
|
||||
form,
|
||||
}: {
|
||||
formType: string;
|
||||
firstBizData?: fcBizType[];
|
||||
form: UseFormReturn<{ items: PbnstRegArrrayType }>;
|
||||
indexMng: number;
|
||||
indexBiz: number;
|
||||
setIndexBiz: (index: number) => void;
|
||||
}) {
|
||||
const ref = useRef<ppInstlType[] | null>(null);
|
||||
const {
|
||||
@@ -73,6 +80,13 @@ export function PbnstBuseForm({
|
||||
const [ppiSelectList, setPpiSelectList] =
|
||||
useState<[{ name: string; val: SelectDataType[] }]>();
|
||||
const [ppiYn, setPpiYn] = useState("Y");
|
||||
|
||||
const [selectBizCycle, setSelectBizCycle] = useState<
|
||||
{
|
||||
text: string;
|
||||
val: number;
|
||||
}[]
|
||||
>([{ text: "없음", val: 0 }]);
|
||||
const [isFcOrgwts, setIsFcOrgwts] = useState<boolean>(false);
|
||||
const [sumCpct, setSumCpct] = useState<number>(0);
|
||||
const [getDmdList, setGetFmdList] = useState<number>(0);
|
||||
@@ -81,56 +95,83 @@ export function PbnstBuseForm({
|
||||
data: DemandCompType;
|
||||
}>({ isMoal: false, data: {} as DemandCompType });
|
||||
|
||||
const form = useForm<fcBizType>({
|
||||
resolver: zodResolver(fcBizSchema),
|
||||
defaultValues:
|
||||
formType === "reg" &&
|
||||
pbnst.pbnstMngRegData &&
|
||||
pbnst.pbnstMngRegData[0]?.fcBizs
|
||||
? (pbnst.pbnstMngRegData[0].fcBizs[0] ?? {})
|
||||
: formType === "update" &&
|
||||
typeof pbnst.pbnsUpdateIndex.biz === "number" &&
|
||||
pbnst.pbnsUpdateIndex.biz >= 0 &&
|
||||
pbnst.pbnstRes
|
||||
? pbnst.pbnstRes[pbnst.pbnsUpdateIndex.mng]?.fcBizs[
|
||||
pbnst.pbnsUpdateIndex.biz
|
||||
]
|
||||
: fcBizSchema.parse({}),
|
||||
mode: "onChange",
|
||||
});
|
||||
|
||||
// 2. Define a submit handler.
|
||||
function onSubmit(values: fcBizType) {
|
||||
// console.log(values);
|
||||
}
|
||||
useEffect(() => {
|
||||
const total =
|
||||
(form.getValues(`items.${indexMng}.fcBizs.${indexBiz}.gvsbs`) ?? 0) +
|
||||
(form.getValues(`items.${indexMng}.fcBizs.${indexBiz}.lcep`) ?? 0) +
|
||||
(form.getValues(`items.${indexMng}.fcBizs.${indexBiz}.cusrAlotm`) ?? 0);
|
||||
|
||||
form.setValue(`items.${indexMng}.fcBizs.${indexBiz}.totalMoney`, total);
|
||||
}, [
|
||||
form.getValues(`items.${indexMng}.fcBizs.${indexBiz}.gvsbs`),
|
||||
form.getValues(`items.${indexMng}.fcBizs.${indexBiz}.lcep`),
|
||||
form.getValues(`items.${indexMng}.fcBizs.${indexBiz}.cusrAlotm`)
|
||||
]);
|
||||
|
||||
// const form = useForm<fcBizType>({
|
||||
// resolver: zodResolver(fcBizSchema),
|
||||
// defaultValues:
|
||||
// formType === "reg" &&
|
||||
// pbnst.pbnstMngRegData &&
|
||||
// pbnst.pbnstMngRegData[0]?.fcBizs
|
||||
// ? (pbnst.pbnstMngRegData[0].fcBizs[0] ?? {})
|
||||
// : formType === "update" &&
|
||||
// typeof pbnst.pbnsUpdateIndex.biz === "number" &&
|
||||
// pbnst.pbnsUpdateIndex.biz >= 0 &&
|
||||
// pbnst.pbnstRes
|
||||
// ? pbnst.pbnstRes[pbnst.pbnsUpdateIndex.mng]?.fcBizs[
|
||||
// pbnst.pbnsUpdateIndex.biz
|
||||
// ]
|
||||
// : fcBizSchema.parse({}),
|
||||
// mode: "onChange",
|
||||
// });
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (form) {
|
||||
const cycleLength = form.getValues(`items.${indexMng}.fcBizs`).length;
|
||||
setSelectBizCycle(
|
||||
Array.from({ length: cycleLength }, (_, index) => ({
|
||||
text: `${index + 1}차`, // ✅ index + 1
|
||||
val: index, // 이건 그대로 유지 (value로는 0부터 시작)
|
||||
}))
|
||||
);
|
||||
}
|
||||
}, [indexMng, form]);
|
||||
// 2. Define a submit handler.
|
||||
function addRuseFcltObj() {
|
||||
const newItem = fcBizSchema.parse({});
|
||||
const formRuse = form.getValues(`items.${indexMng}`);
|
||||
|
||||
const formBizs = form.getValues(`items.${indexMng}.fcBizs`);
|
||||
const pbnstBizCycle = formBizs.length;
|
||||
|
||||
// 🧩 새로운 fcBizs 기본 객체 생성 (필수값만 채우고 나머지는 default로)
|
||||
const newItem = fcBizSchema.parse({
|
||||
cycl: pbnstBizCycle + 1,
|
||||
pbnstRuseFcltFk: formRuse.pbnstRuseFcltPk,
|
||||
fcOrgwts: undefined,
|
||||
pplInstls: undefined,
|
||||
fcDemands: undefined,
|
||||
});
|
||||
const index = pbnst.pbnsUpdateIndex.mng;
|
||||
|
||||
let regData: fcBizType = {} as fcBizType;
|
||||
if (
|
||||
pbnst.pbnstRes &&
|
||||
pbnst.pbnstRes[pbnst.pbnsUpdateIndex.mng] &&
|
||||
pbnst.pbnstRes[pbnst.pbnsUpdateIndex.mng]?.fcBizs
|
||||
) {
|
||||
regData = {
|
||||
pbnstRuseFcltFk:
|
||||
String(pbnst.pbnstRes[0]?.swtrmtFcltFk) +
|
||||
String(pbnst.pbnstRes.length + 1),
|
||||
cycl: Number(
|
||||
(pbnst.pbnstRes[pbnst.pbnsUpdateIndex.mng]?.fcBizs?.length || 0) + 1
|
||||
),
|
||||
} as fcBizType;
|
||||
|
||||
const newPbnstRes = [...(pbnst.pbnstRes as customPbnst[])];
|
||||
newPbnstRes[index]?.fcBizs?.length &&
|
||||
newPbnstRes[index]?.fcBizs?.push(regData);
|
||||
getBizCycle(newPbnstRes[index] as customPbnst);
|
||||
appendRuseFclt(newPbnstRes);
|
||||
}
|
||||
appendBiz(newItem);
|
||||
const cycleLength = form.getValues(`items.${indexMng}.fcBizs`).length;
|
||||
setSelectBizCycle(
|
||||
Array.from({ length: cycleLength }, (_, index) => ({
|
||||
text: `${index + 1}차`, // ✅ index + 1
|
||||
val: index, // 이건 그대로 유지 (value로는 0부터 시작)
|
||||
}))
|
||||
);
|
||||
}
|
||||
useEffect(() => {
|
||||
console.log("form ", form.watch());
|
||||
}, [form.formState]);
|
||||
|
||||
const { fields: fcBizs, append: appendBiz } = useFieldArray({
|
||||
control: form.control,
|
||||
name: `items.${indexMng}.fcBizs`,
|
||||
});
|
||||
|
||||
const {
|
||||
fields: fcDemands,
|
||||
@@ -138,78 +179,54 @@ export function PbnstBuseForm({
|
||||
remove: removeDemand,
|
||||
} = useFieldArray({
|
||||
control: form.control,
|
||||
name: "fcDemands",
|
||||
name: `items.${indexMng}.fcBizs.${indexBiz}.fcDemands`,
|
||||
});
|
||||
|
||||
const { fields: fcOrgwtFiled } = useFieldArray({
|
||||
control: form.control,
|
||||
name: "fcOrgwts",
|
||||
name: `items.${indexMng}.fcBizs.${indexBiz}.fcOrgwts`,
|
||||
});
|
||||
|
||||
console.log(" fcOrgwtFiled ", fcOrgwtFiled);
|
||||
const {
|
||||
fields: pplInstls,
|
||||
append,
|
||||
remove,
|
||||
append: appendPpl,
|
||||
remove: removePpl,
|
||||
} = useFieldArray({
|
||||
control: form.control,
|
||||
name: "pplInstls",
|
||||
name: `items.${indexMng}.fcBizs.${indexBiz}.pplInstls`,
|
||||
});
|
||||
|
||||
// 등록할때 신규 값을 계속 가지고 있으려고
|
||||
useEffect(() => {
|
||||
const formData = form.watch();
|
||||
|
||||
//console.log(" formData.fcDemands. ", formData.fcDemands);
|
||||
formData.pplInstls = ref.current ? [...ref.current] : []; // ← form 내부 상태 기준으로 복사
|
||||
//formData.fcDemands = fcDemands;
|
||||
//formData.fcOrgwts = fcOrgwtFiled;
|
||||
console.log(" formData. ", formData);
|
||||
if (formType === "reg") {
|
||||
if (
|
||||
firstBizData &&
|
||||
firstBizData[0] &&
|
||||
(form.getValues("pbnstRuseFcltFk") === "" ||
|
||||
form.getValues("pbnstRuseFcltFk") === undefined)
|
||||
) {
|
||||
form.setValue(
|
||||
"pbnstRuseFcltFk",
|
||||
String(firstBizData[0].pbnstRuseFcltFk)
|
||||
);
|
||||
form.setValue("cycl", firstBizData[0].cycl);
|
||||
}
|
||||
pbnstBizData(formData as fcBizType);
|
||||
} else if (formType === "update") {
|
||||
pbnstBizData(formData as fcBizType);
|
||||
}
|
||||
}, [firstBizData, form.formState, formType, pbnst.pbnstRes]);
|
||||
|
||||
useEffect(() => {
|
||||
if (ppiYn === "N") {
|
||||
form.setValue("pplInstls", []);
|
||||
form.setValue(`items.${indexMng}.fcBizs.${indexBiz}.pplInstls`, []);
|
||||
}
|
||||
}, [ppiYn]);
|
||||
}, [ppiYn, indexMng, indexBiz]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("pbnst. bug pbnstMngRegData ", pbnst.pbnstMngRegData);
|
||||
}, [pbnst.pbnstMngRegData]);
|
||||
|
||||
const plusHist = () => {
|
||||
const regData = {
|
||||
ruseFcltBizFk:
|
||||
ref.current?.[0]?.ruseFcltBizFk ?? form.getValues("pbnstRuseFcltBizPk"),
|
||||
choose: false,
|
||||
ppMqlt: "",
|
||||
pdmt: "",
|
||||
cpct: 0,
|
||||
};
|
||||
const currentTableDataFromRef = ref.current ? [...ref.current] : [];
|
||||
const newDataForRHF = [...currentTableDataFromRef, regData];
|
||||
form.setValue("pplInstls", newDataForRHF, {
|
||||
shouldValidate: true, // 필요하다면 유효성 검사 실행
|
||||
shouldDirty: true, // 폼 상태를 dirty로 변경
|
||||
});
|
||||
const latestOpers = form.getValues("pplInstls");
|
||||
ref.current = [...latestOpers];
|
||||
if (
|
||||
form.getValues(`items.${indexMng}.fcBizs.${indexBiz}.pbnstRuseFcltBizPk`)
|
||||
) {
|
||||
appendPpl({
|
||||
ruseFcltBizFk: form.getValues(
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.pbnstRuseFcltBizPk`
|
||||
),
|
||||
choose: false,
|
||||
ppMqlt: "",
|
||||
pdmt: "",
|
||||
cpct: 0,
|
||||
});
|
||||
} else {
|
||||
appendPpl({
|
||||
choose: false,
|
||||
ppMqlt: "",
|
||||
pdmt: "",
|
||||
cpct: 0,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const plusArray = () => {
|
||||
@@ -221,29 +238,31 @@ export function PbnstBuseForm({
|
||||
splyEndDay: new Date(),
|
||||
splyCpct: 0,
|
||||
splyFmYn: "Y",
|
||||
pbnstRuseFcltBizPk: form.getValues("pbnstRuseFcltBizPk"),
|
||||
pbnstRuseFcltFk: form.getValues("pbnstRuseFcltFk") ?? "",
|
||||
pbnstRuseFcltBizPk: form.getValues(
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.pbnstRuseFcltBizPk`
|
||||
),
|
||||
pbnstRuseFcltFk:
|
||||
form.getValues(
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.pbnstRuseFcltFk`
|
||||
) ?? "",
|
||||
dmdInfoFk: "",
|
||||
//telno: "",
|
||||
});
|
||||
};
|
||||
|
||||
const removeSelected = () => {
|
||||
if (!ref.current) return;
|
||||
const selectedIdxs = ref.current
|
||||
const nowPPl = form.getValues(
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.pplInstls`
|
||||
);
|
||||
|
||||
if (!nowPPl) return;
|
||||
|
||||
const selectedIdxs = nowPPl
|
||||
.map((item, idx) => (item.choose ? idx : -1))
|
||||
.filter((idx) => idx !== -1);
|
||||
selectedIdxs.reverse().forEach((idx) => remove(idx));
|
||||
selectedIdxs.reverse().forEach((idx) => removePpl(idx));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (bizCycle && formType !== "reg") {
|
||||
const index = Number(bizCycle) - 1;
|
||||
form.reset(pbnst.pbnstResObj?.fcBizs[index]);
|
||||
ref.current = pbnst.pbnstResObj?.fcBizs[index]?.pplInstls ?? [];
|
||||
}
|
||||
}, [bizCycle, pbnst.pbnstResObj, formType]);
|
||||
|
||||
useEffect(() => {
|
||||
const ppl = [] as { name: string; val: SelectDataType[] }[];
|
||||
if (code.pplLenght) {
|
||||
@@ -259,10 +278,6 @@ export function PbnstBuseForm({
|
||||
}
|
||||
}, [code]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(" fcDemands ", fcDemands);
|
||||
}, [fcDemands]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(" demandCompList ", demandCompList);
|
||||
}, [demandCompList]);
|
||||
@@ -270,6 +285,16 @@ export function PbnstBuseForm({
|
||||
console.log("form errors:", form.formState.errors);
|
||||
}, [form.formState.errors]);
|
||||
|
||||
useEffect(() => {
|
||||
const pplSum = form.watch(`items.${indexMng}.fcBizs.${indexBiz}.pplInstls`);
|
||||
if (!pplSum) return;
|
||||
let sum = 0;
|
||||
pplSum.forEach((item) => {
|
||||
sum += Number(item.cpct) || 0;
|
||||
});
|
||||
setSumCpct(sum);
|
||||
}, [form.formState, indexMng, indexBiz]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className=" !mx-[1.6rem] !p-0r">
|
||||
@@ -277,25 +302,23 @@ export function PbnstBuseForm({
|
||||
<div className="justify-between">
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(onSubmit)}
|
||||
key={indexBiz}
|
||||
// onSubmit={form.handleSubmit(onSubmit)}
|
||||
className="space-y-8 mx-auto w-full mt-7"
|
||||
>
|
||||
<div className="flex justify-between items-center mx-3 mb-3">
|
||||
<h1 className=" text-xl"></h1>
|
||||
<div className="flex items-center gap-2 mx-3">
|
||||
<h1 className={formTableName}>등록차수</h1>
|
||||
|
||||
<SelectBox
|
||||
label=""
|
||||
selectArray={pbnstBizCycle}
|
||||
value={bizCycle ?? pbnstBizCycle[0]?.val}
|
||||
selectArray={selectBizCycle || []}
|
||||
value={selectBizCycle[indexBiz]?.val}
|
||||
className={""}
|
||||
selectClass={selectClass}
|
||||
onSelectValue={(val) => {
|
||||
setBizCycle(String(val));
|
||||
getpbnstInsertIndex({
|
||||
...pbnst.pbnsUpdateIndex,
|
||||
biz: Number(val),
|
||||
});
|
||||
setIndexBiz(Number(val));
|
||||
}}
|
||||
></SelectBox>
|
||||
|
||||
@@ -304,7 +327,7 @@ export function PbnstBuseForm({
|
||||
type="button"
|
||||
size={commonButonSize}
|
||||
>
|
||||
저장
|
||||
추가
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -314,6 +337,8 @@ export function PbnstBuseForm({
|
||||
form={form}
|
||||
moClass="grid grid-cols-12 gap-4"
|
||||
sonClass="col-span-4"
|
||||
indexMng={indexMng}
|
||||
indexBiz={indexBiz}
|
||||
/>
|
||||
<MngRegFormDetail
|
||||
formList={businessMoneyInfo}
|
||||
@@ -321,13 +346,18 @@ export function PbnstBuseForm({
|
||||
form={form}
|
||||
moClass="grid grid-cols-12 gap-4"
|
||||
sonClass="col-span-4"
|
||||
indexMng={indexMng}
|
||||
indexBiz={indexBiz}
|
||||
/>
|
||||
|
||||
<MngRegFormDetail
|
||||
formList={ruseFcltinfo}
|
||||
h1Title={"재처리시설"}
|
||||
form={form}
|
||||
moClass="grid grid-cols-12 gap-4"
|
||||
sonClass="col-span-4"
|
||||
indexMng={indexMng}
|
||||
indexBiz={indexBiz}
|
||||
/>
|
||||
<MngRegFormDetail
|
||||
formList={concentratedWaterInfo}
|
||||
@@ -335,6 +365,8 @@ export function PbnstBuseForm({
|
||||
form={form}
|
||||
moClass="grid grid-cols-12 gap-4"
|
||||
sonClass="col-span-4"
|
||||
indexMng={indexMng}
|
||||
indexBiz={indexBiz}
|
||||
/>
|
||||
<MngRegFormDetail
|
||||
formList={wasteWaterFcltINfo}
|
||||
@@ -342,6 +374,8 @@ export function PbnstBuseForm({
|
||||
form={form}
|
||||
moClass="grid grid-cols-12 gap-4"
|
||||
sonClass="col-span-4"
|
||||
indexMng={indexMng}
|
||||
indexBiz={indexBiz}
|
||||
/>
|
||||
|
||||
<h1 className={formH1Class}>재이용 원수취수 현황</h1>
|
||||
@@ -357,9 +391,17 @@ export function PbnstBuseForm({
|
||||
</Button>
|
||||
</div>
|
||||
<RuseMngTable
|
||||
tableData={fcOrgwtFiled}
|
||||
key={`fcOrgwts-${indexMng}-${indexBiz}`} // 이게 핵심!
|
||||
tableData={
|
||||
form.getValues(
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.fcOrgwts`
|
||||
) ?? []
|
||||
}
|
||||
headList={pbnst.pbnstOrgwtHeadList}
|
||||
upHeadList={[]}
|
||||
indexMng={indexMng}
|
||||
indexBiz={indexBiz}
|
||||
formNm={"fcOrgwts"}
|
||||
/>
|
||||
</div>
|
||||
<h1 className={formH1Class}>재이용 공급관로 설치 현황</h1>
|
||||
@@ -404,16 +446,28 @@ export function PbnstBuseForm({
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<RuseMngTable
|
||||
tableData={pplInstls}
|
||||
<RuseMngTableForm
|
||||
key={`pplInstls-${indexMng}-${indexBiz}`} // 이게 핵심!
|
||||
tableData={
|
||||
form.getValues(
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.pplInstls`
|
||||
) ?? []
|
||||
}
|
||||
headList={pbnst.pplInstlsHeadLisat}
|
||||
code={ppiSelectList ?? []}
|
||||
ref={ref}
|
||||
//ref={ref}
|
||||
indexMng={indexMng}
|
||||
indexBiz={indexBiz}
|
||||
form={form}
|
||||
formNm={"pplInstls"}
|
||||
upHeadList={[]}
|
||||
onTableSet={(val) => {
|
||||
if (!ref.current) return;
|
||||
const pplSum = form.getValues(
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.pplInstls`
|
||||
);
|
||||
if (!pplSum) return;
|
||||
let sum = 0;
|
||||
ref.current.forEach((item) => {
|
||||
pplSum.forEach((item) => {
|
||||
sum += Number(item.cpct) || 0;
|
||||
});
|
||||
setSumCpct(sum);
|
||||
@@ -427,6 +481,8 @@ export function PbnstBuseForm({
|
||||
form={form}
|
||||
moClass="grid grid-cols-12 gap-4"
|
||||
sonClass="col-span-4"
|
||||
indexMng={indexMng}
|
||||
indexBiz={indexBiz}
|
||||
/>
|
||||
<div key={"hasu"}>
|
||||
<h1 className={formH1Class}>{"하수처리수 재이용수 수요처"}</h1>
|
||||
@@ -455,15 +511,19 @@ export function PbnstBuseForm({
|
||||
수요처 추가
|
||||
</Button>
|
||||
</div>
|
||||
{fcDemands.map((field, index) => (
|
||||
{(
|
||||
form.getValues(
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.fcDemands`
|
||||
) || []
|
||||
).map((field, index) => (
|
||||
<div
|
||||
key={index + "loot"}
|
||||
key={`fcDemands-${indexMng}-${indexBiz}`} // 이게 핵심!
|
||||
className="grid grid-cols-12 gap-4 mt-3"
|
||||
>
|
||||
<div key={index + "keySon1"} className="col-span-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={`fcDemands.${index}.dmdCoNm`}
|
||||
name={`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.dmdCoNm`}
|
||||
render={({ field: f }) => (
|
||||
<FormUi label="수요처명">
|
||||
<SearchInputText
|
||||
@@ -471,61 +531,32 @@ export function PbnstBuseForm({
|
||||
initValue={f.value}
|
||||
setValue={(val) => {
|
||||
f.onChange(val);
|
||||
console.log("val ", val);
|
||||
if (val && val.length > 2) {
|
||||
getDemandCompList(val, 3);
|
||||
}
|
||||
}}
|
||||
setRtnData={(valList: any) => {
|
||||
if (valList) {
|
||||
console.log(
|
||||
" form.getValues ",
|
||||
form.getValues("pbnstRuseFcltBizPk")
|
||||
);
|
||||
const bizPk =
|
||||
form.getValues("pbnstRuseFcltBizPk");
|
||||
|
||||
if (form.getValues("pbnstRuseFcltBizPk")) {
|
||||
form.setValue(
|
||||
`fcDemands.${index}.pbnstRuseFcltBizPk`,
|
||||
bizPk
|
||||
);
|
||||
}
|
||||
form.setValue(
|
||||
`fcDemands.${index}.pbnstRuseFcltFk`,
|
||||
form.getValues("pbnstRuseFcltFk") ?? ""
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.dmdInfoFk`,
|
||||
valList.dmdInfoPk
|
||||
);
|
||||
form.setValue(
|
||||
`fcDemands.${index}.dmdCoNm`,
|
||||
valList.dmdCoNm
|
||||
);
|
||||
form.setValue(
|
||||
`fcDemands.${index}.daddr`,
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.daddr`,
|
||||
valList.daddr
|
||||
);
|
||||
form.setValue(
|
||||
`fcDemands.${index}.useUsgCd`,
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.useUsgCd`,
|
||||
valList.useUsgCd
|
||||
);
|
||||
form.setValue(
|
||||
`fcDemands.${index}.splyCpct`,
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.splyCpct`,
|
||||
valList.splyCpct
|
||||
);
|
||||
form.setValue(
|
||||
`fcDemands.${index}.splyFmYn`,
|
||||
valList.splyFmYn ?? "Y"
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.dmdInfoFk`,
|
||||
valList.dmdInfoPk?.toString()
|
||||
);
|
||||
form.setValue(
|
||||
`fcDemands.${index}.dmdInfoFk`,
|
||||
valList.dmdInfoPk?.toString() ?? ""
|
||||
);
|
||||
|
||||
// field.daddr=valList.daddr;
|
||||
// field.useUsgCd=valList.useUsgCd;
|
||||
// field.splyCpct=valList.splyCpct;
|
||||
// field.splyFmYn=valList.splyFmYn;
|
||||
// field.dmdInfoFk=valList.dmdInfoPk?.toString();
|
||||
// field.dmdCoNm=valList.dmdCoNm;
|
||||
}
|
||||
}}
|
||||
searchList={demandCompList?.map((item) => {
|
||||
@@ -543,7 +574,7 @@ export function PbnstBuseForm({
|
||||
<div key={index + "keySon2"} className="col-span-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={`fcDemands.${index}.daddr`}
|
||||
name={`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.daddr`}
|
||||
render={({ field: f }) => (
|
||||
<FormUi label="위치(주소)">
|
||||
<Input
|
||||
@@ -561,7 +592,7 @@ export function PbnstBuseForm({
|
||||
<div key={index + "keySon3"} className="col-span-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={`fcDemands.${index}.useUsgCd`}
|
||||
name={`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.useUsgCd`}
|
||||
render={({ field: f }) => (
|
||||
<FormUi label="사용용도">
|
||||
<SelectBox
|
||||
@@ -579,7 +610,7 @@ export function PbnstBuseForm({
|
||||
<div key={index + "keySon4"} className="col-span-3">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={`fcDemands.${index}.splyBgngDay`}
|
||||
name={`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.splyBgngDay`}
|
||||
render={({ field: f }) => (
|
||||
<FormUi label="공급시작일">
|
||||
<DatePicker
|
||||
@@ -597,7 +628,7 @@ export function PbnstBuseForm({
|
||||
<div key={index + "keySon5"} className="col-span-3">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={`fcDemands.${index}.splyEndDay`}
|
||||
name={`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.splyEndDay`}
|
||||
render={({ field: f }) => (
|
||||
<FormUi label="공급종료일">
|
||||
<DatePicker
|
||||
@@ -615,7 +646,7 @@ export function PbnstBuseForm({
|
||||
<div key={index + "keySon6"} className="col-span-3">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={`fcDemands.${index}.splyCpct`}
|
||||
name={`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.splyCpct`}
|
||||
render={({ field: f }) => (
|
||||
<FormUi label="(계약)공급량(m3/일)">
|
||||
<Input
|
||||
@@ -633,7 +664,7 @@ export function PbnstBuseForm({
|
||||
<div key={index + "keySon7"} className="col-span-3">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={`fcDemands.${index}.splyFmYn`}
|
||||
name={`items.${indexMng}.fcBizs.${indexBiz}.fcDemands.${index}.splyFmYn`}
|
||||
render={({ field: f }) => (
|
||||
<FormUi label="공급 유량계 유무">
|
||||
<SelectBox
|
||||
@@ -660,14 +691,17 @@ export function PbnstBuseForm({
|
||||
<UiModal
|
||||
open={isFcOrgwts}
|
||||
onOpenChange={(open: boolean) => setIsFcOrgwts(open)}
|
||||
bodyClass={"w-[50vw] max-w-none h-[60vh]"}
|
||||
bodyClass={"w-[50vw] max-w-none h-[90vh]"}
|
||||
body={
|
||||
<FcOrgwtsRegModal
|
||||
closeModal={() => {
|
||||
setIsFcOrgwts(false);
|
||||
}}
|
||||
onRightSet={(val) => {
|
||||
form.setValue("fcOrgwts", val);
|
||||
form.setValue(
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.fcOrgwts`,
|
||||
val
|
||||
);
|
||||
}}
|
||||
></FcOrgwtsRegModal>
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { useWrStore } from "@/app/store";
|
||||
import { FileUpload, FormUi, SelectBox, type SelectDataType } from "@common/business_components/ui";
|
||||
import {
|
||||
FileUpload,
|
||||
FormUi,
|
||||
SelectBox,
|
||||
type SelectDataType,
|
||||
} from "@common/business_components/ui";
|
||||
import { Form, FormField } from "@common/business_components/ui/form";
|
||||
import { Button, Input } from "@common/components";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useFieldArray, useForm } from "react-hook-form";
|
||||
import { useFieldArray, useForm, type UseFormReturn } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
commonButonSize,
|
||||
@@ -20,22 +25,30 @@ import {
|
||||
type customPbnst,
|
||||
type fcFileType,
|
||||
type operType,
|
||||
type PbnstRegArrrayType,
|
||||
type selectLabel,
|
||||
} from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import { TEST_UUID } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
|
||||
import { Label } from "@common/business_components/ui/form/lib/label";
|
||||
import React from "react";
|
||||
import RuseMngTableForm from "@/components/ui/table/pbnstReg/ruseMngTableForm/ruseMngTableForm";
|
||||
export type FilesType = {
|
||||
atflCd: string;
|
||||
file: File;
|
||||
};
|
||||
|
||||
export function PbnstMngForm({
|
||||
form,
|
||||
formType,
|
||||
firstFcltData,
|
||||
indexMng ,
|
||||
setIndexMng,
|
||||
}: {
|
||||
form: UseFormReturn<{items:PbnstRegArrrayType}>;
|
||||
formType: string;
|
||||
firstFcltData?: customPbnst;
|
||||
indexMng: number;
|
||||
setIndexMng: (index: number) => void;
|
||||
}) {
|
||||
const {
|
||||
code,
|
||||
@@ -49,86 +62,84 @@ export function PbnstMngForm({
|
||||
appendRuseFclt,
|
||||
} = useWrStore((state) => state);
|
||||
|
||||
const { pbnstRes } = pbnst;
|
||||
const [regFileList, setRegFileList] = useState<fcFileType[] | null>(null);
|
||||
const [planFiles, setPlanFiles] = useState<FilesType[] | null>(null);
|
||||
const [relationfiles, setRelationFiles] = useState<FilesType[] | null>(null);
|
||||
const [fcltNm, setFcltNm] = useState<selectLabel[] | null>(null);
|
||||
const [fcOpresData, setFcOpresData] = useState<operType[] | null>(null);
|
||||
const [mngMtdCode, setMngMtdCode] = useState<{ name: string, val: SelectDataType[] }[]>();
|
||||
//const [fcOpresData, setFcOpresData] = useState<operType[] | null>(null);
|
||||
const [mngMtdCode, setMngMtdCode] =
|
||||
useState<{ name: string; val: SelectDataType[] }[]>();
|
||||
|
||||
const [progress, setProgress] = useState(0);
|
||||
//const new File([] as BlobPart[], "") 파일 다운로드 활용
|
||||
const ref = useRef<operType[] | null>(null);
|
||||
//const ref = useRef<operType[] | null>(null);
|
||||
|
||||
const form = useForm<z.infer<typeof pbnstRegZod>>({
|
||||
resolver: zodResolver(pbnstRegZod),
|
||||
defaultValues:
|
||||
formType === "reg" && pbnst.pbnstMngRegData
|
||||
? pbnst.pbnstMngRegData[0]
|
||||
: formType === "update" &&
|
||||
typeof pbnst.pbnsUpdateIndex.mng === "number" &&
|
||||
pbnst.pbnsUpdateIndex.mng >= 0 &&
|
||||
pbnst.pbnstRes
|
||||
? pbnst.pbnstRes[pbnst.pbnsUpdateIndex.mng]
|
||||
: formType === "sttn" && firstFcltData
|
||||
? {
|
||||
ruseUtztnFcltNm: firstFcltData?.ruseUtztnFcltNm,
|
||||
fcltCpct: firstFcltData?.fcltCpct,
|
||||
ruseCpct: firstFcltData?.ruseCpct,
|
||||
splyExtraCpct: firstFcltData?.splyExtraCpct,
|
||||
fcOpers: firstFcltData?.fcOpers,
|
||||
fcFiles: firstFcltData?.fcFiles,
|
||||
}
|
||||
: pbnstRegZod.parse({}),
|
||||
mode: "onChange",
|
||||
});
|
||||
|
||||
// const form = useForm<z.infer<typeof pbnstRegZod>>({
|
||||
// resolver: zodResolver(pbnstRegZod),
|
||||
// defaultValues:
|
||||
// formType === "reg" && pbnst.pbnstMngRegData
|
||||
// ? pbnst.pbnstMngRegData[0]
|
||||
// : formType === "update" &&
|
||||
// typeof pbnst.pbnsUpdateIndex.mng === "number" &&
|
||||
// pbnst.pbnsUpdateIndex.mng >= 0 &&
|
||||
// pbnst.pbnstRes
|
||||
// ? pbnst.pbnstRes[pbnst.pbnsUpdateIndex.mng]
|
||||
// : formType === "sttn" && firstFcltData
|
||||
// ? {
|
||||
// ruseUtztnFcltNm: firstFcltData?.ruseUtztnFcltNm,
|
||||
// fcltCpct: firstFcltData?.fcltCpct,
|
||||
// ruseCpct: firstFcltData?.ruseCpct,
|
||||
// splyExtraCpct: firstFcltData?.splyExtraCpct,
|
||||
// fcOpers: firstFcltData?.fcOpers,
|
||||
// fcFiles: firstFcltData?.fcFiles,
|
||||
// }
|
||||
// : pbnstRegZod.parse({}),
|
||||
// mode: "onChange",
|
||||
// });
|
||||
const {
|
||||
fields: fcOpersField,
|
||||
append,
|
||||
remove,
|
||||
} = useFieldArray({
|
||||
control: form.control,
|
||||
name: "fcOpers",
|
||||
name: `items.${indexMng}.fcOpers`,
|
||||
});
|
||||
|
||||
const handleProgress = (percentage: string) => {
|
||||
setProgress(Number(percentage));
|
||||
};
|
||||
|
||||
|
||||
const selectFclt = (val: number) => {
|
||||
if (pbnst.pbnstRes && pbnst.pbnstRes[val]) {
|
||||
getBizCycle(pbnst.pbnstRes[val]);
|
||||
form.reset(pbnst.pbnstRes[val]);
|
||||
// if (pbnst.pbnstRes && pbnst.pbnstRes[val]) {
|
||||
// getBizCycle(pbnst.pbnstRes[val]);
|
||||
// // form.reset(pbnst.pbnstRes[val]);
|
||||
|
||||
getpbnstInsertIndex({ ...pbnst.pbnsUpdateIndex, mng: val });
|
||||
}
|
||||
// getpbnstInsertIndex({ ...pbnst.pbnsUpdateIndex, mng: val });
|
||||
// }
|
||||
};
|
||||
|
||||
const plusHist = () => {
|
||||
const currentTableDataFromRef = ref.current ? [...ref.current] : [];
|
||||
const regData = {
|
||||
append( {
|
||||
choose: false,
|
||||
pbnstRuseFcltFk: form.getValues("pbnstRuseFcltPk") ?? "",
|
||||
pbnstRuseFcltFk: form.getValues(`items.${indexMng}.pbnstRuseFcltPk`) ?? "",
|
||||
rgtr: "",
|
||||
mdfr: "",
|
||||
operMthd: "",
|
||||
rprtvBzenty: "",
|
||||
bgngDt: new Date(),
|
||||
endDt: new Date(),
|
||||
};
|
||||
const newDataForRHF = [...currentTableDataFromRef, regData];
|
||||
form.setValue("fcOpers", newDataForRHF, {
|
||||
shouldValidate: true, // 필요하다면 유효성 검사 실행
|
||||
shouldDirty: true, // 폼 상태를 dirty로 변경
|
||||
});
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
const removeSelected = () => {
|
||||
if (!ref.current) return;
|
||||
const selectedIdxs = ref.current
|
||||
.map((item, idx) => (item.choose ? idx : -1))
|
||||
.filter((idx) => idx !== -1);
|
||||
selectedIdxs.reverse().forEach((idx) => remove(idx));
|
||||
|
||||
const nowOpers = form.getValues(`items.${indexMng}.fcOpers`);
|
||||
if(!nowOpers) return;
|
||||
|
||||
const selectedIdxs = nowOpers.map((item, idx) => (item.choose ? idx : -1))
|
||||
.filter((idx) => idx !== -1);
|
||||
selectedIdxs.reverse().forEach((idx) => remove(idx));
|
||||
};
|
||||
|
||||
const fileHandler = (files: File[], type: string) => {
|
||||
@@ -203,79 +214,87 @@ export function PbnstMngForm({
|
||||
|
||||
// 등록할때 신규 값을 계속 가지고 있으려고
|
||||
useEffect(() => {
|
||||
if (
|
||||
formType === "reg" &&
|
||||
firstFcltData &&
|
||||
(form.getValues("swtrmtFcltFk") === "" ||
|
||||
form.getValues("swtrmtFcltFk") === undefined)
|
||||
) {
|
||||
form.setValue("swtrmtFcltFk", firstFcltData.swtrmtFcltFk);
|
||||
form.setValue("pbnstRuseFcltPk", String(firstFcltData.pbnstRuseFcltPk));
|
||||
form.setValue("fcBizs", firstFcltData.fcBizs);
|
||||
}
|
||||
}, [firstFcltData]);
|
||||
// if (
|
||||
// formType === "reg" &&
|
||||
// firstFcltData &&
|
||||
// (form.getValues(`items.${indexMng}.swtrmtFcltFk`) === "" ||
|
||||
// form.getValues(`items.${indexMng}.swtrmtFcltFk`) === undefined)
|
||||
// ) {
|
||||
// form.setValue(`items.${indexMng}.swtrmtFcltFk`, firstFcltData.swtrmtFcltFk);
|
||||
// form.setValue(
|
||||
// `items.${indexMng}.pbnstRuseFcltPk`,
|
||||
// String(firstFcltData.pbnstRuseFcltPk)
|
||||
// );
|
||||
// form.setValue(`items.${indexMng}.fcBizs`, firstFcltData.fcBizs);
|
||||
// }
|
||||
console.log('indexMng ', indexMng)
|
||||
}, [indexMng]);
|
||||
|
||||
useEffect(() => {
|
||||
const defaultFiles = form.getValues("fcFiles");
|
||||
|
||||
if (defaultFiles && defaultFiles.length > 0) {
|
||||
const relationFileList = defaultFiles.filter(
|
||||
(item) => item.fileKnd === "계통도"
|
||||
);
|
||||
|
||||
const planFileList = defaultFiles.filter(
|
||||
(item) => item.fileKnd === "평면도"
|
||||
);
|
||||
if (relationFileList.length > 0)
|
||||
setRelationFiles(
|
||||
relationFileList.map((item) => ({
|
||||
atflCd: item.fileTkn,
|
||||
file: new File([] as BlobPart[], item.filePath),
|
||||
}))
|
||||
); // 또는 파일 형식 변환 로직이 있다면 여기에 추가
|
||||
|
||||
if (planFileList.length > 0)
|
||||
setPlanFiles(
|
||||
planFileList.map((item) => ({
|
||||
atflCd: item.fileTkn,
|
||||
file: new File([] as BlobPart[], item.filePath),
|
||||
}))
|
||||
if(indexMng>=0){
|
||||
const defaultFiles = form.getValues(`items.${indexMng}.fcFiles`);
|
||||
if (defaultFiles && defaultFiles.length > 0) {
|
||||
const relationFileList = defaultFiles.filter(
|
||||
(item) => item.fileKnd === "계통도"
|
||||
);
|
||||
|
||||
const planFileList = defaultFiles.filter(
|
||||
(item) => item.fileKnd === "평면도"
|
||||
);
|
||||
if (relationFileList.length > 0)
|
||||
setRelationFiles(
|
||||
relationFileList.map((item) => ({
|
||||
atflCd: item.fileTkn,
|
||||
file: new File([] as BlobPart[], item.filePath),
|
||||
}))
|
||||
); // 또는 파일 형식 변환 로직이 있다면 여기에 추가
|
||||
|
||||
if (planFileList.length > 0)
|
||||
setPlanFiles(
|
||||
planFileList.map((item) => ({
|
||||
atflCd: item.fileTkn,
|
||||
file: new File([] as BlobPart[], item.filePath),
|
||||
}))
|
||||
);
|
||||
}else{
|
||||
setRelationFiles(null);
|
||||
setPlanFiles(null);
|
||||
}
|
||||
}
|
||||
}, [form.formState.defaultValues]); // 초기화 이후 1회 실행
|
||||
}, [form.watch(`items.${indexMng}`),indexMng]); // 초기화 이후 1회 실행
|
||||
|
||||
// 등록할때 신규 값을 계속 가지고 있으려고
|
||||
useEffect(() => {
|
||||
if (
|
||||
formType === "update" &&
|
||||
pbnst.pbnsUpdateIndex.biz >= 0 &&
|
||||
pbnst.pbnstRes
|
||||
) {
|
||||
const bizData = pbnst.pbnstRes[pbnst.pbnsUpdateIndex.biz];
|
||||
// if (
|
||||
// formType === "update" &&
|
||||
// pbnst.pbnsUpdateIndex.biz >= 0 &&
|
||||
// pbnst.pbnstRes
|
||||
// ) {
|
||||
// const bizData = pbnst.pbnstRes[pbnst.pbnsUpdateIndex.biz];
|
||||
|
||||
if (bizData) {
|
||||
getBizCycle(bizData);
|
||||
}
|
||||
}
|
||||
// if (bizData) {
|
||||
// getBizCycle(bizData);
|
||||
// }
|
||||
// }
|
||||
}, [pbnst.pbnsUpdateIndex, pbnst.pbnstRes, formType, getBizCycle]);
|
||||
|
||||
//신규 등록시 입력할때 데이터 넣기
|
||||
useEffect(() => {
|
||||
const formData = form.watch();
|
||||
formData.fcOpers = ref.current ? [...ref.current] : [];
|
||||
formData.fcFiles = regFileList ? [...regFileList] : [];
|
||||
if (formType === "reg") {
|
||||
console.log("formData ", formData);
|
||||
pbnstMngData([formData] as customPbnst[]);
|
||||
} else if (formType === "update") {
|
||||
const updateRes = pbnst.pbnstRes?.map((item) => {
|
||||
if (item.pbnstRuseFcltPk === item.pbnstRuseFcltPk) {
|
||||
item = formData as customPbnst;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
pbnstMngData(updateRes as customPbnst[]);
|
||||
}
|
||||
// const formData = form.watch();
|
||||
// formData.fcOpers = ref.current ? [...ref.current] : [];
|
||||
// formData.fcFiles = regFileList ? [...regFileList] : [];
|
||||
// if (formType === "reg") {
|
||||
// console.log("formData ", formData);
|
||||
// pbnstMngData([formData] as customPbnst[]);
|
||||
// } else if (formType === "update") {
|
||||
// const updateRes = pbnst.pbnstRes?.map((item) => {
|
||||
// if (item.pbnstRuseFcltPk === item.pbnstRuseFcltPk) {
|
||||
// item = formData as customPbnst;
|
||||
// }
|
||||
// return item;
|
||||
// });
|
||||
// pbnstMngData(updateRes as customPbnst[]);
|
||||
// }
|
||||
}, [form.formState, regFileList, formType, pbnst.pbnstRes]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -288,13 +307,12 @@ export function PbnstMngForm({
|
||||
text: item.ruseUtztnFcltNm,
|
||||
val: String(index),
|
||||
}));
|
||||
|
||||
if (fcltNmList) setFcltNm(fcltNmList);
|
||||
}, [pbnst.pbnstRes]);
|
||||
|
||||
// 2. Define a submit handler.
|
||||
function onSubmit(values: z.infer<typeof pbnstRegZod>) {
|
||||
values.fcOpers = fcOpresData || [];
|
||||
values.fcOpers = [];
|
||||
values.fcFiles = regFileList || [];
|
||||
pbnstInsert(values);
|
||||
}
|
||||
@@ -310,21 +328,21 @@ export function PbnstMngForm({
|
||||
}
|
||||
}, [planFiles]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("form errors:", form.formState.errors);
|
||||
}, [form.formState.errors]);
|
||||
|
||||
useEffect(() => {
|
||||
if(code.ruseMngMtd){
|
||||
setMngMtdCode( [{name:"ruseMngMtd",val:code.ruseMngMtd}])
|
||||
}
|
||||
if (code.ruseMngMtd) {
|
||||
setMngMtdCode([{ name: "ruseMngMtd", val: code.ruseMngMtd }]);
|
||||
}
|
||||
}, [code]);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className=" !mx-[1.6rem] !p-0r">
|
||||
<div>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||
{/* <form onSubmit={form.handleSubmit()}> */}
|
||||
<form>
|
||||
<div className="flex justify-between items-center mx-3 mb-3">
|
||||
<div className="col-span-2 flex items-top">
|
||||
<Label className={formTableName + "pr-3 col-span-2 "}>
|
||||
@@ -332,20 +350,30 @@ export function PbnstMngForm({
|
||||
</Label>
|
||||
|
||||
{formType === "update" ? (
|
||||
<SelectBox
|
||||
label=""
|
||||
className="mt-4 ml-2"
|
||||
selectClass={undefined}
|
||||
selectArray={fcltNm ?? []}
|
||||
onSelectValue={(val) => {
|
||||
selectFclt(Number(val));
|
||||
}}
|
||||
value={""}
|
||||
<FormField
|
||||
key={`items.${indexMng}.ruseUtztnFcltNm-key`}
|
||||
control={form.control}
|
||||
name={`items.${indexMng}.ruseUtztnFcltNm`}
|
||||
render={({ field }) => (
|
||||
<FormUi label="">
|
||||
<SelectBox
|
||||
label=""
|
||||
selectArray={fcltNm ?? []}
|
||||
onSelectValue={(val) => {
|
||||
setIndexMng(Number(val));
|
||||
field.onChange(val);
|
||||
}}
|
||||
value={field.value ?? ""}
|
||||
className={""}
|
||||
selectClass={undefined}
|
||||
/>
|
||||
</FormUi>
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="ruseUtztnFcltNm"
|
||||
name={`items.${indexMng}.ruseUtztnFcltNm`}
|
||||
render={({ field }) => (
|
||||
<FormUi label="">
|
||||
<Input
|
||||
@@ -387,28 +415,33 @@ export function PbnstMngForm({
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<RuseMngTable
|
||||
tableData={fcOpersField}
|
||||
<RuseMngTableForm
|
||||
tableData={form.getValues(`items.${indexMng}.fcOpers`)||[]}
|
||||
headList={pbnst.pbnstMngUpHeadList}
|
||||
upHeadList={pbnst.pbnstMngNm}
|
||||
code={mngMtdCode || []}
|
||||
onTableSet={(val) => {
|
||||
setFcOpresData(val);
|
||||
//setFcOpresData(val);
|
||||
}}
|
||||
ref={ref}
|
||||
></RuseMngTable>
|
||||
indexMng={indexMng}
|
||||
form={form}
|
||||
formNm={"fcOpers"}
|
||||
// ref={ref}
|
||||
></RuseMngTableForm>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<h1 className={formH1Class}>재이용수 공급 가능량</h1>
|
||||
<div className="grid grid-cols-12 gap-4">
|
||||
<div className="col-span-3 mt-4">
|
||||
<div className="col-span-4 mt-4">
|
||||
<FormField
|
||||
key={`FormField-items.${indexMng}.splyExtraCpct`}
|
||||
control={form.control}
|
||||
name="fcltCpct"
|
||||
name={`items.${indexMng}.fcltCpct`}
|
||||
render={({ field }) => (
|
||||
<FormUi label="재이용 시설용량(m³/일)">
|
||||
<Input
|
||||
key={`items.${indexMng}.fcltCpct`}
|
||||
placeholder=""
|
||||
type="number"
|
||||
onChange={(e) => {
|
||||
@@ -420,14 +453,16 @@ export function PbnstMngForm({
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-3 mt-4">
|
||||
|
||||
<div className="col-span-4 mt-4">
|
||||
<FormField
|
||||
key={`FormField-items.${indexMng}.ruseCpct`}
|
||||
control={form.control}
|
||||
name="ruseCpct"
|
||||
name={`items.${indexMng}.ruseCpct`}
|
||||
render={({ field }) => (
|
||||
<FormUi label="재이용수공급량(m³/일)">
|
||||
<Input
|
||||
key={`items.${indexMng}.ruseCpct`}
|
||||
placeholder=""
|
||||
type="number"
|
||||
onChange={(e) => {
|
||||
@@ -439,13 +474,15 @@ export function PbnstMngForm({
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-3 mt-4">
|
||||
<div className="col-span-4 mt-4">
|
||||
<FormField
|
||||
key={`FormField-items.${indexMng}.splyExtraCpct`}
|
||||
control={form.control}
|
||||
name="splyExtraCpct"
|
||||
name={`items.${indexMng}.splyExtraCpct`}
|
||||
render={({ field }) => (
|
||||
<FormUi label="공급여유량(m³/일)">
|
||||
<Input
|
||||
key={`items.${indexMng}.splyExtraCpct`}
|
||||
placeholder=""
|
||||
type="number"
|
||||
onChange={(e) => {
|
||||
|
||||
+33
-24
@@ -1,16 +1,17 @@
|
||||
'use client'
|
||||
"use client";
|
||||
import { useWrStore } from "@/app/store";
|
||||
import type { formDetailType } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/headList";
|
||||
import { formH1Class } from "@/components/lib/class/comClass";
|
||||
import { safeDate } from "@/components/lib/func/commom";
|
||||
import {
|
||||
DatePicker,
|
||||
FormField,
|
||||
FormUi,
|
||||
SearchInputSelect,
|
||||
SelectBox,
|
||||
type SelectDataType,
|
||||
} from "@common/business_components/ui";
|
||||
import { DatePicker, Input } from "@common/components/ui";
|
||||
import { Input } from "@common/components/ui";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function MngRegFormDetail({
|
||||
@@ -19,48 +20,55 @@ export default function MngRegFormDetail({
|
||||
form,
|
||||
moClass,
|
||||
sonClass,
|
||||
cycle,
|
||||
onIputData,
|
||||
searchSelectData
|
||||
indexBiz,
|
||||
indexMng,
|
||||
}: {
|
||||
formList: formDetailType[];
|
||||
h1Title?: string;
|
||||
form: any;
|
||||
moClass?: string;
|
||||
cycle?: string;
|
||||
indexBiz?: number;
|
||||
indexMng?: number;
|
||||
sonClass?: string;
|
||||
onIputData?: (data: any) => void;
|
||||
searchSelectData?: SelectDataType[];
|
||||
}) {
|
||||
const { code } = useWrStore((state) => state);
|
||||
|
||||
const [searchData, setSearchData]= useState<string>('')
|
||||
|
||||
return (
|
||||
<>
|
||||
{h1Title ? <h1 className={formH1Class}>{h1Title}</h1> : <></>}
|
||||
<div className={moClass}>
|
||||
{formList?.map((item, index) => {
|
||||
const fieldId = cycle ? `${cycle}.${item.id}` : item.id;
|
||||
{formList?.map((formHead, index) => {
|
||||
const fieldId =
|
||||
typeof indexMng === "number" &&
|
||||
indexMng >= 0 &&
|
||||
typeof indexBiz === "number" &&
|
||||
indexBiz >= 0
|
||||
? `items.${indexMng}.fcBizs.${indexBiz}.${formHead.id}`
|
||||
: typeof indexMng === "number" && indexMng >= 0
|
||||
? `items.${indexMng}.${formHead.id}`
|
||||
: formHead.id;
|
||||
|
||||
return (
|
||||
<div className={sonClass} key={index + `${item.id}`}>
|
||||
<div className={sonClass} key={index + `${formHead.id}`}>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={fieldId}
|
||||
render={({ field }) => (
|
||||
<FormUi label={item.lable}>
|
||||
{item.type === "select" ? (
|
||||
<FormUi label={formHead.lable}>
|
||||
{formHead.type === "select" ? (
|
||||
<Input placeholder="" type="text" {...field} />
|
||||
) : item.type === "date" ? (
|
||||
) : formHead.type === "date" ? (
|
||||
<DatePicker
|
||||
mode={"single"}
|
||||
selected={safeDate(field.value) || new Date()}
|
||||
onSelect={(date: Date | undefined) =>
|
||||
field.onChange(date)
|
||||
}
|
||||
className={"rounded-lg !w-full"}
|
||||
field={{
|
||||
value: safeDate(field.value) || new Date(),
|
||||
onChange: (date: Date | undefined) =>
|
||||
field.onChange(date),
|
||||
}}
|
||||
selectClass={"w-full"}
|
||||
/>
|
||||
) : item.type === "number" ? (
|
||||
) : formHead.type === "number" ? (
|
||||
<Input
|
||||
placeholder=""
|
||||
type="number"
|
||||
@@ -68,8 +76,9 @@ export default function MngRegFormDetail({
|
||||
onChange={(e) => {
|
||||
field.onChange(Number(e.target.value));
|
||||
}}
|
||||
readOnly={formHead.option === "readOnly"?true:false}
|
||||
/>
|
||||
) : item.type === "selectYn" ? (
|
||||
) : formHead.type === "selectYn" ? (
|
||||
<SelectBox
|
||||
label={""}
|
||||
selectClass={""}
|
||||
@@ -78,7 +87,7 @@ export default function MngRegFormDetail({
|
||||
onSelectValue={(val: string | number) =>
|
||||
field.onChange(val)
|
||||
}
|
||||
value={field.value}
|
||||
value={field.value ?? "Y"}
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
@@ -86,6 +95,7 @@ export default function MngRegFormDetail({
|
||||
type="text"
|
||||
value={field.value ?? ""}
|
||||
onChange={field.onChange}
|
||||
readOnly={formHead.option === "readOnly"?true:false}
|
||||
/>
|
||||
)}
|
||||
</FormUi>
|
||||
@@ -98,4 +108,3 @@ export default function MngRegFormDetail({
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ export default function FcOrgwtsRegModal({ onRightSet, closeModal }: { onRightS
|
||||
const [inputVal, setInputVal] = useState<string>("");
|
||||
|
||||
useEffect(()=>{
|
||||
console.log("searchFclts", searchFclts);
|
||||
if(Array.isArray(searchFclts)){
|
||||
const filteredData = searchFclts.filter((item) => {
|
||||
if(rightData){
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
"use client";
|
||||
import { useWrStore } from "@/app/store";
|
||||
import {
|
||||
pbnstRegZod,
|
||||
type customPbnst,
|
||||
type fcBizType,
|
||||
type PbnstRegArrrayType,
|
||||
type pubHasuType,
|
||||
} from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import { PbnstMngForm } from "@/components/ui/form/fcltReg/pbnstReg/mngReg/mngRegForm";
|
||||
@@ -17,64 +16,88 @@ import {
|
||||
} from "@common/components/ui";
|
||||
import { useEffect, useState } from "react";
|
||||
import { PbnstBuseForm } from "@/components/ui/form/fcltReg/pbnstReg/buseReg/bugRegForm";
|
||||
import { useFieldArray, type UseFormReturn } from "react-hook-form";
|
||||
import { writeRgtrAndMdfr } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg";
|
||||
|
||||
export function PbnstRegModal({ data }: { data: pubHasuType }) {
|
||||
export function PbnstRegModal({
|
||||
data,
|
||||
form,
|
||||
}: {
|
||||
data: pubHasuType;
|
||||
form: UseFormReturn<{ items: PbnstRegArrrayType }>;
|
||||
}) {
|
||||
const { pbnst, pbnstInsert, pbnstMngData } = useWrStore((state) => {
|
||||
return state;
|
||||
});
|
||||
|
||||
const { pbnstRes } = pbnst;
|
||||
const [pbnstBdstForm, setPbnstBdstForm] = useState<customPbnst>(
|
||||
{} as customPbnst
|
||||
);
|
||||
const [currentTab, setCurrentTab] = useState<string>("mng");
|
||||
const [indexMng, setIndexMng] = useState<number>(0);
|
||||
const [indexBiz, setIndexBiz] = useState<number>(0);
|
||||
const onSubmit = async (valuse: { items: PbnstRegArrrayType }) => {
|
||||
|
||||
const item = valuse.items[indexMng];
|
||||
const data = item ? writeRgtrAndMdfr([item]) : [];
|
||||
|
||||
const pbnstRegTotal = () => {
|
||||
if (pbnst.pbnstMngRegData[0]) pbnstInsert(pbnst.pbnstMngRegData[0]);
|
||||
};
|
||||
if(data && data[0]){
|
||||
pbnstInsert(data[0])
|
||||
}
|
||||
};
|
||||
|
||||
const handleTabChange = (value: string) => {
|
||||
setCurrentTab(value);
|
||||
};
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log("form errors:", form.formState.errors);
|
||||
}, [form.formState.errors]);
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
let regData;
|
||||
if (pbnstRes && pbnstRes?.length > 0) {
|
||||
regData = {
|
||||
swtrmtFcltFk: String(data.bscFctCd),
|
||||
pbnstRuseFcltPk: String(data.bscFctCd) + String(pbnstRes.length + 1),
|
||||
fcBizs: [
|
||||
{
|
||||
pbnstRuseFcltFk:
|
||||
String(data.bscFctCd) + String(pbnstRes.length + 1),
|
||||
cycl: 1,
|
||||
} as unknown as fcBizType,
|
||||
],
|
||||
};
|
||||
//regData= pbnstRegZod.parse(regData)
|
||||
//setPbnstBdstForm(regData as unknown as customPbnst);
|
||||
// pbnstMngData([regData] as unknown as customPbnst[])
|
||||
} else {
|
||||
regData = {
|
||||
swtrmtFcltFk: String(data.bscFctCd),
|
||||
pbnstRuseFcltPk: String(data.bscFctCd + "1"),
|
||||
fcBizs: [
|
||||
{
|
||||
pbnstRuseFcltFk: String(data.bscFctCd + "1"),
|
||||
cycl: 1,
|
||||
} as unknown as fcBizType,
|
||||
],
|
||||
};
|
||||
//regData= pbnstRegZod.parse(regData)
|
||||
// setPbnstBdstForm(regData as unknown as customPbnst);
|
||||
const firstForm = form.getValues("items");
|
||||
|
||||
// pbnstMngData([regData] as unknown as customPbnst[])
|
||||
}
|
||||
regData = pbnstRegZod.parse(regData);
|
||||
setPbnstBdstForm(regData as unknown as customPbnst);
|
||||
console.log('mngIndex ', firstForm.length)
|
||||
setIndexMng(firstForm.length - 1)
|
||||
// console.log(' firstForm ', firstForm)
|
||||
// let regData;
|
||||
// if (pbnstRes && pbnstRes?.length > 0) {
|
||||
// regData = {
|
||||
// swtrmtFcltFk: String(data.bscFctCd),
|
||||
// pbnstRuseFcltPk: String(data.bscFctCd) + String(pbnstRes.length + 1),
|
||||
// fcBizs: [
|
||||
// {
|
||||
// pbnstRuseFcltFk:
|
||||
// String(data.bscFctCd) + String(pbnstRes.length + 1),
|
||||
// cycl: 1,
|
||||
// } as unknown as fcBizType,
|
||||
// ],
|
||||
// };
|
||||
// //regData= pbnstRegZod.parse(regData)
|
||||
// //setPbnstBdstForm(regData as unknown as customPbnst);
|
||||
// // pbnstMngData([regData] as unknown as customPbnst[])
|
||||
// } else {
|
||||
// regData = {
|
||||
// swtrmtFcltFk: String(data.bscFctCd),
|
||||
// pbnstRuseFcltPk: String(data.bscFctCd + "1"),
|
||||
// fcBizs: [
|
||||
// {
|
||||
// pbnstRuseFcltFk: String(data.bscFctCd + "1"),
|
||||
// cycl: 1,
|
||||
// } as unknown as fcBizType,
|
||||
// ],
|
||||
// };
|
||||
// //regData= pbnstRegZod.parse(regData)
|
||||
// // setPbnstBdstForm(regData as unknown as customPbnst);
|
||||
|
||||
// // pbnstMngData([regData] as unknown as customPbnst[])
|
||||
// }
|
||||
// regData = pbnstRegZod.parse(regData);
|
||||
// setPbnstBdstForm(regData as unknown as customPbnst);
|
||||
}
|
||||
}, [data, pbnstRes]);
|
||||
}, [data, form]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -93,7 +116,7 @@ export function PbnstRegModal({ data }: { data: pubHasuType }) {
|
||||
차수별정보
|
||||
</TabsTrigger>
|
||||
<Button
|
||||
onClick={pbnstRegTotal}
|
||||
onClick={ form.handleSubmit(onSubmit)}
|
||||
size={"sm"}
|
||||
className="!justify-end"
|
||||
>
|
||||
@@ -101,10 +124,22 @@ export function PbnstRegModal({ data }: { data: pubHasuType }) {
|
||||
</Button>
|
||||
</TabsList>
|
||||
<TabsContent className="max-h-full" value="mng">
|
||||
<PbnstMngForm formType={"reg"} firstFcltData={pbnstBdstForm} />
|
||||
<PbnstMngForm
|
||||
form={form}
|
||||
formType={"reg"}
|
||||
firstFcltData={pbnstBdstForm}
|
||||
indexMng={indexMng}
|
||||
setIndexMng={function (index: number): void {
|
||||
throw new Error("Function not implemented.");
|
||||
}}
|
||||
/>
|
||||
</TabsContent>
|
||||
<TabsContent className="max-h-full" value="buse">
|
||||
<PbnstBuseForm
|
||||
form={form}
|
||||
indexMng={indexMng}
|
||||
indexBiz={indexBiz}
|
||||
setIndexBiz={setIndexBiz}
|
||||
formType={"reg"}
|
||||
firstBizData={pbnstBdstForm.fcBizs}
|
||||
/>
|
||||
|
||||
@@ -62,7 +62,9 @@ export default function SearchInputText({
|
||||
document.removeEventListener("mousedown", handleClickOutside);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() =>{
|
||||
console.log('searchList ', searchList)
|
||||
},[searchList])
|
||||
|
||||
return (
|
||||
<div ref={wrapperRef}>
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { headMakeprfmnc } from "@/app/ruseFcltMng/prfmncReg/chkgdnReg/TableHead";
|
||||
import type { TableUpperProps } from "@/app/store/common/type/header";
|
||||
import type { chHeadType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList";
|
||||
import type { customPbnst as OriginalCustomPbnst } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
|
||||
|
||||
import { selectClass, type TableUpperProps } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
|
||||
import { DatePicker, SelectBox, type SelectDataType } from "@common/business_components/ui";
|
||||
import {
|
||||
DatePicker,
|
||||
SelectBox,
|
||||
type SelectDataType,
|
||||
} from "@common/business_components/ui";
|
||||
import {
|
||||
Checkbox,
|
||||
Input,
|
||||
@@ -20,43 +24,41 @@ type RuseMngTableProps = {
|
||||
tableData: any[];
|
||||
headList: TableUpperProps[];
|
||||
upHeadList: chHeadType[];
|
||||
code?: { name: string, val: SelectDataType[] }[];
|
||||
onTableSet?:(item:any)=> void;
|
||||
code?: { name: string; val: SelectDataType[] }[];
|
||||
onTableSet?: (item: any) => void;
|
||||
indexMng?: number;
|
||||
indexBiz?: number;
|
||||
};
|
||||
|
||||
const RuseMngTable = React.forwardRef<any, RuseMngTableProps>(
|
||||
({
|
||||
tableData,
|
||||
headList,
|
||||
upHeadList,
|
||||
code,
|
||||
onTableSet
|
||||
}, ref) => {
|
||||
(
|
||||
{ tableData, headList, upHeadList, code, onTableSet, indexMng, indexBiz },
|
||||
ref
|
||||
) => {
|
||||
const [tableState, setTableState] = useState([...tableData]);
|
||||
useEffect(() => {
|
||||
if (ref && typeof ref === "object" && "current" in ref) {
|
||||
ref.current = tableState;
|
||||
}
|
||||
if(onTableSet)
|
||||
onTableSet (tableState)
|
||||
}, [tableState,onTableSet]);
|
||||
if (onTableSet) onTableSet(tableState);
|
||||
}, [tableState, onTableSet]);
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if(tableData)
|
||||
setTableState(tableData);
|
||||
if (tableData) setTableState(tableData);
|
||||
}, [tableData]);
|
||||
return (
|
||||
<>
|
||||
<Table variant="secondary">
|
||||
<Table key={`table-${indexMng}-${indexBiz}`} variant="secondary">
|
||||
<TableHeader className="font-bold">
|
||||
{upHeadList ? (
|
||||
headMakeprfmnc(headList, upHeadList)
|
||||
) : (
|
||||
<TableRow key={"table-row-test"}>
|
||||
{headList.map((head) => (
|
||||
<TableHead key={"table-head-row " + head.id} className={`border border-gray-600 px-2 py-1 `}>
|
||||
<TableHead
|
||||
key={"table-head-row " + head.id}
|
||||
className={`border border-gray-600 px-2 py-1 `}
|
||||
>
|
||||
{head.title}
|
||||
</TableHead>
|
||||
))}
|
||||
@@ -71,54 +73,58 @@ const RuseMngTable = React.forwardRef<any, RuseMngTableProps>(
|
||||
<TableCell
|
||||
key={`${head.id}-${j}`}
|
||||
className="text-center whitespace-nowrap"
|
||||
onClick={() => { }}
|
||||
onClick={() => {}}
|
||||
>
|
||||
{head.edit === true ? (
|
||||
<Input
|
||||
className={`${head.type === "number" ? "text-right" : "text-center"} !text-xl`}
|
||||
type={head.type}
|
||||
onChange={(txt) => {
|
||||
setTableState(prev => {
|
||||
setTableState((prev) => {
|
||||
const next = [...prev];
|
||||
next[i] = { ...next[i], [head.id]: txt.target.value };
|
||||
next[i] = {
|
||||
...next[i],
|
||||
[head.id]: txt.target.value,
|
||||
};
|
||||
return next;
|
||||
})
|
||||
});
|
||||
}}
|
||||
value={head.type === "number" ?
|
||||
Number(tableState[i][head.id])||0 : tableState[i][head.id] || ""
|
||||
value={
|
||||
head.type === "number"
|
||||
? Number(tableState[i][head.id]) || 0
|
||||
: tableState[i][head.id] || ""
|
||||
}
|
||||
/>
|
||||
) : head.type === "select" ? (
|
||||
<SelectBox
|
||||
label=""
|
||||
selectArray={code?.find(item => item.name === head.selectData)?.val ?? []}
|
||||
value={
|
||||
tableState[i][head.id] || ""
|
||||
selectArray={
|
||||
code?.find((item) => item.name === head.selectData)
|
||||
?.val ?? []
|
||||
}
|
||||
value={tableState[i][head.id] || ""}
|
||||
className={""}
|
||||
selectClass={selectClass}
|
||||
onSelectValue={(val) => {
|
||||
setTableState((prev) => {
|
||||
prev[i][head.id] = val
|
||||
return [...prev]
|
||||
})
|
||||
prev[i][head.id] = val;
|
||||
return [...prev];
|
||||
});
|
||||
}}
|
||||
></SelectBox>
|
||||
) : head.type === "date" ? (
|
||||
<DatePicker
|
||||
mode="single"
|
||||
field={{
|
||||
value:
|
||||
tableState[i][head.id], // Provide a default Date value
|
||||
value: tableState[i][head.id], // Provide a default Date value
|
||||
onChange: (date) => {
|
||||
setTableState(prev => {
|
||||
setTableState((prev) => {
|
||||
const next = [...prev];
|
||||
next[i] = { ...next[i], [head.id]: date };
|
||||
return next;
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
}}
|
||||
selectClass={"w-full"}
|
||||
/>
|
||||
) : head.type === "checkbox" ? (
|
||||
@@ -128,14 +134,12 @@ const RuseMngTable = React.forwardRef<any, RuseMngTableProps>(
|
||||
onCheckedChange={(checked) => {
|
||||
console.log("checked", checked);
|
||||
setTableState((prev) => {
|
||||
prev[i][head.id] = checked
|
||||
return [...prev]
|
||||
})
|
||||
prev[i][head.id] = checked;
|
||||
return [...prev];
|
||||
});
|
||||
}}
|
||||
>
|
||||
</Checkbox>
|
||||
) :
|
||||
(
|
||||
></Checkbox>
|
||||
) : (
|
||||
`${item[head.id] || ""}`
|
||||
)}
|
||||
</TableCell>
|
||||
@@ -146,5 +150,6 @@ const RuseMngTable = React.forwardRef<any, RuseMngTableProps>(
|
||||
</Table>
|
||||
</>
|
||||
);
|
||||
})
|
||||
export default RuseMngTable;
|
||||
}
|
||||
);
|
||||
export default RuseMngTable;
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
import { headMakeprfmnc } from "@/app/ruseFcltMng/prfmncReg/chkgdnReg/TableHead";
|
||||
import type { TableUpperProps } from "@/app/store/common/type/header";
|
||||
import type { chHeadType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList";
|
||||
import type { customPbnst as OriginalCustomPbnst } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
|
||||
|
||||
import {
|
||||
DatePicker,
|
||||
FormField,
|
||||
FormUi,
|
||||
SelectBox,
|
||||
type SelectDataType,
|
||||
} from "@common/business_components/ui";
|
||||
import {
|
||||
Checkbox,
|
||||
Input,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@common/components/ui";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
type RuseMngTableProps = {
|
||||
tableData: any[];
|
||||
headList: TableUpperProps[];
|
||||
upHeadList: chHeadType[];
|
||||
code?: { name: string; val: SelectDataType[] }[];
|
||||
onTableSet?: (item: any) => void;
|
||||
indexMng?: number;
|
||||
indexBiz?: number;
|
||||
form?: any;
|
||||
formNm?:string
|
||||
};
|
||||
|
||||
const RuseMngTableForm = React.forwardRef<any, RuseMngTableProps>(
|
||||
({ tableData, headList, upHeadList, code, onTableSet, indexMng, form,formNm,indexBiz }, ref) => {
|
||||
// const [tableState, setTableState] = useState([...tableData]);
|
||||
|
||||
// // useEffect(() => {
|
||||
|
||||
// // if (ref && typeof ref === "object" && "current" in ref) {
|
||||
// // ref.current = tableState;
|
||||
// // }
|
||||
// // if (onTableSet) onTableSet(tableState);
|
||||
// // }, [tableState, onTableSet]);
|
||||
|
||||
// useEffect(() => {
|
||||
|
||||
// if (tableData)
|
||||
// setTableState(tableData);
|
||||
// }, [tableData]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Table key={`table-${indexMng}-${indexBiz}`} variant="secondary">
|
||||
<TableHeader className="font-bold">
|
||||
{upHeadList ? (
|
||||
headMakeprfmnc(headList, upHeadList)
|
||||
) : (
|
||||
<TableRow key={"table-row-test"}>
|
||||
{headList.map((head) => (
|
||||
<TableHead
|
||||
key={"table-head-row " + head.id}
|
||||
className={`border border-gray-600 px-2 py-1 `}
|
||||
>
|
||||
{head.title}
|
||||
</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
)}
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{tableData.map((item, i) => (
|
||||
<TableRow key={i}>
|
||||
{headList.map((head, j) => (
|
||||
<TableCell
|
||||
key={`${head.id}-${j}`}
|
||||
className="text-center whitespace-nowrap"
|
||||
onClick={() => {}}
|
||||
>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={
|
||||
typeof indexMng === "number" &&
|
||||
indexMng >= 0 &&
|
||||
typeof indexBiz === "number" &&
|
||||
indexBiz >= 0?
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.${formNm}.${i}.${head.id}`:
|
||||
typeof indexMng === "number" && indexMng >= 0?
|
||||
`items.${indexMng}.${formNm}.${i}.${head.id}`:
|
||||
`items.${indexMng}.${formNm}.${i}.${head.id}`}
|
||||
render={({ field }) => (
|
||||
<FormUi label="">
|
||||
{head.edit === true ? (
|
||||
<Input
|
||||
className={`${head.type === "number" ? "text-right" : "text-center"} !text-xl`}
|
||||
type={head.type}
|
||||
onChange={(txt) => {
|
||||
field.onChange(txt.target.value);
|
||||
}}
|
||||
value={
|
||||
head.type === "number"
|
||||
? (Number(field.value) ?? 0)
|
||||
: field.value || ""
|
||||
}
|
||||
/>
|
||||
) : head.type === "select" ? (
|
||||
<SelectBox
|
||||
label=""
|
||||
selectArray={
|
||||
code?.find(
|
||||
(item) => item.name === head.selectData
|
||||
)?.val ?? []
|
||||
}
|
||||
value={
|
||||
field.value || ""
|
||||
}
|
||||
className={""}
|
||||
selectClass={selectClass}
|
||||
onSelectValue={(val) => {
|
||||
field.onChange(val);
|
||||
}}
|
||||
></SelectBox>
|
||||
) : head.type === "date" ? (
|
||||
<DatePicker
|
||||
mode="single"
|
||||
field={{
|
||||
value: field.value || new Date(),
|
||||
onChange: (date: Date | undefined) =>
|
||||
field.onChange(date),
|
||||
}}
|
||||
selectClass={"w-full"}
|
||||
/>
|
||||
) : head.type === "checkbox" ? (
|
||||
<Checkbox
|
||||
className=""
|
||||
checked={ field.value || false}
|
||||
onCheckedChange={(checked) => {
|
||||
field.onChange(checked);
|
||||
|
||||
}}
|
||||
></Checkbox>
|
||||
) : (
|
||||
`${item[head.id] || ""}`
|
||||
)}
|
||||
</FormUi>
|
||||
)}
|
||||
/>
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</>
|
||||
);
|
||||
}
|
||||
);
|
||||
export default RuseMngTableForm;
|
||||
Reference in New Issue
Block a user