214 lines
8.1 KiB
TypeScript
214 lines
8.1 KiB
TypeScript
import React, { useEffect, useMemo } from 'react';
|
|
import LoadingOverlay from '@/components/ui/LoadingBar';
|
|
import { UiModal, UITab, UiTable } from '@common/business_components/ui';
|
|
import { Button } from '@common/components/ui';
|
|
import axios from 'axios';
|
|
import {
|
|
ExclnSewagePumpCol2, MsSwageMhlCol2, MsSwagePplCol2, stofcbrCol2, SwtrmtFcltCol2, SwtrmtPrcsZoneCol2,
|
|
MS_SWAGE_PPL_USE_CODES, MS_SWAGE_MHL_CODES, MS_SWAGE_MHL_USE_CODES,
|
|
} from '../components/common/table';
|
|
import { getData } from "@/components/lib/api";
|
|
import BasicTab, { BASIC_TYPES } from './basicTab';
|
|
import OperationTab, { operationCleaningTableHeadlist, operationInspectionTableHeadlist, operationMaintenanceTableHeadlist, operationTableHeadlist, WORK_TYPES } from './operationTab';
|
|
import ReportTab from './reportTab';
|
|
import { formatDisplayData } from '@/components/lib/utils/formatDisplayValue';
|
|
import { Toaster } from "react-hot-toast";
|
|
import { useSearchModal, OPERATION_TABLE_SIZE, type SearchModalProps } from './useSearchModal';
|
|
import useSearchModalStore from '../../../store/useSearchModalStore';
|
|
|
|
const SearchModal: React.FC<SearchModalProps> = (props) => {
|
|
const {
|
|
open, onOpenChange,
|
|
TABS,
|
|
handleSearch,
|
|
handleBasicCellClick,
|
|
handleOperationCellClick,
|
|
handleOperationResultCellClick,
|
|
basicExcelDownload,
|
|
operationExcelDownload,
|
|
operationResultExcelDownload,
|
|
viewMultipleFeature,
|
|
} = useSearchModal(props);
|
|
const {
|
|
activeTab, basicType, workType,
|
|
tableData, detailTableData,
|
|
tableCount, detailTableCount,
|
|
curPage, detailCurPage,
|
|
isLoading, isDetailLoading,
|
|
isResetPage, isResetDetailPage,
|
|
isResetSelection, isResetDetailSelection,
|
|
setActiveTab,
|
|
setCurPage, setDetailCurPage,
|
|
} = useSearchModalStore();
|
|
|
|
const dynamicHeadlist: { id: string, title: string }[] = useMemo(() => {
|
|
if (activeTab === 'basic') { // 기본정보
|
|
if (basicType === 'tb_ms_swage_ppl') return MsSwagePplCol2;// 하수관로
|
|
if (basicType === 'tb_il_swage_prcs_fclt') return SwtrmtFcltCol2;// 하수처리시설
|
|
if (basicType === 'tb_ms_swage_prcs_zone') return SwtrmtPrcsZoneCol2; // 하수처리구역
|
|
if (basicType === 'tb_ms_swage_mhl') return MsSwageMhlCol2; // 하수맨홀
|
|
if (basicType === 'tb_ms_swage_pmstn') return ExclnSewagePumpCol2; // 하수펌프장
|
|
if (basicType === 'tb_ms_stofcbr') return stofcbrCol2; // 우수토실
|
|
|
|
return [];
|
|
}
|
|
if (activeTab === 'operation') return operationTableHeadlist; // 운영정보
|
|
|
|
return [];
|
|
}, [activeTab, basicType, workType]);
|
|
|
|
const dynamicHeadlist2: { id: string, title: string }[] = useMemo(() => {
|
|
if (activeTab === 'operation') {
|
|
if (workType === WORK_TYPES[0]?.val) return operationMaintenanceTableHeadlist; // 보수 및 갱신
|
|
if (workType === WORK_TYPES[1]?.val) return operationInspectionTableHeadlist; // 점검 및 진단
|
|
if (workType === WORK_TYPES[2]?.val) return operationCleaningTableHeadlist; // 청소 및 준설
|
|
}
|
|
|
|
return [];
|
|
}, [activeTab, workType]);
|
|
|
|
|
|
const renderBody = () => (
|
|
<>
|
|
{/* 탭 영역 */}
|
|
<UITab
|
|
defaultValue={activeTab}
|
|
tabList={TABS.map((tab: any) => ({
|
|
value: tab.val,
|
|
label: tab.text
|
|
}))}
|
|
onValueChange={(value: string) => setActiveTab(value)}
|
|
/>
|
|
{/* 기본정보 탭 */}
|
|
{activeTab === 'basic' && (
|
|
<BasicTab {...props} />
|
|
)}
|
|
{/* 운영정보 탭 */}
|
|
{activeTab === 'operation' && (
|
|
<OperationTab {...props} />
|
|
)}
|
|
{/* 하수도정비기본계획보고서 탭 */}
|
|
{activeTab === 'report' && (
|
|
<ReportTab
|
|
open={open}
|
|
/>
|
|
)}
|
|
|
|
|
|
{/* 📋 결과 리스트 */}
|
|
{/* 기본정보 탭 */}
|
|
{activeTab === 'basic' && (
|
|
<div className="h-[79vh] w-full overflow-hidden rounded-lg border">
|
|
<div className="flex-1 px-2 pb-2">
|
|
<LoadingOverlay isLoading={isLoading} />
|
|
<UiTable
|
|
headName={(() => {
|
|
const label = BASIC_TYPES.find((type) => type.val === basicType)?.text
|
|
return (<>{label} 조회 결과 ({tableCount.toLocaleString('ko-KR')})건</>);
|
|
})()
|
|
}
|
|
tableData={tableData}
|
|
headlist={dynamicHeadlist}
|
|
pageSize={10}
|
|
total={tableCount}
|
|
cellClick={handleBasicCellClick}
|
|
onPageChange={setCurPage}
|
|
resetPageNo={isResetPage}
|
|
resetSelection={isResetSelection}
|
|
curPage={curPage}
|
|
headButton={
|
|
<div className='flex'>
|
|
<Button className="px-4 py-2 !mr-[1.2rem] text-white rounded-sm text-lg font-medium primary" size="sm" onClick={viewMultipleFeature}>지도에서 보기</Button>
|
|
<Button className="px-4 py-2 !mr-[1.2rem] text-white rounded-sm text-lg font-medium green" size="sm" onClick={basicExcelDownload}>파일 다운로드</Button>
|
|
</div>
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
)}
|
|
{/* 운영정보 탭 */}
|
|
{activeTab === 'operation' && (
|
|
<>
|
|
<div className="h-[39vh] w-full overflow-hidden rounded-lg border">
|
|
<div className="flex-1 px-2 pb-2">
|
|
<LoadingOverlay isLoading={isLoading} />
|
|
<UiTable
|
|
headName={
|
|
(() => {
|
|
const label = WORK_TYPES.find((type) => type.val === workType)?.text
|
|
return (<>{label} 사업 현황 ({tableCount.toLocaleString('ko-KR')})건</>);
|
|
})()
|
|
}
|
|
tableData={tableData}
|
|
headlist={dynamicHeadlist}
|
|
pageSize={OPERATION_TABLE_SIZE}
|
|
total={tableCount}
|
|
cellClick={handleOperationCellClick}
|
|
onPageChange={setCurPage}
|
|
resetPageNo={isResetPage}
|
|
resetSelection={isResetSelection}
|
|
curPage={curPage}
|
|
headButton={
|
|
<Button className="px-4 py-2 !mr-[1.2rem] text-white rounded-sm text-sm font-medium green" size="sm" onClick={operationExcelDownload}>파일 다운로드</Button>
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="h-[39vh] w-full overflow-hidden rounded-lg border">
|
|
{/* 테이블2 영역 */}
|
|
<div className="flex-1 px-2 pb-2">
|
|
<LoadingOverlay isLoading={isDetailLoading} />
|
|
<UiTable
|
|
headName={
|
|
(() => {
|
|
const label = WORK_TYPES.find((type) => type.val === workType)?.text
|
|
return (<>{label} 결과표 ({detailTableCount.toLocaleString('ko-KR')})건</>);
|
|
})()
|
|
}
|
|
tableData={detailTableData}
|
|
headlist={dynamicHeadlist2}
|
|
pageSize={OPERATION_TABLE_SIZE}
|
|
total={detailTableCount}
|
|
cellClick={handleOperationResultCellClick}
|
|
onPageChange={setDetailCurPage}
|
|
resetPageNo={isResetDetailPage}
|
|
resetSelection={isResetDetailSelection}
|
|
curPage={detailCurPage}
|
|
headButton={
|
|
<div className='flex'>
|
|
<Button className="px-4 py-2 !mr-[1.2rem] text-white rounded-sm text-lg font-medium primary" size="sm" onClick={viewMultipleFeature}>지도에서 보기</Button>
|
|
<Button className="px-4 py-2 !mr-[1.2rem] text-white rounded-sm text-lg font-medium green" size="sm" onClick={operationResultExcelDownload}>파일 다운로드</Button>
|
|
</div>
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<UiModal
|
|
open={open}
|
|
onOpenChange={onOpenChange}
|
|
bodyClass={`
|
|
h-[100dvh]
|
|
w-[60dvw]
|
|
max-w-[100dvw]
|
|
max-h-[100dvh]
|
|
overflow-hidden
|
|
z-[101]
|
|
`}
|
|
body={renderBody()}
|
|
useDirectRender={true}
|
|
/>
|
|
<Toaster position="top-center"></Toaster>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default React.memo(SearchModal);
|