146 lines
4.6 KiB
TypeScript
146 lines
4.6 KiB
TypeScript
"use client";
|
|
import { useDmStore } from "@/app/store";
|
|
import {
|
|
SearchDiv,
|
|
SearchFormLeft,
|
|
SearchFormRight,
|
|
SelectBox,
|
|
type SelectDataType,
|
|
} from "@common/business_components/ui";
|
|
import { Button, Label } from "@common/components/ui";
|
|
import { useCallback, useEffect, useState } from "react";
|
|
import SearchInputText from "../SearchInputText/SearchInputText";
|
|
|
|
export function SearchBar({
|
|
setHasuPk,
|
|
onApply
|
|
}: {
|
|
setHasuPk: (hasuPk: string) => void;
|
|
onApply: () => void;
|
|
}) {
|
|
const { map, Common, initializeCommonData, findRuseFclt } = useDmStore(
|
|
(state) => state
|
|
);
|
|
const [sidoValue, setSidoValue] = useState<string>("");
|
|
const [sigunValue, setSigunValue] = useState<string>("");
|
|
const [filteredSigunData, setFilteredSigunData] = useState<SelectDataType[]>([
|
|
{ text: "전체", val: "0" },
|
|
]);
|
|
useEffect(() => {
|
|
initializeCommonData();
|
|
}, [initializeCommonData]);
|
|
|
|
const initializeSigunData = useCallback(
|
|
(sidoCd: string) => {
|
|
if (sidoCd === "0") {
|
|
setSigunValue("0");
|
|
setFilteredSigunData([{ text: "전체", val: "0" }]);
|
|
} else {
|
|
const newFilteredData = [
|
|
{ text: "전체", val: "0" },
|
|
...Common.selectSigunData.filter(
|
|
(item: SelectDataType) => item.val.substring(0, 2) === sidoCd
|
|
),
|
|
];
|
|
setSigunValue("0");
|
|
setFilteredSigunData(newFilteredData);
|
|
}
|
|
},
|
|
[Common.selectSigunData]
|
|
);
|
|
const onSelectValue = useCallback(
|
|
(val: string, type: string) => {
|
|
switch (type) {
|
|
case "ctpvCd":
|
|
initializeSigunData(val);
|
|
setSidoValue(val);
|
|
break;
|
|
case "sggCd":
|
|
setSigunValue(val);
|
|
}
|
|
},
|
|
[initializeSigunData]
|
|
);
|
|
|
|
useEffect(() => {
|
|
console.log("map.ruseFcltList ", map.ruseFcltList);
|
|
}, [map.ruseFcltList]);
|
|
|
|
return (
|
|
<>
|
|
<div className="grid grid-cols-4 gap-4 ">
|
|
<div className="col-span-4">
|
|
<SearchDiv>
|
|
<SearchFormLeft>
|
|
<div className="col-span-10 flex flex-row">
|
|
<SelectBox
|
|
className="col-span-2 w-1/6 h-full text-2xl"
|
|
label="시도"
|
|
selectClass={""}
|
|
selectArray={Common.selectSidoData || []}
|
|
onSelectValue={(val) =>
|
|
onSelectValue(val.toString(), "ctpvCd")
|
|
}
|
|
value={sidoValue || Common.selectSidoData[0]?.val || ""}
|
|
/>
|
|
<SelectBox
|
|
className="col-span-2 w-1/6 h-full text-2xl ml-10"
|
|
label="시군구"
|
|
selectClass={""}
|
|
selectArray={filteredSigunData || []}
|
|
onSelectValue={(val) =>
|
|
onSelectValue(val.toString(), "sggCd")
|
|
}
|
|
value={sigunValue}
|
|
/>
|
|
<div className="col-span-6 flex flex-row items-center min-w-[27rem] ml-10">
|
|
<Label className="text-xl justify-self-center mt-2 mx-3">
|
|
하수재이용시설
|
|
</Label>
|
|
<SearchInputText
|
|
label={"시설명"}
|
|
initValue={undefined}
|
|
setValue={(searchNm?: string) => {
|
|
let sggOrCity = "";
|
|
if (searchNm) {
|
|
if (sigunValue === "0" || sigunValue === "") {
|
|
sggOrCity = sidoValue;
|
|
} else {
|
|
sggOrCity = sigunValue;
|
|
}
|
|
findRuseFclt(sggOrCity, searchNm);
|
|
}
|
|
}}
|
|
setRtnData={(rtnData: any) => {
|
|
setHasuPk(rtnData.bscFctCd || "");
|
|
}}
|
|
searchList={map.ruseFcltList || []}
|
|
/>
|
|
</div>
|
|
<div className="flex flex-row space-x-2">
|
|
<Button
|
|
color="red"
|
|
className="mx-2 mt-2"
|
|
size={"sm"}
|
|
onClick={() => {}}
|
|
>
|
|
후보지선택
|
|
</Button>
|
|
<Button
|
|
color="sky"
|
|
className="mt-2"
|
|
size={"sm"}
|
|
onClick={() => {onApply();}}
|
|
>
|
|
적용
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</SearchFormLeft>
|
|
</SearchDiv>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|