hrms-user/src/modules/06_evaluate/stores/evaluationFunction.ts

218 lines
5.7 KiB
TypeScript
Raw Normal View History

2023-12-19 10:56:51 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useEvaluateStore } from "@/modules/06_evaluate/store";
2023-12-19 17:04:39 +07:00
const store = useEvaluateStore();
2023-12-19 10:56:51 +07:00
const mixin = useCounterMixin();
2025-06-06 13:50:04 +07:00
const { showLoader, hideLoader } = mixin;
2023-12-19 10:56:51 +07:00
2023-12-19 17:04:39 +07:00
/** function เช็คการยื่นข้อประเมิน*/
2023-12-19 10:56:51 +07:00
async function fetchCheckStatus() {
2023-12-19 17:04:39 +07:00
store.showLoadStatus = false;
2023-12-21 17:51:13 +07:00
// = 1;
2023-12-19 10:56:51 +07:00
showLoader();
await http
.get(config.API.evaluationCheckStatus())
.then((res) => {
2023-12-19 17:04:39 +07:00
const data = res.data.result;
store.tabMenu === "1"
? (store.evaluateId = data.expertId)
: (store.evaluateId = data.specialExpertId);
2023-12-20 14:23:27 +07:00
fetchCheckStep(store?.evaluateId);
2023-12-19 10:56:51 +07:00
})
.catch((err) => {
2025-06-06 13:50:04 +07:00
console.log(err);
2023-12-19 10:56:51 +07:00
})
.finally(() => {
hideLoader();
});
}
2023-12-20 14:23:27 +07:00
async function fetchCheckStep(id: string) {
if (id) {
await http
.get(config.API.evaluationCheckStep(id))
.then((res) => {
const data = res.data.result;
2023-12-19 17:04:39 +07:00
2023-12-20 14:23:27 +07:00
let step =
2023-12-21 17:51:13 +07:00
data.step === "CHECK_SPEC"
2023-12-20 14:23:27 +07:00
? 1
2023-12-21 17:51:13 +07:00
: data.step === "PREPARE_DOC_V1"
2023-12-20 14:23:27 +07:00
? 2
2023-12-21 17:51:13 +07:00
: data.step === "CHECK_DOC_V1"
2023-12-20 14:23:27 +07:00
? 3
2023-12-21 17:51:13 +07:00
: data.step === "WAIT_CHECK_DOC_V1"
2023-12-20 14:23:27 +07:00
? 4
2023-12-21 17:51:13 +07:00
: data.step === "ANNOUNCE_WEB"
2023-12-20 14:23:27 +07:00
? 5
2023-12-21 17:51:13 +07:00
: data.step === "PREPARE_DOC_V2"
2023-12-20 14:23:27 +07:00
? 6
2023-12-21 17:51:13 +07:00
: data.step === "WAIT_CHECK_DOC_V2"
2023-12-24 10:44:26 +07:00
? 7
: data.step === "CHECK_DOC_V2"
2023-12-20 14:23:27 +07:00
? 8
2023-12-21 17:51:13 +07:00
: data.step === "DONE"
2023-12-20 14:23:27 +07:00
? 9
: 1;
2023-12-21 17:51:13 +07:00
2023-12-22 16:29:12 +07:00
store.currentStep = step;
store.step = step;
2023-12-20 14:23:27 +07:00
})
.catch((err) => {
2025-06-06 13:50:04 +07:00
console.log(err);
2023-12-20 14:23:27 +07:00
})
.finally(() => {
store.showLoadStatus = true;
});
2023-12-21 17:51:13 +07:00
} else
((store.step = 1), (store.currentStep = 1)), (store.showLoadStatus = true);
2023-12-19 17:04:39 +07:00
}
2023-12-21 17:51:13 +07:00
async function saveEvaluation(formSpec: any, detail: any) {
2024-06-29 01:07:22 +07:00
const salaries = detail.salaries.map((e: any) => ({
2023-12-22 16:00:05 +07:00
amount: e.amount,
date: e.date,
mouthSalaryAmount: e.mouthSalaryAmount ? e.mouthSalaryAmount : 0,
posNo: e.posNo,
position: e.position,
positionSalaryAmount: e.positionSalaryAmount ? e.positionSalaryAmount : 0,
refCommandDate: e.refCommandDate,
refCommandNo: e.refCommandNo ? e.refCommandNo : "",
salaryClass: e.salaryClass ? e.salaryClass : "",
salaryRef: e.salaryRef ? e.salaryRef : "",
salaryStatus: e.salaryStatus ? e.salariesStatus : "",
}));
const educations = detail.educations.map((e: any) => ({
country: e.country,
degree: e.degree,
duration: e.duration,
durationYear: e.durationYear.toString(),
educationLevel: e.educationLevel,
endDate: e.endDate,
field: e.field,
finishDate: e.finishDate,
fundName: e.fundName,
gpa: e.gpa,
institute: e.institute,
isDate: e.isDate,
isEducation: e.isEducation,
other: e.other,
startDate: e.startDate,
}));
2023-12-21 17:51:13 +07:00
const form = {
userId: detail.id,
citizenId: detail.citizenId,
prefix: detail.prefix,
fullName: `${detail.firstName} ${detail.lastName}.`,
position: detail.position,
oc: detail.oc,
salary: detail.salary.toString(),
positionLevel: detail.positionLevel,
posNo: detail.posNo,
birthDate: detail.birthDate,
govAge: detail.govAge,
2023-12-22 17:03:21 +07:00
type: store.tabMenu === "1" ? "EXPERT" : "SPECIAL_EXPERT",
step: "PREPARE_DOC_V1",
2023-12-21 17:51:13 +07:00
isEducationalQft: formSpec.isEducationalQft,
isGovermantServiceHtr: formSpec.isGovermantServiceHtr,
isOperatingExp: formSpec.isOperatingExp,
isMinPeriodOfTenure: formSpec.isMinPeriodOfTenure,
isHaveSpecificQft: formSpec.isHaveSpecificQft,
isHaveProLicense: formSpec.isHaveProLicense,
isHaveMinPeriodOrHoldPos: formSpec.isHaveMinPeriodOrHoldPos,
reason: "",
2023-12-22 16:00:05 +07:00
educations: [...educations],
2023-12-21 17:51:13 +07:00
certificates: [...detail.certificates],
2023-12-22 16:00:05 +07:00
salaries: [...salaries],
2023-12-21 17:51:13 +07:00
trainings: [...detail.trainings],
assessments: [...detail.assessments],
2023-12-20 15:16:49 +07:00
};
2023-12-19 17:04:39 +07:00
showLoader();
await http
2023-12-21 17:51:13 +07:00
.post(config.API.evaluationCheckspec(), form)
2023-12-19 17:04:39 +07:00
.then((res) => {
fetchCheckStatus();
2023-12-19 17:04:39 +07:00
})
.catch((err) => {
2025-06-06 13:50:04 +07:00
console.log(err);
2023-12-19 17:04:39 +07:00
})
.finally(() => {
2023-12-20 14:23:27 +07:00
fetchCheckStep(store?.evaluateId);
hideLoader();
2023-12-19 17:04:39 +07:00
});
}
async function nextPrapare(type: string, body: any) {
showLoader();
await http
.put(config.API.evaluationPreparedoc(store.evaluateId, type), body)
2025-06-06 13:50:04 +07:00
.then((res) => {})
2023-12-19 17:04:39 +07:00
.catch((err) => {
2025-06-06 13:50:04 +07:00
console.log(err);
2023-12-19 17:04:39 +07:00
})
.finally(() => {
hideLoader();
2023-12-22 17:03:21 +07:00
fetchCheckStatus();
2023-12-19 17:04:39 +07:00
});
}
async function nextCheckDoc(type: string) {
showLoader();
await http
.put(config.API.evaluationCheckdoc(store.evaluateId, type))
2025-06-06 13:50:04 +07:00
.then((res) => {})
2023-12-19 17:04:39 +07:00
.catch((err) => {
2025-06-06 13:50:04 +07:00
console.log(err);
2023-12-19 17:04:39 +07:00
})
.finally(() => {
hideLoader();
2023-12-20 14:23:27 +07:00
fetchCheckStep(store?.evaluateId);
2023-12-19 17:04:39 +07:00
});
}
2023-12-19 10:56:51 +07:00
2024-06-29 01:07:22 +07:00
// async function nextCheckDoc2(data: any) {
// const body = {
// commanderAboveFullnameDoc2: data.commanderAboveFullname,
// commanderAbovePositionDoc2: data.commanderAbovePosition,
// commanderFullnameDoc2: data.commanderFullname,
// commanderPositionDoc2: data.commanderPosition,
// };
// showLoader();
// await http
// .put(config.API.evaluationCheckdocV1(store.evaluateId), body)
// .then((res) => {})
// .catch((err) => {})
// .finally(() => {
// hideLoader();
// fetchCheckStatus();
// });
// }
2023-12-22 16:00:05 +07:00
async function nextPrepareDoc2() {
2023-12-19 17:04:39 +07:00
showLoader();
await http
2023-12-22 16:00:05 +07:00
.put(config.API.evaluationPreparedocV2(store.evaluateId))
2023-12-19 17:04:39 +07:00
.then((res) => {})
.catch((err) => {})
.finally(() => {
hideLoader();
2023-12-22 16:00:05 +07:00
fetchCheckStatus();
2023-12-19 17:04:39 +07:00
});
2023-12-19 10:56:51 +07:00
}
2023-12-19 17:04:39 +07:00
export default {
fetchCheckStatus,
saveEvaluation,
nextPrapare,
nextCheckDoc,
2024-06-29 01:07:22 +07:00
// nextCheckDoc2,
2023-12-22 16:00:05 +07:00
nextPrepareDoc2,
2023-12-19 17:04:39 +07:00
};