Files
frontend/apps/wr/app/store/common/searchCode/index.ts
T
yschoi d3748e8609
iipbs_wr / build (push) Waiting to run
dmdInfoId 중복 제거
2025-07-14 21:34:26 +09:00

185 lines
4.4 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";
import toast from "react-hot-toast";
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: ""
},
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) => void;
updateDemandCompany: (data: DemandCompType) => void;
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) {
toast.success('수요처가 등록되었습니다. ')
set((state: comFcltState) => {
return {
...state,
dmdIsSucees: "success"
}
});
}
} catch (err) {
console.log(err);
toast.error('수요처가 등록 오류입니다.. ')
}
},
updateDemandCompany: async (data: DemandCompType) => {
try {
const response = await putFectch("/reuseFc/request", data);
let message = "";
if (response.status === 200) {
message = "success";
toast.success('수요처 정보가 변경되었습니다. ' )
} else {
message = "fail";
}
set((state: comFcltState) => {
return {
...state,
dmdIsSucees: message
}
});
} catch (err) {
console.log(err);
toast.success('수요처 정보가 오류입니다. ' )
}
},
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);
}
},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)
}
}
};
};