157 lines
4.6 KiB
TypeScript
157 lines
4.6 KiB
TypeScript
import type { CommonTableProps } from "@/app/store/common/type/header";
|
|
import { fetchType, getFetchWithCount } from "@/components/lib/api";
|
|
import type { SelectDataType } from "@common/business_components/ui";
|
|
import type { z } from "zod";
|
|
import type { customHtdflBdst } from "../../fcltReg/htdflReg";
|
|
import { controlHeadView } from "../rainSttn";
|
|
import type { sttnHeadListType } from "../rainSttn/headList";
|
|
import { excelHtdflSttnParsing } from "./excel";
|
|
import { htdflSttHeadListExport, htdflSttNodeListExport } from "./headList";
|
|
|
|
const htdflSttHeadList = htdflSttHeadListExport;
|
|
const htdflSttNodeList = htdflSttNodeListExport;
|
|
|
|
|
|
export const htdflSttnSize =10;
|
|
export type htdflSttnState = {
|
|
htdflSttn: {
|
|
isInit: boolean;
|
|
htdflSttHeadList: z.infer<typeof sttnHeadListType>;
|
|
htdflSttNodeList: CommonTableProps[];
|
|
htdflSttnRes: customHtdflBdst[]
|
|
excelList: [];
|
|
htdflSttnResCount: number;
|
|
};
|
|
};
|
|
type htdflSttnActions = {
|
|
initHtdfl: (isExcel: boolean, page: number, total: number, con: string, txt: string,
|
|
sidoCode: SelectDataType[],
|
|
sggCode: SelectDataType[]) => void;
|
|
htdflSttnSearch: (isExcel: boolean, page: number, total: number, con: string, txt: string,
|
|
sidoCode: SelectDataType[],
|
|
sggCode: SelectDataType[]) => void;
|
|
htdflChSttnHead: (
|
|
headList: z.infer<typeof sttnHeadListType>,
|
|
) => void;
|
|
};
|
|
|
|
export type htdflSttnType = htdflSttnState & htdflSttnActions;
|
|
|
|
export const htdflSttnStateExport: htdflSttnState = {
|
|
htdflSttn: {
|
|
htdflSttHeadList: htdflSttHeadList,
|
|
htdflSttNodeList: htdflSttNodeList,
|
|
htdflSttnRes: [],
|
|
excelList: [],
|
|
isInit: false,
|
|
htdflSttnResCount: 1,
|
|
},
|
|
};
|
|
const initFetch = async (page: number, total: number, con: string, txt: string) => {
|
|
const htdflRes = await getFetchWithCount(
|
|
"wr",
|
|
`/drain/facilityList` +
|
|
(page ? `/${page}` : "/1") +
|
|
(total ? `/${total}` : "/20") +
|
|
(con ? `/${con}` : "/0") +
|
|
(txt ? `/${txt}` : "")
|
|
);
|
|
|
|
return htdflRes;
|
|
};
|
|
|
|
export const htdflSttnActionsExport: (set: any) => htdflSttnActions = (
|
|
set: any
|
|
) => {
|
|
return {
|
|
initHtdfl: async (isExcel: boolean, page: number, total: number, con: string, txt: string,
|
|
sidoCode: SelectDataType[],
|
|
sggCode: SelectDataType[]) => {
|
|
try {
|
|
const htdflSttnRes = await initFetch(page, total, con, txt);
|
|
if (isExcel) {
|
|
const htdflExcel = excelHtdflSttnParsing(htdflSttnRes, sidoCode, sggCode);
|
|
set((state: htdflSttnState) => {
|
|
return {
|
|
...state,
|
|
htdflSttn: {
|
|
...state.htdflSttn,
|
|
excelList: htdflExcel,
|
|
},
|
|
};
|
|
});
|
|
} else {
|
|
set((state: htdflSttnState) => {
|
|
return {
|
|
...state,
|
|
htdflSttn: {
|
|
...state.htdflSttn,
|
|
htdflSttnRes: htdflSttnRes.data,
|
|
htdflSttnResCount: htdflSttnRes.count,
|
|
isInit: false,
|
|
},
|
|
};
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
},
|
|
htdflSttnSearch: async (isExcel: boolean, page: number, total: number, con: string, txt: string,
|
|
sidoCode: SelectDataType[],
|
|
sggCode: SelectDataType[]) => {
|
|
try {
|
|
const htdflSttnRes = await getFetchWithCount(
|
|
fetchType.WR,
|
|
`/drain/facilityList` +
|
|
(page ? `/${page}` : "/1") +
|
|
(total ? `/${total}` : "/20") +
|
|
(con ? `/${con}` : "/0") +
|
|
(txt ? `/${txt}` : "")
|
|
);
|
|
|
|
if (isExcel) {
|
|
const htdflExcel = excelHtdflSttnParsing(htdflSttnRes, sidoCode, sggCode);
|
|
set((state: htdflSttnState) => {
|
|
return {
|
|
...state,
|
|
htdflSttn: {
|
|
...state.htdflSttn,
|
|
excelList: htdflExcel,
|
|
},
|
|
};
|
|
});
|
|
} else
|
|
set((state: htdflSttnState) => {
|
|
return {
|
|
...state,
|
|
htdflSttn: {
|
|
...state.htdflSttn,
|
|
htdflSttnRes: htdflSttnRes.data,
|
|
htdflSttnResCount: htdflSttnRes.count,
|
|
isInit: false,
|
|
},
|
|
};
|
|
});
|
|
} catch (erTxt) {
|
|
console.log("error", erTxt);
|
|
}
|
|
},
|
|
htdflChSttnHead: async (
|
|
headList: z.infer<typeof sttnHeadListType>
|
|
): Promise<void> => {
|
|
|
|
const changeNodeList = controlHeadView(headList, htdflSttNodeList)
|
|
|
|
return set((state: htdflSttnState) => ({
|
|
htdflSttn: {
|
|
...state.htdflSttn,
|
|
htdflSttHeadList: headList,
|
|
htdflSttNodeList: changeNodeList,
|
|
},
|
|
}));
|
|
},
|
|
|
|
|
|
}
|
|
} |