128 lines
3.5 KiB
TypeScript
128 lines
3.5 KiB
TypeScript
"use client";
|
|
import { headMakeColSpan } from "@/app/ruseFcltMng/fcltReg/rainReg/page";
|
|
import { useWrStore } from "@/app/store";
|
|
import {
|
|
selectClass,
|
|
type bdstType,
|
|
type selectArray,
|
|
} from "@/app/store/ruseFcltMng/fcltReg/rainReg";
|
|
import { ScrollArea, SearchInput, SelectBox, UiTable } from "@common/business_components";
|
|
import { Button, Input } from "@common/components";
|
|
import { useEffect, useState } from "react";
|
|
import { RainRegForm } from "../../form/fcltReg/rainReg/component";
|
|
|
|
export function BdstReg() {
|
|
const { rain, code, bdst, findBdst } = useWrStore((state) => {
|
|
return state;
|
|
});
|
|
|
|
const [bdstTable, setbdstTable] = useState<bdstType[]>();
|
|
const [rainBdstForm, setRainBdstForm] = useState<bdstType[] | undefined>();
|
|
const { bdstObj, rainRuseObj } = rain;
|
|
const [selectSgg, setSelectSgg] = useState<selectArray[] | undefined>()
|
|
const [searchTxt, setSearchTxt] = useState<string>()
|
|
|
|
const getCity = (val: string ) => {
|
|
|
|
|
|
const data = code.sggCd
|
|
.filter((item) => String(item.val).substring(0, 2) === val)
|
|
.map((item) => ({ ...item, val: String(item.val) })); // Ensure 'val' is a string
|
|
setSelectSgg(data);
|
|
};
|
|
|
|
const getSgg = (val: string | number) => {
|
|
console.log(val);
|
|
};
|
|
|
|
|
|
|
|
useEffect(()=>{
|
|
|
|
// console.log("searchTxt ", searchTxt)
|
|
findBdst(searchTxt)
|
|
},[searchTxt])
|
|
|
|
useEffect(() => {
|
|
if (code.sggCd.length > 0) {
|
|
const table = bdst?.bdstBase?.map((item) => {
|
|
const sggText = code.sggCd.find(
|
|
(cd) => cd.val === Number(item.sggCd)
|
|
)?.text;
|
|
const cityText = code.cityCd.find(
|
|
(cd) => cd.val === Number(item.ctpvCd)
|
|
)?.text;
|
|
return { ...item, sggText: sggText, cityText: cityText };
|
|
});
|
|
|
|
|
|
setbdstTable(table);
|
|
}
|
|
}, [code, bdst]);
|
|
|
|
const tableClick: (val: number | undefined) => void = (val) => {
|
|
|
|
console.log("val , " ,val)
|
|
console.log("bdst , " ,bdst?.bdstBase[val])
|
|
if(val!==undefined && bdst?.bdstBase.length>0){
|
|
const data =bdst?.bdstBase[val]
|
|
console.log("data ", [data])
|
|
setRainBdstForm([data]);
|
|
}
|
|
}
|
|
|
|
const nodeList = headMakeColSpan(bdst.moUpHeadList);
|
|
return (
|
|
<>
|
|
<div className="grid grid-cols-12 gap-4">
|
|
<SelectBox
|
|
className="col-span-3 col-start-4"
|
|
label={"시도"}
|
|
selectClass={selectClass}
|
|
selectArray={code.cityCd}
|
|
onSelectValue={getCity}
|
|
>
|
|
{" "}
|
|
</SelectBox>
|
|
<SelectBox
|
|
className="col-span-3"
|
|
label={"시군구"}
|
|
selectClass={selectClass}
|
|
selectArray={selectSgg || []}
|
|
onSelectValue={getSgg}
|
|
>
|
|
{" "}
|
|
</SelectBox>
|
|
<SearchInput
|
|
className="col-span-3 col-start-10"
|
|
label="건물명"
|
|
textValue={searchTxt}
|
|
setText={ setSearchTxt}
|
|
|
|
/>
|
|
</div>
|
|
<div className="border-t border-gray-300 my-4"></div>
|
|
<div className="h-auto">
|
|
<div>
|
|
<UiTable
|
|
tableData={bdstTable || []}
|
|
headlist={bdst.moUpHeadList}
|
|
pageSize={-10}
|
|
total={-1}
|
|
headName={undefined}
|
|
cellClick={tableClick}
|
|
>
|
|
{nodeList}
|
|
</UiTable>
|
|
</div>
|
|
<div className="border-t border-gray-300 my-4"></div>
|
|
<ScrollArea className="h-[60vh]">
|
|
<div>
|
|
<RainRegForm data={rainBdstForm || []} isModal={true}></RainRegForm>
|
|
</div>
|
|
</ScrollArea>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|