195 lines
6.6 KiB
TypeScript
195 lines
6.6 KiB
TypeScript
import { useWrStore } from "@/app/store";
|
|
import { rainMapSize } from "@/app/store/map/rainMap";
|
|
import type { customRswtBdst } from "@/app/store/ruseFcltMng/fcltReg/rswtReg";
|
|
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 RswtFacility({
|
|
rtnFeature,
|
|
}: {
|
|
rtnFeature: (feature: any) => void;
|
|
}) {
|
|
const { code, rswtMap, rswtMapInit,rswtMapSearch } = useWrStore((state) => state);
|
|
const { rswtMapRes, rswtMapCount, rswtSttHeadList, rswtSttNodeList } =
|
|
rswtMap;
|
|
const [rswtrTable, setRswtrTable] = useState<customRswtBdst[]>();
|
|
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 rswtCellClick = (index: number | undefined, headId: string) => {
|
|
if (
|
|
headId !== "chBuildingYn" &&
|
|
index !== undefined &&
|
|
rswtrTable !== undefined
|
|
) {
|
|
rtnFeature(rswtrTable[index]);
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (!rswtMap.isInit) {
|
|
rswtMapInit(1, rainMapSize, "0");
|
|
}
|
|
}, [rswtMapInit, rswtMap.isInit]);
|
|
|
|
useEffect(() => {
|
|
const data = tableData(rswtMapRes, { code });
|
|
const chData = data
|
|
.map((item: customRswtBdst) => {
|
|
return {
|
|
...item,
|
|
...item.reuseBuilding[0],
|
|
...item.reuseBuilding[0]?.rswtrObj,
|
|
chBuildingYn:
|
|
item?.chgBuilding[0]?.bdstChgNm !== null &&
|
|
item?.chgBuilding.length > 0
|
|
? "Y"
|
|
: "N",
|
|
instlCst:
|
|
item.reuseBuilding[0]?.instlCst === -1
|
|
? "확인불가"
|
|
: item.reuseBuilding[0]?.instlCst,
|
|
instlCstSprtAmt:
|
|
item.reuseBuilding[0]?.instlCstSprtAmt === -1
|
|
? "확인불가"
|
|
: item.reuseBuilding[0]?.instlCstSprtAmt,
|
|
archArea:
|
|
item?.archArea.split(".")[0] !== "-1"
|
|
? item?.archArea.split(".")[0]
|
|
: "확인불가",
|
|
};
|
|
})
|
|
.filter(
|
|
(item: customRswtBdst) => item.reuseBuilding[0]?.rswtrObj !== undefined
|
|
);
|
|
setRswtrTable(chData);
|
|
}, [code, rswtMapRes]);
|
|
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={rswtrTable || []}
|
|
headlist={rswtSttHeadList}
|
|
pageSize={20}
|
|
total={rswtMapCount}
|
|
cellClick={(index: number | undefined, headId: string) => {
|
|
rswtCellClick(index, headId);
|
|
}}
|
|
onPageChange={(page) => {
|
|
const con =
|
|
objSearch.sgg && objSearch.sgg !== "0"
|
|
? objSearch.sgg
|
|
: objSearch.city;
|
|
if (con) {
|
|
if (seartchTxt && seartchTxt?.length > 0) {
|
|
rswtMapSearch(
|
|
page,
|
|
rainMapSize,
|
|
String(con),
|
|
seartchTxt ?? ""
|
|
);
|
|
} else {
|
|
rswtMapSearch(page, rainMapSize, String(con));
|
|
}
|
|
setIsReset(false);
|
|
}}}
|
|
resetPageNo={isReset}
|
|
>
|
|
<HeadMakeColSpan upHeadList={rswtSttNodeList} />
|
|
</UiTable>
|
|
</div>
|
|
</div>
|
|
</ContentsDiv>
|
|
</>
|
|
);
|
|
}
|