잠재수요처 엑셀 다운로드 수정
This commit is contained in:
@@ -3,11 +3,10 @@
|
||||
import { useWrStore } from "@/app/store";
|
||||
import { btnClass } from "@/app/store/common/code";
|
||||
import { type customLdrmnt } from "@/app/store/matDmd/ldrmntCoSttn";
|
||||
import { ldrmntHeadListExport, ldrmntNodeListExport } from "@/app/store/matDmd/ldrmntCoSttn/headList";
|
||||
import { ldrmntHeadListExport } from "@/app/store/matDmd/ldrmntCoSttn/headList";
|
||||
import {
|
||||
excelDownload,
|
||||
getCity,
|
||||
getCityOrSgg,
|
||||
tableData
|
||||
} from "@/components/lib/func/commom";
|
||||
import CoRegExcel from "@/components/ui/modal/coReg/coRegExcel/coRegExcelModal";
|
||||
@@ -24,42 +23,62 @@ import {
|
||||
Title,
|
||||
UiModal,
|
||||
UiTable,
|
||||
type ReturnType,
|
||||
type SelectDataType
|
||||
} from "@common/business_components/ui";
|
||||
import ListDiv from "@common/business_components/ui/list_div";
|
||||
import { Button } from "@common/components/ui";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
|
||||
export default function LdrmntCoSttn() {
|
||||
const { code, ldrmnt, ldrmntInit, ldrmntSearch, } = useWrStore(
|
||||
(state) => state
|
||||
);
|
||||
const { ldrmntRes, excelList } = ldrmnt;
|
||||
const { ldrmntRes, excelList, ldrmntResCount } = ldrmnt;
|
||||
const [detailModal, setDetailModal] = useState<{ isOpen: boolean, data: customLdrmnt | undefined }>({ data: undefined, isOpen: false })
|
||||
const [pageNation, setPageNation] = useState(1);
|
||||
const [selectSgg, setSelectSgg] = useState<SelectDataType[] | []>()
|
||||
const [objSearch, setObjSearch] = useState<objSearchType>({ sgg: "", city: "" });
|
||||
const [bdstTable, setBdstTable] = useState<customLdrmnt[]>();
|
||||
const [searchTxt, setSearchTxt] = useState<string>();
|
||||
const ref = useRef<ReturnType>({} as ReturnType);
|
||||
const [excelData, setExcelData] = useState<any[]>();
|
||||
const [isExcelDownload, setIsExcelDownload] = useState(false);
|
||||
|
||||
const excelClick = useCallback(() => {
|
||||
excelDownload(
|
||||
[[]],
|
||||
"잠재수요처 관리",
|
||||
"잠재수요처 등록양식",
|
||||
"sample_ldrmntCoSttn.xlsx",
|
||||
"A1:AL1",
|
||||
2
|
||||
);
|
||||
}, []);
|
||||
|
||||
const excelDownloadClick = () => {
|
||||
ldrmntSearch(1, "10000", "0", "");
|
||||
const computeCityNm = () => {
|
||||
let cityTxt = "";
|
||||
let sggTxt = "";
|
||||
|
||||
if (objSearch.city) {
|
||||
cityTxt =
|
||||
code.cityCd.find((c) => c.val === objSearch.city)?.text || "";
|
||||
}
|
||||
if (objSearch.sgg) {
|
||||
sggTxt =
|
||||
code.sggCd.find((s) => s.val === objSearch.sgg)?.text || "";
|
||||
}
|
||||
|
||||
if (cityTxt === "" || cityTxt === "전체") cityTxt = "0";
|
||||
|
||||
return sggTxt && sggTxt !== "0"
|
||||
? `${cityTxt} ${sggTxt}`
|
||||
: cityTxt;
|
||||
};
|
||||
|
||||
const excelDownloadClick = useCallback(() => {
|
||||
const cityNm = computeCityNm();
|
||||
ldrmntSearch(true, pageNation, String(ldrmntResCount), cityNm, searchTxt || "");
|
||||
setIsExcelDownload(true);
|
||||
}
|
||||
}, [objSearch, pageNation, searchTxt, code, ldrmntSearch, computeCityNm]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isExcelDownload && excelData && excelData.length > 0) {
|
||||
@@ -141,33 +160,8 @@ export default function LdrmntCoSttn() {
|
||||
}, [excelList])
|
||||
|
||||
useEffect(() => {
|
||||
let cityTxt = ''
|
||||
let sggTxt = ''
|
||||
|
||||
if (objSearch?.city.toString().length > 0) {
|
||||
cityTxt = code.cityCd.find((item) => item.val === objSearch?.city)?.text ?? '';
|
||||
}
|
||||
|
||||
if (objSearch?.sgg.toString().length > 1) {
|
||||
sggTxt = code.sggCd.find((item) => item.val === objSearch?.sgg)?.text ?? '';
|
||||
}
|
||||
|
||||
if (cityTxt === '전체' || cityTxt === '') {
|
||||
cityTxt = '0'
|
||||
}
|
||||
|
||||
let cityNm = ""
|
||||
|
||||
if (sggTxt !== "0") {
|
||||
cityNm = cityTxt + " " + sggTxt
|
||||
} else {
|
||||
cityNm = cityTxt
|
||||
}
|
||||
if (cityNm) {
|
||||
ldrmntSearch(pageNation, '20', cityNm, searchTxt || "");
|
||||
} else {
|
||||
ldrmntSearch(pageNation, '20', '0', searchTxt || "");
|
||||
}
|
||||
const cityNm = computeCityNm();
|
||||
ldrmntSearch(false, pageNation, '20', cityNm, searchTxt || "");
|
||||
}, [pageNation]);
|
||||
|
||||
return (
|
||||
@@ -210,32 +204,8 @@ export default function LdrmntCoSttn() {
|
||||
<Button
|
||||
size={"sm"}
|
||||
onClick={(e) => {
|
||||
|
||||
let cityTxt = ''
|
||||
let sggTxt = ''
|
||||
|
||||
if (objSearch?.city.toString().length > 0) {
|
||||
cityTxt = code.cityCd.find((item) => item.val === objSearch?.city)?.text ?? '';
|
||||
}
|
||||
|
||||
if (objSearch?.sgg.toString().length > 1) {
|
||||
sggTxt = code.sggCd.find((item) => item.val === objSearch?.sgg)?.text ?? '';
|
||||
}
|
||||
|
||||
if (cityTxt === '전체' || cityTxt === '') {
|
||||
cityTxt = '0'
|
||||
}
|
||||
|
||||
let cityNm = ""
|
||||
|
||||
if (sggTxt !== "0") {
|
||||
cityNm = cityTxt + " " + sggTxt
|
||||
} else {
|
||||
cityNm = cityTxt
|
||||
}
|
||||
if (cityNm) {
|
||||
ldrmntSearch(pageNation, '20', cityNm, searchTxt || "");
|
||||
}
|
||||
const cityNm = computeCityNm();
|
||||
ldrmntSearch(false, pageNation, '20', cityNm, searchTxt || "");
|
||||
}}
|
||||
>
|
||||
조회
|
||||
@@ -273,7 +243,7 @@ export default function LdrmntCoSttn() {
|
||||
<div className="overflow-x-auto">
|
||||
<ListDiv className="min-w-max">
|
||||
<UiTable
|
||||
headName={[]}
|
||||
headName={undefined}
|
||||
tableData={bdstTable || []}
|
||||
headlist={ldrmntHeadListExport}
|
||||
pageSize={20}
|
||||
@@ -299,8 +269,9 @@ export default function LdrmntCoSttn() {
|
||||
setIsExcelOpen({ isModal: !isExcelOpen.isModal })
|
||||
}}
|
||||
bodyClass={"w-[40vw] max-w-none"}
|
||||
body={<CoRegExcel />}
|
||||
body={<CoRegExcel isModal={(isOpen) => setIsExcelOpen({ isModal: isOpen })} />}
|
||||
/>
|
||||
<Toaster position="top-center"></Toaster>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { CommonTableProps } from "@/app/store/common/type/header";
|
||||
import { deleteFectch, fetchType, getFetch, postFectch, putFectch } from "@/components/lib/api";
|
||||
import { deleteFectch, fetchType, getFetch, getFetchWithCount, postFectch, putFectch } from "@/components/lib/api";
|
||||
import { ToastFormUi } from "@/components/ui/toast/toastFromUi";
|
||||
import { z } from "zod";
|
||||
import { TEST_UUID } from "../../ruseFcltMng/fcltReg/rainReg";
|
||||
@@ -20,6 +20,8 @@ export type ldrmntState = {
|
||||
excelList: ExcelType[];
|
||||
isInit: boolean;
|
||||
ldrmntRes: customLdrmnt[];
|
||||
isLoading: boolean;
|
||||
ldrmntResCount: number;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -32,9 +34,10 @@ const excelDownList: ExcelType[] = [];
|
||||
type ldrmntActions = {
|
||||
ldrmntRegData: (data: any[]) => void,
|
||||
ldrmntInit: (con: string) => void
|
||||
ldrmntSearch: (page: number, sggCd: string, total: string, coNm: 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;
|
||||
@@ -46,6 +49,8 @@ export const ldrmntStateExport: ldrmntState = {
|
||||
excelList: [],
|
||||
isInit: false,
|
||||
ldrmntRes: ldrmntRes,
|
||||
isLoading: false,
|
||||
ldrmntResCount: 1,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -75,33 +80,32 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
||||
console.log(e)
|
||||
}
|
||||
},
|
||||
ldrmntRegData: async (data) => {
|
||||
try {
|
||||
const response = await postFectch(
|
||||
"/reuseFc/request/temp",
|
||||
data,
|
||||
fetchType.WR
|
||||
);
|
||||
|
||||
console.log('response ', response)
|
||||
|
||||
if (response.status === 200) {
|
||||
ToastFormUi({
|
||||
body: "잠재수요처 등록이 완료되었습니다. ",
|
||||
title: "잠재수요처 등록",
|
||||
});
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
ToastFormUi({
|
||||
body: "잠재수요처 등록이 실패하였습니다. ",
|
||||
title: "잠재수요처 등록",
|
||||
});
|
||||
|
||||
}
|
||||
loadingOpen: (isOpen) => {
|
||||
return set((state: ldrmntState) => {
|
||||
return {
|
||||
...state,
|
||||
ldrmnt: {
|
||||
...state.ldrmnt,
|
||||
isLoading: isOpen,
|
||||
},
|
||||
};
|
||||
});
|
||||
},
|
||||
ldrmntSearch: async (page: number, total: string, sggCd: string, coNm: string) => {
|
||||
ldrmntRegData: async (data) => {
|
||||
await deleteFectch(
|
||||
`/reuseFc/request/temp`,
|
||||
);
|
||||
|
||||
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 !== "") {
|
||||
@@ -112,14 +116,14 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
||||
}
|
||||
}
|
||||
try {
|
||||
const ldrmntRes = await getFetch(
|
||||
const ldrmntRes = await getFetchWithCount(
|
||||
fetchType.WR,
|
||||
searchUrl
|
||||
);
|
||||
|
||||
if (Number(total) > 5000) {
|
||||
if (isExcel) {
|
||||
let excelDownList: ExcelType[] = [];
|
||||
ldrmntRes.forEach((item: customLdrmnt) => {
|
||||
ldrmntRes.data.forEach((item: customLdrmnt) => {
|
||||
excelDownList.push({
|
||||
ctpvCd: item.ctpvCd,
|
||||
sggCd: item.sggCd,
|
||||
@@ -146,7 +150,8 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
||||
...state,
|
||||
ldrmnt: {
|
||||
...state.ldrmnt,
|
||||
ldrmntRes: ldrmntRes,
|
||||
ldrmntRes: ldrmntRes.data,
|
||||
ldrmntResCount: ldrmntRes.count,
|
||||
isInit: false,
|
||||
},
|
||||
};
|
||||
@@ -178,11 +183,30 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
||||
},
|
||||
ldrmntDelete: async () => {
|
||||
try {
|
||||
set((state: ldrmntState) => {
|
||||
return {
|
||||
...state,
|
||||
ldrmnt: {
|
||||
...state.ldrmnt,
|
||||
isLoading: true,
|
||||
},
|
||||
};
|
||||
});
|
||||
const response = 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);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4,32 +4,32 @@ import type { customLdrmnt } from "@/app/store/matDmd/ldrmntCoSttn";
|
||||
import { names } from "@/app/store/matDmd/ldrmntCoSttn/excel";
|
||||
import { filePicked, FileUpload, FormUi, Title } from "@common/business_components/ui";
|
||||
import { Form, FormField } from "@common/business_components/ui/form";
|
||||
import LoadingOverlay from "@common/business_components/ui/loadingBar";
|
||||
import { Button, Progress } from "@common/components/ui";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import toast from "react-hot-toast";
|
||||
import type { z } from "zod";
|
||||
|
||||
export default function CoRegExcel() {
|
||||
|
||||
|
||||
export default function CoRegExcel({ isModal }: { isModal: (open: boolean) => void }) {
|
||||
const { ldrmnt,loadingOpen } = useWrStore((state) => state);
|
||||
const { isLoading } = ldrmnt;
|
||||
const form = useForm<z.infer<typeof coRegExcel>>({
|
||||
resolver: zodResolver(coRegExcel),
|
||||
});
|
||||
const { ldrmntRegData, ldrmntDelete } = useWrStore((state) => state);
|
||||
const [excelData, setExcelData] = useState<customLdrmnt[]>();
|
||||
|
||||
|
||||
const [file, setFiles] = useState<File | undefined>();
|
||||
|
||||
const onSubmit = (values: z.infer<typeof coRegExcel>) => {
|
||||
ldrmntDelete();
|
||||
loadingOpen(true);
|
||||
if (file) {
|
||||
filePicked(file, 0).then((res) => {
|
||||
//TODO:loading
|
||||
filePicked(file, 0).then(async (res) => {
|
||||
|
||||
try {
|
||||
let array: { [key: string]: string | number }[] = []
|
||||
let isError = false;
|
||||
if (Array.isArray(res)) {
|
||||
res.some((item, index) => {
|
||||
let object: { [key: string]: string | number } = {}
|
||||
@@ -43,26 +43,24 @@ export default function CoRegExcel() {
|
||||
}
|
||||
return false;
|
||||
})
|
||||
if (isError === true)
|
||||
return true;
|
||||
|
||||
array.push(object)
|
||||
|
||||
if (index != 0 && index % 5000 == 0) {
|
||||
ldrmntRegData(array);
|
||||
array = []
|
||||
array.length = 0;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
}
|
||||
if (isError === false)
|
||||
ldrmntRegData(array);
|
||||
await ldrmntRegData(array);
|
||||
isModal(false);
|
||||
loadingOpen(false);
|
||||
toast.success(`잠재수요처 등록이 완료되었습니다.`);
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
loadingOpen(false);
|
||||
alert(e)
|
||||
return true;
|
||||
}
|
||||
|
||||
}).catch((e)=>{
|
||||
console.log("file", e);
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -70,6 +68,7 @@ export default function CoRegExcel() {
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<LoadingOverlay isLoading={isLoading}></LoadingOverlay>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user