Files
frontend/apps/wr/components/ui/modal/bdstReg/component.tsx
T
2025-04-01 11:25:58 +09:00

145 lines
4.1 KiB
TypeScript

"use client";
import { headMakeColSpan } from "@/app/ruseFcltMng/fcltReg/rainReg/page";
import { useWrStore } from "@/app/store";
import {
selectClass,
type bdstType,
type RainyInfoResponse,
type selectArray,
} from "@/app/store/ruseFcltMng/fcltReg/rainReg";
import { ScrollArea, SearchInput, SelectBox, UiTable } from "@common/business_components";
import { Button, Input, Label } 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;
});
type objSearchType = {
sgg: string;
city: string;
};
const [bdstTable, setbdstTable] = useState<RainyInfoResponse[]>();
const [rainBdstForm, setRainBdstForm] = useState<RainyInfoResponse | undefined>();
const { bdstObj, rainRuseObj } = rain;
const [selectSgg, setSelectSgg] = useState<selectArray[] | undefined>()
const [searchTxt, setSearchTxt] = useState<string>()
const [objSearch, setObjSearch] = useState<objSearchType>({sgg:"",city:""});
const getCity = (val: string) => {
const data = code.sggCd
.filter((item) => String(item.val).substring(0, 2) === val)
.map((item) => ({
val: String(item.val),
text: item.text // 한국어 텍스트
}));
setSelectSgg(data);
setObjSearch({ city:val , sgg:''})
};
const getSgg = (val: string | number) => {
console.log(val);
setObjSearch({...objSearch,sgg: String(val)})
};
const searchBdst=()=>{
if(objSearch.sgg===""){
alert('시도조건은 필수 입니다.')
}
}
useEffect(()=>{
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) => {
if(val!==undefined && bdst?.bdstBase.length>0){
const data =bdst?.bdstBase[val]
setRainBdstForm([data]);
}
}
const nodeList = headMakeColSpan(bdst.moUpHeadList);
return (
<>
<div className="grid grid-cols-12 gap-4 mt-4">
<SelectBox
className="col-span-3 "
label={"시도"}
selectClass={selectClass}
selectArray={code.cityCd}
onSelectValue={getCity}
>
{" "}
</SelectBox>
<SelectBox
className="col-span-3"
label={"시군구"}
selectClass={selectClass}
selectArray={selectSgg || []}
onSelectValue={getSgg}
>
{" "}
</SelectBox>
<Label className="w-20 text-base text-gray-600 mt-4 text-right">건축물명</Label>
<Input className="w-full h-full text-2xl col-span-2 col-start-8" type="text" value={searchTxt} onChange={(e) => setSearchTxt(e.target.value)}/>
{/* <SearchInput
className="col-span-3 col-start-8"
label="건물명"
textValue={searchTxt}
setText={ setSearchTxt}
/> */}
<Button className="rounded-lg" onClick={()=>{searchBdst()}}>조회</Button>
</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 rainForm={rainBdstForm ||undefined} isModal={true}></RainRegForm>
</div>
</ScrollArea>
</div>
</>
);
}