135 lines
3.8 KiB
TypeScript
135 lines
3.8 KiB
TypeScript
import { fetchType, getFetch, getFetchWithCount } from "@/components/lib/api";
|
|
import type { CommonTableProps } from "../../common/type/header";
|
|
import type { customRswtBdst } from "../../ruseFcltMng/fcltReg/rswtReg";
|
|
import {
|
|
rswtSttHeadListExport,
|
|
rswtSttNodeListExport,
|
|
} from "../../ruseFcltMng/fcltSttn/rswtSttn/headList";
|
|
import type { SelectDataType } from "@common/business_components/ui";
|
|
import { excelRSwtSttnParsing } from "../../ruseFcltMng/fcltSttn/rswtSttn/excel";
|
|
|
|
export const rswtMapSize = 15;
|
|
export type rswtMapState = {
|
|
rswtMap: {
|
|
rswtMapRes: customRswtBdst[];
|
|
rswtMapCount: number;
|
|
rswtMapExcelList:[]
|
|
isInit: boolean;
|
|
rswtSttHeadList: CommonTableProps[];
|
|
rswtSttNodeList: CommonTableProps[];
|
|
};
|
|
};
|
|
|
|
type rswtMapActions = {
|
|
rswtMapInit: (page: number, total: number, cityOrSgg: string) => void;
|
|
rswtMapSearch: (
|
|
isExcel: boolean, page: number, total: string, con: string, txt: string,
|
|
sidoCode: SelectDataType[],
|
|
sggCode: SelectDataType[]
|
|
) => void;
|
|
rswtMapDetile: (featureCd: string) => Promise<customRswtBdst | undefined>;
|
|
};
|
|
|
|
export type rswtMapType = rswtMapState & rswtMapActions;
|
|
|
|
export const rswtMapStateExport: rswtMapState = {
|
|
rswtMap: {
|
|
isInit: false,
|
|
rswtMapRes: [],
|
|
rswtMapExcelList:[],
|
|
rswtMapCount: 1,
|
|
rswtSttHeadList: rswtSttHeadListExport,
|
|
rswtSttNodeList: rswtSttNodeListExport,
|
|
},
|
|
};
|
|
|
|
export const rswtMapActionsExport: (set: any) => rswtMapActions = (
|
|
set: any
|
|
) => {
|
|
return {
|
|
rswtMapInit: async (page: number, total: number, cityOrSgg: string) => {
|
|
try {
|
|
const rswtMapRes = await getFetchWithCount(
|
|
fetchType.WR,
|
|
`/reuseFc/waterreuseFc` +
|
|
(page ? `/${page}` : "/1") +
|
|
(total ? `/${total}` : "/20") +
|
|
(cityOrSgg ? `/${cityOrSgg}` : "/0")
|
|
);
|
|
|
|
set((state: rswtMapState) => {
|
|
return {
|
|
...state,
|
|
rswtMap: {
|
|
...state.rswtMap,
|
|
rswtMapRes: rswtMapRes.data,
|
|
rswtMapCount: rswtMapRes.count,
|
|
isInit: false,
|
|
},
|
|
};
|
|
});
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
},
|
|
rswtMapSearch: async (isExcel: boolean, page: number, total: string, con: string, txt: string,
|
|
sidoCode: SelectDataType[],
|
|
sggCode: SelectDataType[]
|
|
) => {
|
|
try {
|
|
const rswtMapRes = await getFetchWithCount(
|
|
fetchType.WR,
|
|
`/reuseFc/waterreuseFc` +
|
|
(page ? `/${page}` : "/1") +
|
|
(total ? `/${total}` : "/20") +
|
|
(con ? `/${con}` : "/0") +
|
|
(txt ? `/${txt}` : "")
|
|
);
|
|
if (isExcel) {
|
|
const rswtMapExcelList = excelRSwtSttnParsing(rswtMapRes, sidoCode, sggCode);
|
|
set((state: rswtMapState) => {
|
|
return {
|
|
...state,
|
|
rswtMap: {
|
|
...state.rswtMap,
|
|
rswtMapExcelList:rswtMapExcelList
|
|
},
|
|
};
|
|
});
|
|
}else{
|
|
|
|
set((state: rswtMapState) => {
|
|
return {
|
|
...state,
|
|
rswtMap: {
|
|
...state.rswtMap,
|
|
rswtMapRes: rswtMapRes.data,
|
|
rswtMapCount: rswtMapRes.count,
|
|
},
|
|
};
|
|
});
|
|
}
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
},
|
|
rswtMapDetile: async (featureCd: string) => {
|
|
try {
|
|
const rswtDetail = await getFetch(
|
|
fetchType.WR,
|
|
`/reuseFc/waterreuseFc/1/3/0/${featureCd}`
|
|
);
|
|
|
|
if (rswtDetail && rswtDetail.length > 0) {
|
|
return rswtDetail[0];
|
|
} else {
|
|
return null;
|
|
}
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw error; // 호출부에서 catch 가능하도록
|
|
}
|
|
},
|
|
};
|
|
};
|