85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
import type { comCodeState, } from "@/app/store/common/code";
|
|
import { filePickedBlob, type SelectDataType } from "@common/business_components/ui";
|
|
|
|
|
|
|
|
|
|
|
|
export const getCity = (val: string, sggCd: SelectDataType[]) => {
|
|
const data = sggCd
|
|
.filter((item) => String(item.val).substring(0, 2) === val)
|
|
.map((item) => ({
|
|
val: item.val,
|
|
text: item.text // 한국어 텍스트
|
|
}));
|
|
return data
|
|
|
|
};
|
|
|
|
|
|
// cd text 넣기
|
|
export const tableData = ( data: any,code:comCodeState)=>{
|
|
const chCode = code.code;
|
|
return data?.map((item: { sggCd: string; ctpvCd: string; reuseBuilding: { lawTrgtYn: any , bdstUsgCd:any}[]; }) => {
|
|
let returnData = {};
|
|
const sggText = chCode.sggCd.find(
|
|
(cd) => cd.val === String(item.sggCd)
|
|
)?.text;
|
|
const cityText = chCode.cityCd.find(
|
|
(cd) => cd.val === String(item.ctpvCd)
|
|
)?.text;
|
|
console
|
|
.log(item?.reuseBuilding)
|
|
if (item?.reuseBuilding?.length >0) {
|
|
|
|
const bdsgUsgText = chCode.bdstUsgCd.find(
|
|
(cd) =>Number(cd.val) === item?.reuseBuilding[0]?.bdstUsgCd
|
|
)?.text
|
|
const lawTrgtYn = item?.reuseBuilding[0]?.lawTrgtYn
|
|
console
|
|
.log(bdsgUsgText)
|
|
|
|
returnData= { ...item, sggText: sggText??'없음', cityText: cityText??'없음' ,bdsgUsgText:bdsgUsgText ,lawTrgtYn:lawTrgtYn};
|
|
}else{
|
|
returnData= { ...item, sggText: sggText??'없음', cityText: cityText??'없음'};
|
|
}
|
|
|
|
return returnData;
|
|
|
|
});
|
|
}
|
|
|
|
|
|
|
|
export const excelDownload =(excelList: [][], fileNm:string ,sampleFile:string, headerRange='A1:V3') =>{
|
|
if (excelList.length === 0) return;
|
|
fetch(`/${sampleFile}`, {})
|
|
.then(async (response) => {
|
|
if (!response.ok) {
|
|
throw Error(response.statusText)
|
|
}
|
|
// 받은 파일 바인너리 처리
|
|
const blobRet = await response.arrayBuffer()
|
|
// 버퍼에 있는 엑셀데이터 전달 후 json으로 변환
|
|
await filePickedBlob(blobRet, excelList,fileNm, 4,headerRange)
|
|
})
|
|
}
|
|
|
|
|
|
// onchange 텍스트를 숫자로 and ,제거
|
|
export const handleCommaNumberChange = (
|
|
e: React.ChangeEvent<HTMLInputElement>,
|
|
onChange: (value: number | "") => void
|
|
) => {
|
|
const raw = e.target.value.replace(/,/g, "");
|
|
if (!/^\d*$/.test(raw)) return;
|
|
onChange(raw === "" ? "" : Number(raw));
|
|
};
|
|
// 숫자입력시 , 삽입
|
|
|
|
export const formatCommaNumber = (
|
|
value: number | string | undefined | null
|
|
): string => {
|
|
if (value === undefined || value === null || value === "") return "";
|
|
return Number(value).toLocaleString();
|
|
}; |