152 lines
7.1 KiB
TypeScript
152 lines
7.1 KiB
TypeScript
import { useRef, useState } from "react";
|
|
import { useAlertStore } from "@/shared/lib";
|
|
import { LoadingWithAnimation, Tabs, TabsContent, TabsList, TabsTrigger } from "@common/components";
|
|
import SearchForm from "@/components/module/SearchForm";
|
|
import DataGrid from "@/components/module/DataGrid";
|
|
import type { SearchFormValues } from "@/components/type/SearchForm.type";
|
|
import { toGridRows } from "@/components/util/grid/gridFunction";
|
|
import CellColorInfo from "./CellColorInfo";
|
|
|
|
// 13. 하수도서비스수준 컬럼 설정
|
|
import { SewageComplaintTab1ColumnConfig } from "@/components/util/column/total/sewerageServiceLevel/ComplaintTotColumn";
|
|
import { ResidentFriendlyFacilityTab2ColumnConfig } from "@/components/util/column/total/sewerageServiceLevel/ResidentFriendlyFactTotColumn";
|
|
|
|
import { statisticsTotalStatusApi } from "@/entities/statistics/api/statistics-total-service";
|
|
import type {
|
|
SewerageServiceLevelRequest,
|
|
SewerageServiceLevelComplaintResponse,
|
|
SewerageServiceLevelResidentFriendlyFactResponse
|
|
} from "@/entities/statistics/model/statistics-total/statistics-service-level-total-interface";
|
|
|
|
const SewageServiceLevelColumnListTot = [
|
|
SewageComplaintTab1ColumnConfig,
|
|
ResidentFriendlyFacilityTab2ColumnConfig
|
|
].filter(Boolean);
|
|
|
|
const firstTabKey = SewageServiceLevelColumnListTot[0]?.tabKey ?? "ST00130001";
|
|
|
|
const SewerageServiceLevelTot = () => {
|
|
const { setMessage: alert } = useAlertStore((state) => state);
|
|
|
|
const [rowDataMap, setRowDataMap] = useState<Map<string, Record<string, string | number>[]>>(new Map());
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [activeTab, setActiveTab] = useState(firstTabKey);
|
|
const lastSearchedValuesRef = useRef<SearchFormValues | null>(null);
|
|
|
|
const handleReset = () => {
|
|
setRowDataMap(new Map());
|
|
setActiveTab(firstTabKey);
|
|
lastSearchedValuesRef.current = null;
|
|
};
|
|
|
|
const loadGridData = async (tabKey: string, values: SearchFormValues): Promise<boolean> => {
|
|
setIsLoading(true);
|
|
const param: SewerageServiceLevelRequest = {
|
|
ctpvNm: values.sido === "ALL" ? "" : values.sido,
|
|
sggNm: values.gugun === "ALL" ? "" : values.gugun,
|
|
sewerBzmnCd: values.bsnmCd,
|
|
statsYr: values.year,
|
|
rowDataYn: values.isDetail,
|
|
summaryYn: values.isSummary !== 'ALL',
|
|
summaryYearCnt: values.isSummary !== 'ALL' ? Number(values.isSummary) : undefined
|
|
};
|
|
|
|
try {
|
|
// [TAB1] 민원
|
|
if (tabKey === "ST00130001") {
|
|
const response: SewerageServiceLevelComplaintResponse = await statisticsTotalStatusApi.getSewerageServiceLevelComplaint(param);
|
|
if (response?.status === "success") {
|
|
setRowDataMap((prev) => new Map(prev).set(tabKey, toGridRows(response.data as object[])));
|
|
return true;
|
|
}
|
|
}
|
|
// [TAB2] 주민친화시설
|
|
else if (tabKey === "ST00130002") {
|
|
const response: SewerageServiceLevelResidentFriendlyFactResponse = await statisticsTotalStatusApi.getSewerageServiceLevelResidentFriendlyFact(param);
|
|
if (response?.status === "success") {
|
|
setRowDataMap((prev) => new Map(prev).set(tabKey, toGridRows(response.data as object[])));
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
} catch {
|
|
alert("서버 연결 중 오류가 발생했습니다.");
|
|
return false;
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
const handleSearch = async (values: SearchFormValues) => {
|
|
lastSearchedValuesRef.current = values;
|
|
await loadGridData(activeTab, values);
|
|
};
|
|
|
|
const handleActiveTabChange = async (tabKey: string) => {
|
|
setActiveTab(tabKey);
|
|
const values = lastSearchedValuesRef.current;
|
|
if (!values || rowDataMap.has(tabKey)) return;
|
|
await loadGridData(tabKey, values);
|
|
};
|
|
|
|
return (
|
|
<div className="relative">
|
|
<SearchForm isDetail={true} isSummary={true} onSubmit={handleSearch} onReset={handleReset} sidoSelectText="전체" defaultRegionAll />
|
|
|
|
{isLoading && (
|
|
<div className="absolute inset-0 z-50 [data-theme='black']:bg-transparent rounded-lg p-10 flex justify-center items-center">
|
|
<div className="relative size-[5rem]">
|
|
<LoadingWithAnimation color="primary" />
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<CellColorInfo />
|
|
|
|
<div className="flex flex-col gap-[0.6rem] mx-[0.6rem]">
|
|
<Tabs value={activeTab} onValueChange={(v) => void handleActiveTabChange(v)} className="w-full" variant="default">
|
|
<TabsList>
|
|
{SewageServiceLevelColumnListTot.map((info) => (
|
|
<TabsTrigger key={info.tabKey} value={info.tabKey}>{info.tabLabel}</TabsTrigger>
|
|
))}
|
|
</TabsList>
|
|
|
|
{SewageServiceLevelColumnListTot.map((info) => (
|
|
<TabsContent key={info.tabKey} value={info.tabKey}>
|
|
<DataGrid
|
|
columnInfo={{ columns: info.columns, columnLayout: info.columnLayout }}
|
|
rowStartNum={info.rowStartNum}
|
|
rowData={rowDataMap.get(info.tabKey) ?? []}
|
|
excelExportFileSuffix={info.tabLabel}
|
|
setRowData={(updater) => {
|
|
setRowDataMap((prev) => {
|
|
const next = new Map(prev);
|
|
const cur = next.get(info.tabKey) ?? [];
|
|
const n = typeof updater === "function" ? updater(cur) : updater;
|
|
next.set(info.tabKey, n);
|
|
return next;
|
|
});
|
|
}}
|
|
isExcelImport={false}
|
|
isExcelExport={true}
|
|
excelExportApplyStyles
|
|
showHeaderCheckbox={false}
|
|
fixedColumns={info.fixedColumns}
|
|
enableSort={false}
|
|
cellStyleCallback={({ row }) => {
|
|
const rowType = String(row.rowType ?? '');
|
|
if (rowType === 'DETAIL') return undefined;
|
|
if (rowType === 'BIZ_SUM') return 'rg-cell-rowtype-biz-sum';
|
|
if (rowType === 'SUMMARY') return 'rg-cell-rowtype-summary';
|
|
return 'rg-cell-rowtype-other';
|
|
}}
|
|
/>
|
|
</TabsContent>
|
|
))}
|
|
</Tabs>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default SewerageServiceLevelTot; |