Files
frontend/apps/sn/app/(map-layout)/map/components/popupComponent/chart/rdiiChart.tsx
T
2025-07-01 11:44:52 +09:00

253 lines
9.7 KiB
TypeScript

'use client'
import { CHART_FORM, type ChartConfig, MainChart, UiModal } from "@common/business_components";
import { SelectBox } from '@common/business_components/ui';
import { Button, Input, Label } from '@common/components';
import React, { useEffect, useState } from 'react';
import type { TRdiiAnls, TRdiiAnlsRslt, TOilqData } from './aplcnYms';
import { getChartDataRdiiAnlsRslt, selectRdiiAnlsRslt } from './aplcnYms';
import { getOptionsRdiiAnlsInfo, selectRdiiAnls, useAplcnYms } from './aplcnYms';
type ModalOpenProp = {
isModalOpen: boolean,
setIsModalOpen: (open: boolean) => void,
closeModal: () => void,
btnTxt?: string,
pplMngNo?: string, // 관로관리번호
}
const RdiiChart = ({ btnTxt, isModalOpen, setIsModalOpen, closeModal, pplMngNo }: ModalOpenProp) => {
const [popupOpen, setPopupOpen] = React.useState(true);
const buttonRef = React.useRef<HTMLButtonElement>(null); // 버튼 참조
const [popupPosition, setPopupPosition] = useState<{ top: number; left: number }>({ top: 0, left: 0 }); // 팝업 위치
const [aplcnYm, setAplcnYm] = useState("");
const [rdiiAnlss, setRdiiAnlss] = useState<TRdiiAnls[]>([]);
const [rdiiAnlsInfos, setRdiiAnlsInfos] = useState<any[]>([{ val: 0, text: '선택' }]); // 강우유입수분석정보 options
const [rdiiAnls, setRdiiAnls] = useState<TRdiiAnls | null>(null); // 강우유입수분석정보
const [rainInfwtAnlsSn, setRainInfwtAnlsSn] = useState<number>(0); // 강우유입수분석 정보 선택시 사용
const [chartData, setChartData] = useState<{ chartData1: { label: string; val: number }[]; chartData2: { label: string; val: number }[] }>({
chartData1: [{ label: "1", val: 20 },
{ label: "3", val: 40 },
{ label: "5", val: 60 },],
chartData2: [{ label: "1", val: 15 },
{ label: "3", val: 35 },
{ label: "5", val: 55 },],
});
const aplcnYms = useAplcnYms('rdiiAnlsRslt'); // 상수사용월 데이터 가져오기
const openPopup = () => {
if (buttonRef.current) {
const rect = buttonRef.current.getBoundingClientRect(); // 버튼 위치 계산
setPopupPosition({
top: rect.bottom + window.scrollY, // 버튼 아래쪽
left: rect.left + window.scrollX, // 버튼 왼쪽
});
}
setPopupOpen(true); // 팝업 열기
};
//console.log("btnTxt", btnTxt);
const chartForm = CHART_FORM.LINE;
const chartConfig = {
chartData1: { label: '강우유입수예측유량', color: "red", },
chartData2: { label: '실측유량', color: "orange", }
} as ChartConfig;
useEffect(() => {
if (isModalOpen === false) {
setPopupOpen(true); // 모달이 닫힐 때 팝업은
setAplcnYm(""); // 상수사용월 초기화
setRdiiAnlss([]); // 강우유입수분석 초기화
setRdiiAnlsInfos([{ val: 0, text: '선택' }]); // 강우유입수분석정보 초기화
setRdiiAnls(null); // 강우유입수분석정보 초기화
setRainInfwtAnlsSn(0); // 강우유입수분석 일련번호 초기화
setChartData({
chartData1: [{ label: "1", val: 20 },
{ label: "3", val: 40 },
{ label: "5", val: 60 },],
chartData2: [{ label: "1", val: 15 },
{ label: "3", val: 35 },
{ label: "5", val: 55 },],
}); // 차트 데이터 초기화
}
}, [isModalOpen]);
// 상수사용월 변경시 분석 정보 리스트 가져오기
useEffect(() => {
// aplcnYm이 비어있거나 "0"이면 API 호출하지 않음
if (!aplcnYm || aplcnYm === "0" || aplcnYm === "") {
setRainInfwtAnlsSn(0); // 초기화
setRdiiAnlsInfos([]);
return;
}
selectRdiiAnls(aplcnYm)
.then((data) => {
setRdiiAnlss(data ?? []);
setRdiiAnlsInfos(getOptionsRdiiAnlsInfo(data));
setRainInfwtAnlsSn(0); // 초기화
})
.catch((error) => {
console.error("selectrdiiAnls 에러:", error);
setRdiiAnlss([]);
setRdiiAnlsInfos([]);
});
}, [aplcnYm]);
// 값 표시
useEffect(() => {
// 선택된 강우유입수분석 정보에 대한 처리 로직
if (rainInfwtAnlsSn === 0) return;
const selectedAnls = rdiiAnlss.find(anls => anls.rainInfwtAnlsSn === rainInfwtAnlsSn);
if (selectedAnls) {
setRdiiAnls(selectedAnls);
}
}, [rainInfwtAnlsSn]);
const closePopup = () => { // 팝업 닫기
selectRdiiAnlsRslt(rainInfwtAnlsSn, "L13101003").then((data) => {// 강우유입수분석 결과 조회
const rsltData = getChartDataRdiiAnlsRslt(data ?? []);
setChartData(prev => ({
...prev,
chartData1: rsltData // 강우유입수분석결과
}));
});
setPopupOpen(false);
};
const renderBody = () => (
<>
{/* 분석 입력현황 조회 */}
<div className='grid grid-cols-4 gap-4'>
<div className="grid grid-rows-4 gap-4 mb-4">
<Button className="bg-white text-white w-[130px] font-bold px-4 mt-2 py-2" onClick={openPopup}>
분석 입력현황 조회
</Button>
{/* 강우유입수량 분석결과 */}
<div className="bg-white text-red-600 font-bold px-4 py-2 ">
강우유입수량 분석결과
<div className="flex items-center mt-2">
<span className="text-black text-xl font-bold">120</span>
<span className="ml-2 text-black">m³/d</span>
</div>
</div>
</div>
{/* 차트 */}
<div className="w-[500px] h-[300px] bg-white p-4">
<MainChart chartConfig={chartConfig} chartForm={chartForm} chartData={chartData} chartTitle={'관로유량'} />
</div>
</div>
{popupOpen && (
<div
className="absolute bg-gray-100 border border-gray-300 w-[440px] shadow-lg p-6 rounded text-2xl"
style={{
top: popupPosition.top,
left: popupPosition.left,
zIndex: 1000,
}}
>
<div className="font-bold mb-6 text-3xl">강우유입수분석 입력현황</div>
<div className='flex flex-col'>
<div className='flex items-center justify-between'>
<Label className="mr-2 w-auto text-2xl text-gray-600 whitespace-nowrap">상수사용월:</Label>
<SelectBox
className="w-[220px] mr-8 z-[51] mb-2"
selectClass="rounded-lg bg-white"
label=''
selectArray={aplcnYms}
value={aplcnYm}
onSelectValue={(val) => {
setAplcnYm(String(val));
}}
/>
</div>
<div className='flex items-center justify-between'>
<Label className="mr-2 w-auto text-2xl text-gray-600 whitespace-nowrap">분석정보:</Label>
<SelectBox
className="w-[220px] mr-8 z-[51] mb-2"
selectClass="rounded-lg bg-white"
label=''
selectArray={rdiiAnlsInfos}
value={rainInfwtAnlsSn}
onSelectValue={(val) => {
setRainInfwtAnlsSn(Number(val));
}}
/>
</div>
<div className='flex items-center justify-between'>
<Label className="mr-2 w-auto text-2xl text-gray-600 whitespace-nowrap">오수전환율:</Label>
<Input
className="mr-8 w-[220px] !text-xl placeholder:text-center mb-2"
placeholder=""
value={rdiiAnls?.drtwSwtcRt ?? ""}
readOnly={true}
/>
</div>
<div className='flex items-center justify-between'>
<Label className="mr-2 w-auto text-2xl text-gray-600 whitespace-nowrap">수용가-맨홀 매칭:</Label>
<Input
className="mr-8 w-[220px] !text-xl placeholder:text-center mb-2"
placeholder=""
value={rdiiAnls?.atflMpngNm ?? ""}
readOnly={true}
/>
</div>
<div className='flex items-center justify-between'>
<Label className="mr-2 w-auto text-2xl text-gray-600 whitespace-nowrap">관망도 파일명:</Label>
<Input
className="mr-8 w-[220px] !text-xl placeholder:text-center mb-2"
placeholder=""
value={rdiiAnls?.atflInpNm ?? ""}
readOnly={true}
/>
</div>
<div className='flex items-center justify-between'>
<Label className="mr-2 w-auto text-2xl text-gray-600 whitespace-nowrap">강우 파일명:</Label>
<Input
className="mr-8 w-[220px] !text-xl placeholder:text-center mb-2"
placeholder=""
value={rdiiAnls?.atflRainNm ?? ""}
readOnly={true}
/>
</div>
<div className='flex items-center justify-between'>
<Label className="mr-2 w-auto text-2xl text-gray-600 whitespace-nowrap">RTK계수 출처:</Label>
<Input
className="mr-8 w-[220px] !text-xl placeholder:text-center mb-2"
placeholder=""
value={rdiiAnls?.srcNm ?? ""}
readOnly={true}
/>
</div>
</div>
<div className="flex justify-end mt-4 space-x-2">
<button className="px-4 py-2 bg-gray-600 text-white rounded" onClick={closePopup}>
분석결과 도표
</button>
</div>
</div>)}
{/* </Modal > */}
</>
)
return (
<UiModal
open={isModalOpen}
onOpenChange={setIsModalOpen}
bodyClass={`
h-[50vh]
w-[40vw]
max-w-none
max-h-none
overflow-visible
z-[50]
`}
body={renderBody()}
/>
)
}
export default RdiiChart