231 lines
6.2 KiB
TypeScript
231 lines
6.2 KiB
TypeScript
import type { CommonTableProps } from "@/app/store/common/type/header";
|
|
import { deleteFectch, fetchType, getFetchWithCount, postFectch, putFectch } from "@/components/lib/api";
|
|
import toast from "react-hot-toast";
|
|
import { z } from "zod";
|
|
import { TEST_UUID } from "../../ruseFcltMng/fcltReg/rainReg";
|
|
import { ldrmntHeadListExport, ldrmntNodeListExport, ldrmntZod } from "./headList";
|
|
|
|
// 테이블 헤드 리스트
|
|
const ldrmntHeadList = ldrmntHeadListExport;
|
|
const ldrmntNodeList = ldrmntNodeListExport;
|
|
|
|
export type customLdrmnt = z.infer<typeof ldrmntZod>;
|
|
|
|
const ldrmntRes: customLdrmnt[] = [];
|
|
|
|
export type ldrmntState = {
|
|
ldrmnt: {
|
|
ldrmntHeadList: CommonTableProps[];
|
|
ldrmntNodeList: CommonTableProps[];
|
|
excelList: ExcelType[];
|
|
isInit: boolean;
|
|
ldrmntRes: customLdrmnt[];
|
|
isLoading: boolean;
|
|
ldrmntResCount: number;
|
|
};
|
|
};
|
|
|
|
type ExcelType = {
|
|
[key: string]: string | number | undefined;
|
|
};
|
|
|
|
// const excelDownList: ExcelType[] = [];
|
|
|
|
type ldrmntActions = {
|
|
ldrmntRegData: (data: any[]) => void,
|
|
ldrmntInit: (isExcel: boolean, con: string) => void
|
|
ldrmntSearch: (isExcel: boolean, page: number, sggCd: string, total: string, coNm: string) => void;
|
|
ldrmntUpdate: (ldrmntRes: customLdrmnt) => void;
|
|
ldrmntDelete: () => void;
|
|
loadingOpen: (isOpen: boolean) => void
|
|
};
|
|
|
|
export type ldrmntType = ldrmntState & ldrmntActions;
|
|
|
|
export const ldrmntStateExport: ldrmntState = {
|
|
ldrmnt: {
|
|
ldrmntHeadList: ldrmntHeadList,
|
|
ldrmntNodeList: ldrmntNodeList,
|
|
excelList: [],
|
|
isInit: false,
|
|
ldrmntRes: ldrmntRes,
|
|
isLoading: false,
|
|
ldrmntResCount: 1,
|
|
},
|
|
};
|
|
|
|
export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
|
set: any
|
|
) => {
|
|
return {
|
|
ldrmntInit: async (isExcel: boolean,con: string) => {
|
|
try {
|
|
const ldrmntRes = await getFetchWithCount(
|
|
fetchType.WR,
|
|
`/reuseFc/request/temp/1/20/${con}`
|
|
);
|
|
if (isExcel) {
|
|
const excelDownList: ExcelType[] = [];
|
|
ldrmntRes.data.forEach((item: customLdrmnt) => {
|
|
excelDownList.push({
|
|
ctpvCd: item.ctpvCd,
|
|
sggCd: item.sggCd,
|
|
dmdCoNm: item.dmdCoNm,
|
|
fctryAddr: item.fctryAddr,
|
|
fctryMngNo: item.fctryMngNo,
|
|
telno: item.telno,
|
|
})
|
|
})
|
|
set((state: ldrmntState) => {
|
|
return {
|
|
...state,
|
|
ldrmnt: {
|
|
...state.ldrmnt,
|
|
excelList: excelDownList,
|
|
ldrmntResCount: ldrmntRes.count,
|
|
},
|
|
};
|
|
});
|
|
} else {
|
|
set((state: ldrmntState) => {
|
|
return {
|
|
...state,
|
|
ldrmnt: {
|
|
...state.ldrmnt,
|
|
ldrmntRes: ldrmntRes.data,
|
|
ldrmntResCount: ldrmntRes.count,
|
|
isInit: false,
|
|
},
|
|
}
|
|
});
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|
|
},
|
|
loadingOpen: (isOpen) => {
|
|
return set((state: ldrmntState) => {
|
|
return {
|
|
...state,
|
|
ldrmnt: {
|
|
...state.ldrmnt,
|
|
isLoading: isOpen,
|
|
},
|
|
};
|
|
});
|
|
},
|
|
ldrmntRegData: async (data) => {
|
|
await deleteFectch(
|
|
`/reuseFc/request/temp`,
|
|
);
|
|
console.log("deleteFectch", deleteFectch)
|
|
|
|
const response = await postFectch(
|
|
"/reuseFc/request/temp",
|
|
data,
|
|
fetchType.WR
|
|
);
|
|
|
|
console.log('response ', response)
|
|
|
|
},
|
|
ldrmntSearch: async (isExcel: boolean, page: number, total: string, sggCd: string, coNm: string) => {
|
|
let searchUrl = "";
|
|
|
|
if (sggCd !== "") {
|
|
if (coNm !== "") {
|
|
searchUrl = `/reuseFc/request/temp/${page}/${total}/${sggCd}/${coNm}`;
|
|
} else {
|
|
searchUrl = `/reuseFc/request/temp/${page}/${total}/${sggCd}`;
|
|
}
|
|
}
|
|
try {
|
|
const ldrmntRes = await getFetchWithCount(
|
|
fetchType.WR,
|
|
searchUrl
|
|
);
|
|
if (isExcel) {
|
|
const excelDownList: ExcelType[] = [];
|
|
ldrmntRes.data.forEach((item: customLdrmnt) => {
|
|
excelDownList.push({
|
|
ctpvCd: item.ctpvCd,
|
|
sggCd: item.sggCd,
|
|
dmdCoNm: item.dmdCoNm,
|
|
fctryAddr: item.fctryAddr,
|
|
fctryMngNo: item.fctryMngNo,
|
|
telno: item.telno,
|
|
})
|
|
})
|
|
set((state: ldrmntState) => {
|
|
return {
|
|
...state,
|
|
ldrmnt: {
|
|
...state.ldrmnt,
|
|
excelList: excelDownList,
|
|
ldrmntResCount: ldrmntRes.count,
|
|
},
|
|
};
|
|
});
|
|
} else
|
|
set((state: ldrmntState) => {
|
|
return {
|
|
...state,
|
|
ldrmnt: {
|
|
...state.ldrmnt,
|
|
ldrmntRes: ldrmntRes.data,
|
|
ldrmntResCount: ldrmntRes.count,
|
|
isInit: false,
|
|
},
|
|
};
|
|
});
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|
|
},
|
|
ldrmntUpdate: async (ldrmntRes: customLdrmnt) => {
|
|
if (ldrmntRes)
|
|
try {
|
|
ldrmntRes.rgtr = TEST_UUID;
|
|
const res = await putFectch(
|
|
`/reuseFc/request/temp`,
|
|
ldrmntRes
|
|
);
|
|
|
|
if (res.ok) {
|
|
toast.success("잠재수요처 상세정보가 수정되었습니다.",)
|
|
}
|
|
} catch (error) {
|
|
console.error("Error ldrmntUpdate:", error);
|
|
toast.error("잠재수요처 상세정보 수정에 실패하였습니다.")
|
|
}
|
|
},
|
|
ldrmntDelete: async () => {
|
|
try {
|
|
set((state: ldrmntState) => {
|
|
return {
|
|
...state,
|
|
ldrmnt: {
|
|
...state.ldrmnt,
|
|
isLoading: true,
|
|
},
|
|
};
|
|
});
|
|
await deleteFectch(
|
|
`/reuseFc/request/temp`,
|
|
);
|
|
} catch (error) {
|
|
console.log("error", error)
|
|
set((state: ldrmntState) => {
|
|
return {
|
|
...state,
|
|
ldrmnt: {
|
|
...state.ldrmnt,
|
|
isLoading: false,
|
|
},
|
|
};
|
|
});
|
|
console.error("Error ldrmntDelete:", error);
|
|
}
|
|
},
|
|
}
|
|
} |