Files
frontend/apps/sn/app/store/table.tsx
T

117 lines
3.6 KiB
TypeScript

export type TableUpperProps = {
id: string,
title: string,
upSequnce?: number,
upName?: string
}
type PublicReuseFacility = {
sido: string,
sigungo: string,
facilityName: string,
location: string,
locationgubun: string,
facilityCapacity: string,
yn?: string,
authoDay?: string,
area?: string,
reuse?: string
}
const upHeadList:TableUpperProps[] = [
{ id: "sido", title: "자산ID"},
{ id: "sigungo", title: "설비시설"},
{ id: "facilityName", title: "주소"},
{ id: "location", title: "자산코드"},
{ id: "locationgubun", title: "자산명"},
{ id: "facilityCapacity", title: "용도"},
{ id: "yn", title: '신설/교체'},
{ id: "authoDay", title: '처리구역'},
{ id: "area", title: '내용연수' },
{ id: "reuse", title: '취득금액' },
];
const publicReuseFacilityUper:PublicReuseFacility[] = [
{
sido: "1048967",
sigungo: "관로",
facilityName: "양평군 양평읍 백안리 25-5전",
location: "S-T-S-2018000675",
locationgubun: "2018000675",
facilityCapacity: "오수관",
yn: "신설",
authoDay: "양평하수처리구역",
area: "30",
reuse: "28,313,220"
}
]
export type tableState = {
isInit: boolean;
upHeadList: TableUpperProps[];
publicReuseFacilityUper: PublicReuseFacility[];
}
type tableActions = {
setHeadList: (newHeadList: TableUpperProps[]) => void
setTableData: (newTableDataList: PublicReuseFacility[]) => void
decrementList: () => void
addRow: (newTableData: PublicReuseFacility) => void
}
export type tableType = tableState & tableActions;
export const tableStateExport:tableState= {
isInit:false,
upHeadList: [
{ id: "sido", title: "자산ID"},
{ id: "sigungo", title: "설비시설"},
{ id: "facilityName", title: "주소"},
{ id: "location", title: "자산코드"},
{ id: "locationgubun", title: "자산명"},
{ id: "facilityCapacity", title: "용도"},
{ id: "yn", title: '신설/교체'},
{ id: "authoDay", title: '처리구역'},
{ id: "area", title: '내용연수' },
{ id: "reuse", title: '취득금액' },
],
publicReuseFacilityUper: publicReuseFacilityUper,
}
export const tableActionsExport:(set:any)=>tableActions=(set: any) => {
return {
// 마지막 데이터 삭제
decrementList: ()=>set(
(state: tableState) => {
return (
{
...state,
upHeadList: state.upHeadList,
publicReuseFacilityUper: state.publicReuseFacilityUper.slice(0, state.publicReuseFacilityUper.length - 1)
})}
),
// 데이터 추가
addRow: (newTableData: PublicReuseFacility)=>set(
(state: tableState) => {
console.log('asdfasdfadsf')
return (
{
...state,
upHeadList: state.upHeadList,
publicReuseFacilityUper: [...state.publicReuseFacilityUper, newTableData]
})}
),
// 테이블 헤더 변경
setHeadList: (newHeadList: TableUpperProps[]) => set(
(state: tableState) => ({
...state,
upHeadList: newHeadList
})
),
// 시설 목록 데이터 변경
setTableData: (newTableData: PublicReuseFacility[]) => set(
(state: tableState) => ({
...state,
publicReuseFacilityUper: newTableData
})
),
}
}