255 lines
6.4 KiB
TypeScript
255 lines
6.4 KiB
TypeScript
import { getFetch } from "@/components/lib/api";
|
|
import type { EnvPartSelectDataType, SelectDataType } from "@common/business_components/ui";
|
|
import { bdstFilterYn, bdstGrntchClass, bdstIncenYn, bdstUsgCd, chBuCd, dmdUszCd, erctUswtrPrcsMeth, htdPowerMthdCd, htdUtztnUsgCd, orgwtKndCd, pplLenght, pplQulity, rainFcltCd, rswtPrscCdMthdCd, ruseBizMthdCd, ruseMngMtd, rusePrcsMthdCd, ruseSeCd, yn } from "./basicCode";
|
|
export const btnClass = "p-4 m-2 text-white rounded-sm text-lg font-medium "
|
|
|
|
|
|
const laeSecd = '41'
|
|
|
|
|
|
export const buildingType = {
|
|
RST:"RST",
|
|
RNB:"RNB",
|
|
HTB:"HTB"
|
|
}
|
|
export const getSggCd = async (set: any) => {
|
|
const sgg = await getFetch("common", "/addr/sgg");
|
|
/* const sggCd = sgg.map((item: any) => ({
|
|
val: item.adstDstrCd,
|
|
text: item.gugun,
|
|
})); */
|
|
|
|
const sggCd = [
|
|
// { text: "전체", val: '0' },
|
|
...sgg
|
|
.map((item: any) => ({
|
|
text: item.gugun || '',
|
|
val: String(item.adstDstrCd) || ''
|
|
}))
|
|
];
|
|
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
sggCd: sggCd,
|
|
},
|
|
}));
|
|
};
|
|
export const getCityCd = async (set: any) => {
|
|
const city = await getFetch("common", "/addr/city");
|
|
const cityCd = city.map((item: any) => ({
|
|
val: item.adstDstrCd,
|
|
text: item.sido,
|
|
}));
|
|
cityCd.unshift({ val: '0', text: '전체' })
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
cityCd: cityCd,
|
|
},
|
|
}));
|
|
};
|
|
|
|
// 권역 API 호출 함수 추가
|
|
export const getRegionCd = async (set: any) => {
|
|
try {
|
|
const rvbsn = await getFetch("common", "/addr/sarea");
|
|
const rvbsnCd = rvbsn.map((item: any) => ({
|
|
val: item.rvbsnCd,
|
|
text: item.rvbsn,
|
|
}));
|
|
rvbsnCd.unshift({ val: '0', text: '전체' })
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
rvbsnCd: rvbsnCd,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error('권역 데이터를 가져오는데 실패했습니다:', error);
|
|
}
|
|
};
|
|
|
|
// 중권역 API 호출 함수 추가
|
|
export const getMiddleRegionCd = async (set: any) => {
|
|
try {
|
|
const mdmbsn = await getFetch("common", "/addr/midArea");
|
|
const mdmbsnCd = mdmbsn.map((item: any) => ({
|
|
val: item.rvbsnCd,
|
|
text: item.mdmbsn,
|
|
}));
|
|
mdmbsnCd.unshift({ val: '0', text: '전체' })
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
mdmbsnCd: mdmbsnCd,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error('중권역 데이터를 가져오는데 실패했습니다:', error);
|
|
}
|
|
};
|
|
|
|
|
|
// 단위유역 API 호출 함수 추가
|
|
export const getUnitWaterShedCd = async (set: any) => {
|
|
try {
|
|
const lgbsn = await getFetch("common", "/addr/largeArea");
|
|
const lgbsnCd = lgbsn.map((item: any) => ({
|
|
val: item.rvbsnCd,
|
|
text: item.lgbsn,
|
|
}));
|
|
lgbsnCd.unshift({ val: '0', text: '전체' })
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
lgbsnCd: lgbsnCd,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error('대영역 데이터를 가져오는데 실패했습니다:', error);
|
|
}
|
|
};
|
|
|
|
|
|
|
|
// 환경청 데이터
|
|
export const getEnvPartCd = async (set: any) => {
|
|
try {
|
|
const lclgvrnmnt = await getFetch('common', '/addr/govArea');
|
|
const lclgvrnmntCd = lclgvrnmnt.map((item: any) => ({
|
|
val: item.lclgvrnmntCd,
|
|
text: item.lclgvrnmntNm,
|
|
adstDliStrCd: item.adstDliStrCd || ''
|
|
|
|
}));
|
|
lclgvrnmntCd.unshift({ val: '0', text: '전체', adstDliStrCd: '' })
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
lclgvrnmntCd: lclgvrnmntCd,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error('환경청 데이터를 가져오는데 실패했습니다:', error);
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
export type comCodeState = {
|
|
code: {
|
|
isInit: boolean;
|
|
chBuCd: SelectDataType[]
|
|
rainFcltCd: SelectDataType[];
|
|
bdstUsgCd: SelectDataType[];
|
|
cityCd: SelectDataType[];
|
|
sggCd: SelectDataType[];
|
|
rvbsnCd: SelectDataType[];
|
|
mdmbsnCd: SelectDataType[];
|
|
lgbsnCd: SelectDataType[];
|
|
lclgvrnmntCd: EnvPartSelectDataType[];
|
|
orgwtKndCd: SelectDataType[];
|
|
yn: SelectDataType[];
|
|
pplQulity: SelectDataType[];
|
|
pplLenght: SelectDataType[];
|
|
dmdUszCd:SelectDataType[]
|
|
buildingType: {
|
|
RST:string,
|
|
RNB:string,
|
|
HTB:string
|
|
}
|
|
ruseMngMtd:SelectDataType[]
|
|
ruseSeCd: SelectDataType[];
|
|
ruseBizMthdCd: SelectDataType[];
|
|
rusePrcsMthdCd: SelectDataType[];
|
|
erctUswtrPrcsMeth: SelectDataType[];
|
|
bdstFilterYn: SelectDataType[];
|
|
bdstIncenYn: SelectDataType[];
|
|
bdstGrntchClass:SelectDataType[];
|
|
rswtPrscCdMthdCd:SelectDataType[];
|
|
htdPowerMthdCd:SelectDataType[]
|
|
htdUtztnUsgCd:SelectDataType[]
|
|
userSiSggCd : string;
|
|
|
|
};
|
|
};
|
|
|
|
export type comCodeType = comCodeState & comCodeActions;
|
|
|
|
|
|
|
|
export const comCodeStateExport: comCodeState = {
|
|
code: {
|
|
isInit: false,
|
|
rainFcltCd: rainFcltCd,
|
|
bdstUsgCd: bdstUsgCd,
|
|
chBuCd: chBuCd,
|
|
orgwtKndCd: orgwtKndCd,
|
|
cityCd: [],
|
|
sggCd: [],
|
|
rvbsnCd: [],
|
|
mdmbsnCd: [],
|
|
lgbsnCd: [],
|
|
lclgvrnmntCd: [],
|
|
pplQulity:pplQulity,
|
|
pplLenght:pplLenght,
|
|
yn: yn,
|
|
dmdUszCd:dmdUszCd,
|
|
buildingType:buildingType,
|
|
ruseMngMtd:ruseMngMtd,
|
|
ruseSeCd:ruseSeCd,
|
|
ruseBizMthdCd: ruseBizMthdCd,
|
|
rusePrcsMthdCd:rusePrcsMthdCd,
|
|
erctUswtrPrcsMeth:erctUswtrPrcsMeth,
|
|
bdstFilterYn:bdstFilterYn,
|
|
bdstIncenYn:bdstIncenYn,
|
|
bdstGrntchClass:bdstGrntchClass,
|
|
rswtPrscCdMthdCd:rswtPrscCdMthdCd,
|
|
htdPowerMthdCd:htdPowerMthdCd,
|
|
htdUtztnUsgCd:htdUtztnUsgCd,
|
|
userSiSggCd:laeSecd,
|
|
},
|
|
};
|
|
|
|
export type comCodeActions = {
|
|
codeInit: () => void;
|
|
};
|
|
|
|
export const codeActionExport: (set: any) => comCodeActions = (set: any) => {
|
|
return {
|
|
codeInit: async () => {
|
|
const sgg = await getFetch("common", "/addr/sgg");
|
|
|
|
const sggCd = sgg.map((item: any) => ({
|
|
val: item.adstDstrCd,
|
|
text: item.gugun,
|
|
}));
|
|
|
|
const city = await getFetch("common", "/addr/city");
|
|
const cityCd = city.map((item: any) => ({
|
|
val: item.adstDstrCd,
|
|
text: item.sido,
|
|
}));
|
|
|
|
return set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
sggCd: sggCd,
|
|
cityCd: cityCd,
|
|
},
|
|
}));
|
|
},
|
|
|
|
divCityCd: async (cd: string) => {
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
sggCd: state.code.sggCd.filter((item) => { return item.val.toString().slice(0, 2) === cd }),
|
|
},
|
|
}));
|
|
},
|
|
};
|
|
};
|