182 lines
5.9 KiB
TypeScript
182 lines
5.9 KiB
TypeScript
import { useWrStore } from "@/app/store";
|
|
import { rainMapSize } from "@/app/store/map/rainMap";
|
|
import type { customHtdflBdst } from "@/app/store/ruseFcltMng/fcltReg/htdflReg";
|
|
import { getCity, tableData } from "@/components/lib/func/commom";
|
|
import type { objSearchType } from "@/components/ui/modal/fcltReg/bdstRegModal/bdstRegModal";
|
|
import {
|
|
ContentsDiv,
|
|
SearchDiv,
|
|
SearchFormLeft,
|
|
SearchFormRight,
|
|
SearchInput,
|
|
SelectBox,
|
|
Title,
|
|
UiTable,
|
|
type SelectDataType,
|
|
} from "@common/business_components/ui";
|
|
import { HeadMakeColSpan } from "@common/business_components/ui/table/HeadMakeColSpan";
|
|
import { Button } from "@common/components/ui";
|
|
import { useCallback, useEffect, useState } from "react";
|
|
|
|
export function HtdflFacility({
|
|
rtnFeature,
|
|
}: {
|
|
rtnFeature: (feature: any) => void;
|
|
}) {
|
|
const { code, htdfMap, htdfMapInit,htdfMapSearch } = useWrStore((state) => state);
|
|
const { htdfMapCount, htdfMapRes, htdfSttHeadList, htdfSttNodeList } =
|
|
htdfMap;
|
|
const [htdflTable, setHtdflTable] = useState<customHtdflBdst[]>();
|
|
const [isReset, setIsReset] = useState(false);
|
|
const [selectSgg, setSelectSgg] = useState<SelectDataType[] | []>();
|
|
const [objSearch, setObjSearch] = useState<objSearchType>({
|
|
sgg: "",
|
|
city: "",
|
|
});
|
|
|
|
const [seartchTxt, setSearchTxt] = useState<string>();
|
|
|
|
const getSelCity = useCallback(
|
|
(val: string | number) => {
|
|
const cityValue = String(val);
|
|
const data = getCity(cityValue, code.sggCd);
|
|
setSelectSgg(data);
|
|
setObjSearch({ city: cityValue, sgg: "0" });
|
|
},
|
|
[code.sggCd]
|
|
);
|
|
|
|
const getSgg = useCallback((val: string | number) => {
|
|
setObjSearch((prev) => ({ ...prev, sgg: String(val) }));
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
// code.cityCd 데이터가 로드되었고, 아직 시/도 선택이 안된 초기 상태일 때 실행
|
|
if (code.cityCd && code.cityCd.length > 0 && !objSearch.city) {
|
|
const firstCityVal = code.cityCd[0]?.val;
|
|
if (firstCityVal) {
|
|
// 첫 번째 시/도 값으로 상태를 초기화합니다.
|
|
getSelCity(firstCityVal);
|
|
}
|
|
}
|
|
}, [code.cityCd, objSearch.city, getSelCity]);
|
|
|
|
const htdflCellClick = (index: number | undefined) => {
|
|
if (index !== undefined && htdflTable !== undefined) {
|
|
rtnFeature(htdflTable[index]);
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (!htdfMap.isInit) {
|
|
htdfMapInit(1, rainMapSize, "0");
|
|
}
|
|
}, [htdfMap.isInit, htdfMapInit]);
|
|
|
|
useEffect(() => {
|
|
const data = tableData(htdfMapRes, { code });
|
|
const chData = data
|
|
.map((item: any) => ({
|
|
...item,
|
|
...item.reuseBuilding[0],
|
|
...item.reuseBuilding[0].htdflObj,
|
|
chBuildingYn: item.chgBuilding[0]?.bdstChgNm !== null ? "Y" : "N",
|
|
}))
|
|
.filter((item: any) => item.htdflObj !== undefined);
|
|
setHtdflTable(chData);
|
|
}, [code, htdfMapRes]);
|
|
|
|
return (
|
|
<>
|
|
<ContentsDiv>
|
|
<div className="grid grid-cols-4 gap-4 ">
|
|
<div className="col-span-4">
|
|
<Title title="온배수시설 현황" />
|
|
<SearchDiv>
|
|
<SearchFormLeft>
|
|
<div className="col-span-10 flex flex-row">
|
|
<SelectBox
|
|
className="col-span-3 w-1/6 h-full text-2xl"
|
|
label="시도"
|
|
selectClass={""}
|
|
selectArray={code.cityCd || []}
|
|
onSelectValue={(val) => {
|
|
getSelCity(val);
|
|
}}
|
|
value={objSearch.city}
|
|
/>
|
|
<SelectBox
|
|
className="col-span-3 w-1/6 h-full text-2xl ml-4"
|
|
label="시군구"
|
|
selectClass={""}
|
|
selectArray={selectSgg || []}
|
|
onSelectValue={getSgg}
|
|
value={objSearch.sgg}
|
|
/>
|
|
<SearchInput
|
|
className={"!text-3xl ml-4"}
|
|
label="회사명"
|
|
textValue={seartchTxt ?? ""}
|
|
setText={(e) => {
|
|
setSearchTxt(e);
|
|
}}
|
|
/>
|
|
</div>
|
|
</SearchFormLeft>
|
|
<SearchFormRight className="w-3/12 mx-5 flex flex-col items-center justify-center space-x-2 ">
|
|
<div className="flex flex-row space-x-2">
|
|
<Button
|
|
className="mt-2"
|
|
size={"sm"}
|
|
onClick={() => {
|
|
setIsReset(true);
|
|
}}
|
|
>
|
|
조회
|
|
</Button>
|
|
</div>
|
|
</SearchFormRight>
|
|
</SearchDiv>
|
|
</div>
|
|
</div>
|
|
<div className="grid grid-cols-2 gap-4 ">
|
|
<div className="col-span-2">
|
|
<UiTable
|
|
headName={[]}
|
|
tableData={htdflTable || []}
|
|
headlist={htdfSttHeadList}
|
|
pageSize={rainMapSize}
|
|
total={htdfMapCount}
|
|
cellClick={(index: number | undefined) => {
|
|
htdflCellClick(index ?? undefined);
|
|
}}
|
|
onPageChange={(page) => {
|
|
const con =
|
|
objSearch.sgg && objSearch.sgg !== "0"
|
|
? objSearch.sgg
|
|
: objSearch.city;
|
|
if (con) {
|
|
if (seartchTxt && seartchTxt?.length > 0) {
|
|
htdfMapSearch(
|
|
page,
|
|
rainMapSize,
|
|
String(con),
|
|
seartchTxt ?? ""
|
|
);
|
|
} else {
|
|
htdfMapSearch(page, rainMapSize, String(con));
|
|
}
|
|
setIsReset(false);
|
|
}
|
|
}}
|
|
resetPageNo={isReset}
|
|
>
|
|
<HeadMakeColSpan upHeadList={htdfSttNodeList} />
|
|
</UiTable>
|
|
</div>
|
|
</div>
|
|
</ContentsDiv>
|
|
</>
|
|
);
|
|
}
|