253 lines
7.8 KiB
TypeScript
253 lines
7.8 KiB
TypeScript
import { useWrStore } from "@/app/store";
|
|
import { htdfMapSize } from "@/app/store/map/htdflMap";
|
|
import { rainMapSize } from "@/app/store/map/rainMap";
|
|
import type { customHtdflBdst } from "@/app/store/ruseFcltMng/fcltReg/htdflReg";
|
|
import {
|
|
excelDownload,
|
|
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";
|
|
import toast from "react-hot-toast";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
export function HtdflFacility({
|
|
rtnFeature,
|
|
}: {
|
|
rtnFeature: (feature: any) => void;
|
|
}) {
|
|
const { code, htdfMap, htdfMapInit, htdfMapSearch } = useWrStore(
|
|
(state) => state
|
|
);
|
|
const { t } = useTranslation("base");
|
|
|
|
const {
|
|
htdfMapCount,
|
|
htdflMapExcelList,
|
|
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]);
|
|
|
|
useEffect(() => {
|
|
if (htdflMapExcelList.length > 0) {
|
|
excelDownload(
|
|
htdflMapExcelList,
|
|
"온배수시설 현황",
|
|
"sample_htdflSttn.xlsx",
|
|
"A1:R3"
|
|
);
|
|
} else {
|
|
toast.error(t("excelDownErrMsg"));
|
|
}
|
|
}, [htdflMapExcelList]);
|
|
|
|
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);
|
|
}}
|
|
/>{" "}
|
|
<Button
|
|
className="mt-2 mx-4"
|
|
size={"sm"}
|
|
onClick={() => {
|
|
setIsReset(true);
|
|
}}
|
|
>
|
|
조회
|
|
</Button>
|
|
<Button
|
|
className="mt-2"
|
|
size={"sm"}
|
|
color="green"
|
|
onClick={() => {
|
|
const con =
|
|
objSearch.sgg && objSearch.sgg !== "0"
|
|
? objSearch.sgg
|
|
: objSearch.city;
|
|
if (con) {
|
|
htdfMapSearch(
|
|
true,
|
|
1,
|
|
"1000000",
|
|
String(con),
|
|
seartchTxt||'',
|
|
code.cityCd,
|
|
code.sggCd
|
|
);
|
|
}
|
|
}}
|
|
>
|
|
엑셀다운로드
|
|
</Button>
|
|
</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>
|
|
<Button
|
|
className="mt-2"
|
|
size={"sm"}
|
|
color="green"
|
|
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) {
|
|
htdfMapSearch(
|
|
false,
|
|
page,
|
|
String(htdfMapSize),
|
|
String(con),
|
|
seartchTxt||'',
|
|
code.cityCd,
|
|
code.sggCd
|
|
);
|
|
setIsReset(false);
|
|
}
|
|
}}
|
|
resetPageNo={isReset}
|
|
>
|
|
<HeadMakeColSpan upHeadList={htdfSttNodeList} />
|
|
</UiTable>
|
|
</div>
|
|
</div>
|
|
</ContentsDiv>
|
|
</>
|
|
);
|
|
}
|