Files
frontend/apps/wr/app/store/common/searchCode/index.ts
T

190 lines
4.8 KiB
TypeScript

import {
fetchType,
getFetch,
postFectch,
putFectch,
} from "@/components/lib/api";
import type { pubHasuType } from "../../ruseFcltMng/fcltReg/pbnstReg/type";
import type { DemandCompType } from "@common/business_components/ui/sdmInsertForm/form";
import type { conCostFeeType, rateFeeType } from "./type";
export const comFcltStateExport: comFcltState = {
searchFclts: [] as pubHasuType[],
demandCompList: [],
checkDemand: {
index: 0,
dmdInfoId: "",
bzmnNo: "",
dmdCoNm: "",
daddr: "",
telno: "",
rgtr: "",
useUsgCd: "",
ctpvCd: "",
sggCd: "",
dmdAplyPswd: "",
wntUntprc: 0,
dmndTmng: "",
dmndQty: 0,
grssClfg: 0,
tn: 0,
combResdch: 0,
tph: 0,
trbt: 0,
ph: 0,
blgcOxygDmndQnt: 0,
clIonQnt: 0,
smll: 0,
cdtnv: 0,
crmty: 0,
rmrk: "",
reqDt: "",
zip: "",
},
constCostRes:[],
rateFeeRes:[],
};
export type comFcltType = comFcltState & comFcltActions;
export type comFcltState = {
searchFclts: pubHasuType[];
demandCompList: DemandCompType[];
checkDemand: DemandCompType;
constCostRes:conCostFeeType[], // 표준사업비
rateFeeRes:rateFeeType[],
};
type comFcltActions = {
getSwtrmtFcltNm: (searchNm: string) => void;
getDemandCompList: (searchNm: string, cnt: number) => void;
regDemandCompany: (data: DemandCompType) => Promise<string>;
updateDemandCompany: (data: DemandCompType) => Promise<string>;
getConstCostFee: (year: string) => void;
getRateFee: (year: string) => void;
};
export const comFcltSearchAction: (set: any) => comFcltActions = (set: any) => {
return {
getSwtrmtFcltNm: async (searchNm: string) => {
const fcltNm = await getFetch(
"common",
`/prcsFclt/info/1/11/${searchNm}`
);
const searchFclts: pubHasuType[] = fcltNm.map((item: any) => ({
bscFctCd: item.bscFctCd,
sido: item.sido,
gugun: item.gugun,
bscFctNm: item.bscFctNm,
addr: item.addr,
fctCpc: item.fctCpc,
}));
set((state: comFcltState) => ({
...state,
searchFclts: searchFclts,
}));
},
getDemandCompList: async (searchNm: string, cnt: number) => {
const coList = await getFetch(
fetchType.WR,
`/reuseFc/request/${searchNm}/${cnt}`
);
if(coList&&coList.length>0){
set((state: comFcltState) => {
return (state.demandCompList = [...coList]);
});
}
},
regDemandCompany: async (data: DemandCompType) => {
try {
const response = await postFectch(
"/reuseFc/request",
data,
fetchType.WR
);
if (response.status === 200) {
set((state: comFcltState) => {
return {
...state,
dmdIsSucees: "success"
}
});
return "수요처가 등록되었습니다.";
}
return "수요처 등록에 실패하였습니다.";
} catch (err) {
console.log(err);
return "수요처 등록 중 오류가 발생했습니다.";
}
},
updateDemandCompany: async (data: DemandCompType) => {
try {
const response = await putFectch("/reuseFc/request", data);
let message = "";
if (response.status === 200) {
message = "success";
} else {
message = "fail";
}
set((state: comFcltState) => {
return {
...state,
dmdIsSucees: message
}
});
if (response.status === 200) {
return "수요처 정보가 변경되었습니다.";
}
return "수요처 정보 변경에 실패하였습니다.";
} catch (err) {
console.log(err);
return "수요처 정보 변경 중 오류가 발생했습니다.";
}
},
// 요율정보 조회 : ONSEMIRO_NEW.EM_STD_COST_INC_EXP_RT 설치관리표준사업비 부대경비요율
getRateFee: async (year: string) => {
try {
const url = `/prcsFclt/CstRt/${year}`;
const rateFeeRes = await getFetch(fetchType.COMMON, url);
set((state: comFcltState) => {
return {
...state,
rateFeeRes: rateFeeRes
}
});
} catch (e) {
console.log(" error ", e);
}
},
// 공사금액 조회 : ONSEMIRO_NEW.EM_STD_COST_REUSE 설치관리표준사업비 재이용시설 공사비
getConstCostFee: async (year: string) => {
try {
const url = `/prcsFclt/CstRuse/${year}`;
const constCost = await getFetch(fetchType.COMMON, url);
set((state: comFcltState) => {
return {
...state,
constCostRes: constCost
}
});
} catch (e) {
console.log('getConstCostFee ', e)
}
}
};
};