import { getFectch } from "@/components/lib/api"; // Description: 공통코드 type selectArray = { text: string; val: string | number; }; export const bdstUsgCd: selectArray[] = [ { val: 1, text: "운동장" }, { val: 2, text: "체육관" }, { val: 3, text: "공공업무시설" }, { val: 4, text: "공공기관의청사" }, { val: 5, text: "아파트" }, { val: 6, text: "연립주택" }, { val: 7, text: "다세대주택" }, { val: 8, text: "기숙사" }, { val: 9, text: "초등학교" }, { val: 10, text: "중학교" }, { val: 11, text: "고등학교" }, { val: 12, text: "전문대학" }, { val: 13, text: "대학및대학교" }, { val: 14, text: "골프장" }, { val: 15, text: "대규모점포" }, { val: 16, text: "기타" }, ]; export const rainFcltCd = [ { val: "1", text: "지붕" }, { val: "2", text: "건물옥상" }, { val: "3", text: "골프장 연못" }, { val: "4", text: "운동장 바닥" }, { val: "5", text: "운동장 지붕" }, { val: "6", text: "주차장" }, { val: "7", text: "태양광패널" }, { val: "8", text: "연못" }, { val: "9", text: "기타" }, { val: "10", text: "확인불가" }, ]; export type comCodeState = { code: { isInit: boolean; rainFcltCd: selectArray[]; bdstUsgCd: selectArray[]; cityCd: selectArray[]; sggCd: selectArray[]; }; }; export type comCodeType = comCodeState & comCodeActions; export const getSggCd = async (set: any) => { const sgg = await getFectch("common", "/addr/sgg"); const sggCd = sgg.map((item: any) => ({ val: item.sggCd, text: item.sggKornNm, })); set((state: comCodeState) => ({ code: { ...state.code, sggCd: sggCd, }, })); }; export const getCityCd = async (set: any) => { const city = await getFectch("common", "/addr/city"); const cityCd = city.map((item: any) => ({ val: item.mctpvCd, text: item.mctpvKornNm, })); set((state: comCodeState) => ({ code: { ...state.code, cityCd: cityCd, }, })); }; export const comCodeStateExport: comCodeState = { code: { isInit: false, rainFcltCd: rainFcltCd, bdstUsgCd: bdstUsgCd, cityCd: [], sggCd: [], }, }; export type comCodeActions = { codeInit: () => void; }; export const codeActionExport: (set: any) => comCodeActions = (set: any) => { return { codeInit: async () => { const sgg = await getFectch("common", "/addr/sgg"); const sggCd = sgg.map((item: any) => ({ val: item.sggCd, text: item.sggKornNm, })); const city = await getFectch("common", "/addr/city"); const cityCd = city.map((item: any) => ({ val: item.mctpvCd, text: item.mctpvKornNm, })); return set((state: comCodeState) => ({ code: { ...state.code, sggCd: sggCd, cityCd: cityCd, }, })); }, divCityCd: async(cd: number) => { set((state: comCodeState) => ({ code: { ...state.code, sggCd:state.code.sggCd.filter((item) => { return Number(item.val.toString().slice(0,2)) === cd }), }, })); }, }; };