206 lines
7.6 KiB
TypeScript
206 lines
7.6 KiB
TypeScript
"use client"
|
||
import { useFoStore } from "@/app/store";
|
||
import type { TableUpperProps } from "@/app/store/common";
|
||
import { downloadExcel, MainDiv, SearchBaseForm, SearchInput, SelectBox, Title, UiTable, type ReturnType } from "@common/business_components";
|
||
import ListDiv from "@common/business_components/ui/list_div";
|
||
import { useCallback, useEffect, useRef, useState } from "react";
|
||
import LoadingOverlay from "@common/business_components/ui/loadingBar";
|
||
|
||
export default function PlanSewage() {
|
||
const {Common
|
||
,PlanSewage
|
||
,PlanSewageSearch
|
||
,initializeCommonData
|
||
,searchPlanSewageList
|
||
} = useFoStore((state) => state) || { processAreaList: { processAreaList: [] }};
|
||
|
||
const {
|
||
isInit,
|
||
selectUpdownData,
|
||
selectOperationData,
|
||
selectSidoData,
|
||
selectSigunData,
|
||
selectRegionData,
|
||
selectUnitWaterShedData,
|
||
selectMiddleRegionData,
|
||
selectEnvPartData,
|
||
selectSearchYear,
|
||
btnClass
|
||
} = Common;
|
||
|
||
const {
|
||
labelArray,
|
||
} = PlanSewageSearch;
|
||
|
||
const {
|
||
upHeadList1,
|
||
upHeadList2,
|
||
upHeadList3,
|
||
planSewageList,
|
||
planSewageCount,
|
||
excelList,
|
||
isLoading,
|
||
} = PlanSewage;
|
||
|
||
const ref = useRef<ReturnType>({
|
||
partValue: '',
|
||
sidoValue: '',
|
||
sigunValue: '',
|
||
regionValue: '',
|
||
unitWaterShedValue: '',
|
||
middleRegionValue: '',
|
||
envPartValue: '',
|
||
sidoText: '',
|
||
sigunText: ''
|
||
});
|
||
|
||
// 그리드 관련
|
||
const searchInputRef = useRef<HTMLDivElement & HTMLInputElement>(null);
|
||
|
||
// 모달 상태 추가
|
||
|
||
// 초기화 변수
|
||
const [resetPage, setResetPage] = useState<boolean>(false);
|
||
// 표 너비
|
||
const [widthSize, setWidthSize] = useState<string>("w-[120%]");
|
||
// 구분별 그리드 헤더
|
||
const [upheadList, setUpheadList] = useState<TableUpperProps[]>(upHeadList1);
|
||
// 용량별
|
||
const [fcltCpct, setFcltCpct] = useState<string>("0");
|
||
// 시설명
|
||
const [fcltyName, setFcltyName] = useState<string>("");
|
||
// 시설상태
|
||
const [operationValue, setOperationValue] = useState<string>("0");
|
||
// 조회기간
|
||
const [searchYear, setSearchYear] = useState<string>(selectSearchYear[0]?.val || "0");
|
||
|
||
/**
|
||
* 페이지 함수
|
||
*/
|
||
// 초기화
|
||
const resetVal = () => {
|
||
setWidthSize("w-[120%]");
|
||
setUpheadList(upHeadList1);
|
||
// 상태값 설정
|
||
setFcltCpct(selectUpdownData[0]?.val || "0");
|
||
setOperationValue(selectOperationData[0]?.val || "0");
|
||
setSearchYear(selectSearchYear[0]?.val || "0");
|
||
// SearchInputSelect 초기화
|
||
setFcltyName("");
|
||
if (searchInputRef.current) {
|
||
const input = searchInputRef.current.querySelector('input');
|
||
if (input) {
|
||
input.value = "";
|
||
}
|
||
}
|
||
searchPlanSewageList(1, 10, selectSearchYear[0]?.val || "0", ref.current.partValue);
|
||
}
|
||
|
||
/**
|
||
* useEffect
|
||
*/
|
||
useEffect(() => {
|
||
if (!isInit) {
|
||
initializeCommonData();
|
||
searchPlanSewageList(1, 10, selectSearchYear[0]?.val || "0", ref.current.partValue);
|
||
}
|
||
}, [isInit, initializeCommonData, searchPlanSewageList]);
|
||
|
||
useEffect(() => {
|
||
console.log('excelList' , excelList);
|
||
if (excelList && excelList.length > 0) {
|
||
downloadExcel({
|
||
data: excelList as unknown as JSON[],
|
||
fileName: '계획하수량 산정지표 현황',
|
||
sheetNameArray: ['계획하수량 산정지표 현황'],
|
||
headerRange: 'A1:M1'
|
||
});
|
||
}
|
||
}, [excelList]);
|
||
|
||
/**
|
||
* 콜백함수
|
||
*/
|
||
// 조회
|
||
const searchPlanSewage = useCallback(({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => {
|
||
let nameCd, partStr
|
||
switch (partValue) {
|
||
case 'R':
|
||
if (regionValue !== '0') {
|
||
if(unitWaterShedValue==='0') nameCd = regionValue;
|
||
else if (middleRegionValue==='0') nameCd = unitWaterShedValue;
|
||
else nameCd = middleRegionValue;
|
||
}
|
||
partStr = partValue
|
||
break;
|
||
default:
|
||
if(sidoValue !== '0') nameCd = sidoValue;
|
||
if(sigunValue !== '0') nameCd = sigunValue;
|
||
partStr = envPartValue !== '0' ? envPartValue:partValue;
|
||
break;
|
||
}
|
||
if (partStr.length > 1 || fcltCpct !== '0' || operationValue!== '0' ||nameCd ||(fcltyName.trim() !== "" && fcltyName.trim() !== null)) {
|
||
searchPlanSewageList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined);
|
||
} else {
|
||
searchPlanSewageList(pageNo, pageCnt, searchYear, partValue);
|
||
}
|
||
}, [operationValue, fcltyName, searchPlanSewageList, searchYear, fcltCpct]);
|
||
|
||
const chkVal = useCallback((returntype:ReturnType) => {
|
||
setWidthSize(returntype.partValue=='A' ?"w-[120%]":"w-[130%]")
|
||
setUpheadList(returntype.partValue == 'R' ? upHeadList2 : returntype.partValue == 'G'?upHeadList3:upHeadList1);
|
||
setResetPage(true);
|
||
}, [upHeadList1, upHeadList2, upHeadList3]);
|
||
|
||
// 엑셀다운로드
|
||
const excelDownload = useCallback((searchReturn: ReturnType) => {
|
||
searchPlanSewage(searchReturn, 1, 10000);
|
||
}, [searchPlanSewage]);
|
||
|
||
// 페이지 변경
|
||
const handlePageChange = useCallback((page: number) => {
|
||
setResetPage(false);
|
||
searchPlanSewage(ref.current, page, 10);
|
||
}, [searchPlanSewage]);
|
||
|
||
const mainList = planSewageList || [];
|
||
const total = planSewageCount || 0;
|
||
|
||
return (
|
||
<MainDiv>
|
||
<Title title="계획하수량 산정지표 현황" />
|
||
<SearchBaseForm
|
||
leftChildren={<>
|
||
<SelectBox className="col-span-3" label={labelArray[3] as string} selectArray={selectUpdownData} onSelectValue={(val) => setFcltCpct(val.toString())} value={fcltCpct} selectClass={undefined} />
|
||
<SearchInput className={"col-span-3"} label={labelArray[4] as string} textValue={fcltyName} setText={setFcltyName} />
|
||
<SelectBox className="col-span-3" label={labelArray[5] as string} selectArray={selectSearchYear} onSelectValue={(val) => setSearchYear(val.toString())} value={searchYear} selectClass={undefined} />
|
||
<SelectBox className="col-span-3" label={labelArray[6] as string} selectArray={selectOperationData} onSelectValue={(val) => setOperationValue(val.toString())} value={operationValue} selectClass={undefined} />
|
||
</>}
|
||
rightChildren={undefined}
|
||
selectSidoData={selectSidoData}
|
||
selectSigunData={selectSigunData}
|
||
selectRegionData={selectRegionData}
|
||
selectUnitWaterShedData={selectUnitWaterShedData}
|
||
selectMiddleRegionData={selectMiddleRegionData}
|
||
selectEnvPartData={selectEnvPartData}
|
||
btnClass={btnClass}
|
||
queryClick={chkVal}
|
||
excelClick={excelDownload}
|
||
initClick={resetVal}
|
||
ref={ref} isAdmin={false}/>
|
||
<ListDiv>
|
||
<LoadingOverlay isLoading={isLoading} />
|
||
<div className="h-full w-full overflow-x-scroll">
|
||
<div className={widthSize}>
|
||
<UiTable cellClick={ undefined } headName={"계획하수량 산정지표 현황"} tableData={mainList} headlist={upheadList} pageSize={10} total={total} resetPageNo={resetPage} onPageChange={handlePageChange} />
|
||
</div>
|
||
<div className="mt-14">
|
||
<span className="text-2xl font-bold text-gray-500">☞ 여유용량 = 하수처리시설 시설용량 – 건기시 유입유량(평균)</span><br/>
|
||
<span className="text-2xl font-bold text-gray-500">☞ 변동부하율 = 건기시 일최대 유량/일평균유량(기준 최근 3개년)</span><br/>
|
||
<span className="text-2xl font-bold text-gray-500">☞ 분류식화율 = 분류식지역 면적(㎢) / 처리구역 면적합계(㎢) ×100</span><br/>
|
||
</div>
|
||
</div>
|
||
</ListDiv>
|
||
</MainDiv>
|
||
);
|
||
} |