ทะเบียนประวัติ: ประวัติส่วนตัว (GET, PUT)

This commit is contained in:
puriphatt 2024-03-22 19:20:35 +07:00
parent 93fc17cea0
commit 79f08f7569
5 changed files with 409 additions and 454 deletions

View file

@ -1,92 +1,123 @@
import { ref, computed } from "vue";
import { ref } from "vue";
import { defineStore } from "pinia";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import type {
Gender,
Religion,
Relationship,
BloodGroup,
} from "@/modules/04_registryNew/interface/response/Profile";
export const useProfileDataStore = defineStore("profile", () => {
const isVerified = ref<boolean>(false);
const isEdit = ref<boolean>(false);
const emplployeeClass = ref<string | null>("");
interface profile {
main: { columns: String[] };
education: { columns: String[] };
oldName: { columns: String[] };
certicate: { columns: String[] };
train: { columns: String[] };
insignia: { columns: String[] };
coined: { columns: String[] };
assessment: { columns: String[] };
salary: { columns: String[] };
discipline: { columns: String[] };
leave: { columns: String[] };
talent: { columns: String[] };
work: { columns: String[] };
record: { columns: String[] };
other: { columns: String[] };
document: { columns: String[] };
const $q = useQuasar();
const mixin = useCounterMixin();
const {
showLoader,
hideLoader,
date2Thai,
messageError,
convertDate,
dateToISO,
} = mixin;
const genderOp = ref<Gender[]>([]);
const religionOp = ref<Religion[]>([]);
const relationshipOp = ref<Relationship[]>([]);
const bloodGroupOp = ref<BloodGroup[]>([]);
const prefixOp = ref<string[]>(["นาย", "นาง", "นางสาว"]);
function calculateAge(birthDate: Date): string {
const birthDateTimeStamp = new Date(birthDate).getTime();
const now = new Date();
const diff = now.getTime() - birthDateTimeStamp;
const ageDate = new Date(diff);
const years = ageDate.getUTCFullYear() - 1970;
const months = ageDate.getUTCMonth();
const days = ageDate.getUTCDate() - 1;
if (years > 60) {
return "อายุเกิน 60 ปี";
}
return `${years} ปี ${months} เดือน ${days} วัน`;
}
const birthDate = ref<Date>(new Date());
const retireText = ref<string | null>(null);
const changeRetireText = (val: string | null) => {
retireText.value = val;
};
const changeBirth = (val: Date) => {
birthDate.value = val;
};
const profileData = ref<profile>({
main: { columns: [] },
education: { columns: [] },
oldName: { columns: [] },
certicate: { columns: [] },
train: { columns: [] },
insignia: { columns: [] },
coined: { columns: [] },
assessment: { columns: [] },
salary: { columns: [] },
discipline: { columns: [] },
leave: { columns: [] },
talent: { columns: [] },
work: { columns: [] },
record: { columns: [] },
other: { columns: [] },
document: { columns: [] },
});
const changeProfileColumns = (system: String, val: String[]) => {
if (system == "main") profileData.value.main.columns = val;
if (system == "education") profileData.value.education.columns = val;
if (system == "oldName") profileData.value.oldName.columns = val;
if (system == "certicate") profileData.value.certicate.columns = val;
if (system == "train") profileData.value.train.columns = val;
if (system == "insignia") profileData.value.insignia.columns = val;
if (system == "coined") profileData.value.coined.columns = val;
if (system == "assessment") profileData.value.assessment.columns = val;
if (system == "salary") profileData.value.salary.columns = val;
if (system == "discipline") profileData.value.discipline.columns = val;
if (system == "leave") profileData.value.leave.columns = val;
if (system == "talent") profileData.value.talent.columns = val;
if (system == "work") profileData.value.work.columns = val;
if (system == "record") profileData.value.record.columns = val;
if (system == "other") profileData.value.other.columns = val;
if (system == "document") profileData.value.document.columns = val;
localStorage.setItem("profile", JSON.stringify(profileData.value));
};
if (localStorage.getItem("profile") !== null) {
profileData.value = JSON.parse(localStorage.getItem("profile") || "{}");
async function getGender() {
showLoader();
await http
.get(config.API.profileNewGender)
.then((res) => {
genderOp.value = res.data.result;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
const isLoad = ref<number>(0);
async function getRelationship() {
showLoader();
await http
.get(config.API.profileNewRelationship)
.then((res) => {
relationshipOp.value = res.data.result;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
async function getReligion() {
showLoader();
await http
.get(config.API.profileNewReligion)
.then((res) => {
religionOp.value = res.data.result;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
async function getBloodGroup() {
showLoader();
await http
.get(config.API.profileNewBloodGroup)
.then((res) => {
bloodGroupOp.value = res.data.result;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
return {
isLoad,
isVerified,
isEdit,
profileData,
changeProfileColumns,
birthDate,
changeBirth,
retireText,
changeRetireText,
emplployeeClass,
prefixOp,
genderOp,
religionOp,
relationshipOp,
bloodGroupOp,
calculateAge,
getGender,
getRelationship,
getReligion,
getBloodGroup,
};
});