Files
frontend/apps/wr/components/ui/modal/coMat/rateFeeModal.tsx
T

122 lines
3.7 KiB
TypeScript

"use client";
import { useWrStore } from "@/app/store";
import type { rateFeeType } from "@/app/store/common/searchCode/type";
import { yearOptions } from "@/components/lib/func/commom";
import { SelectBox, UiTable } from "@common/business_components/ui";
import ListDiv from "@common/business_components/ui/list_div";
import { Label, ScrollArea } from "@common/components/ui";
import { Scroll } from "lucide-react";
import { useEffect, useState } from "react";
export function RateFeeTableModal({
setReturnData,
}: {
setReturnData: (data: any) => void;
}) {
const { code, coRvw,rateFeeRes } = useWrStore((state) => state);
const [year, setYear] = useState<string>(String(new Date().getFullYear()));
const [reateFeeTable, setRateFeeTable] = useState<rateFeeType[]>([]);
const gubunLabelMap: Record<number, string> = {
50: "5천만원까지",
100: "1억원까지",
200: "2억원까지",
300: "3억원까지",
500: "5억원까지",
1000: "10억원까지",
2000: "20억원까지",
3000: "30억원까지",
5000: "50억원까지",
10000: "100억원까지",
20000: "200억원까지",
30000: "300억원까지",
40000: "400억원까지",
50000: "500억원까지",
70000: "700억원까지",
100000: "1000억원까지",
150000: "1500억원까지",
200000: "2000억원까지",
300000: "3000억원까지",
500000: "5000억원까지",
};
const fetchData = async (rateFeeRes: rateFeeType[]) => {
const data = await rateFeeRes?.reduce((acc: any, cur: rateFeeType) => {
const key = cur.stdCost;
let target = acc.find((item: any) => item.stdCost === key);
if (!target) {
target = {
stdCost: cur.stdCost,
BD: 0,
WD: 0,
SE: 0,
CE: 0,
};
acc.push(target);
}
target[cur.incExpCd] = cur.rt;
return acc;
}, []);
const dataGubun = data?.map((item: any) => {
return {
...item,
gubun: gubunLabelMap[item.stdCost] || item.stdCost,
};
});
return dataGubun?.sort((a: any, b: any) => a.stdCost - b.stdCost);
};
useEffect(() => {
console.log("rateFeeRes ", rateFeeRes);
if (rateFeeRes?.length >= 0) {
fetchData(rateFeeRes).then((data) => {
setRateFeeTable(data);
});
}
}, [rateFeeRes]);
return (
<>
<ListDiv className="!h-[calc(100vh-100px)] w-[90vw] max-w-[1200px] min-w-[600px] overflow-hidden">
<div className="sticky top-0 z-10 grid grid-cols-6 gap-4 p-4 bg-white">
<h3 className="col-span-6 text-2xl font-medium text-label">
요율표 보기
</h3>
<hr className="col-span-6 border-gray-300" />
<div className="col-span-2 flex items-center">
<Label className="text-xl text-gray-600">기준년도</Label>
<SelectBox
className="h-full text-2xl"
label=""
selectClass={"ml-4"}
selectArray={yearOptions}
value={year}
onSelectValue={(val: string | number) => setYear(String(val))}
/>
</div>
<div className="col-span-6">
<ScrollArea className="h-[60vh] overflow-auto">
<UiTable
className="min-w-full"
key={"rateTable" + reateFeeTable?.length}
headName={""}
tableData={reateFeeTable || []}
headlist={coRvw.rateFeeHeadList}
onPageChange={() => {}}
pageSize={0}
total={0}
cellClick={undefined}
/>
</ScrollArea>
</div>
</div>
</ListDiv>
</>
);
}