Refactoring code module 03_recruiting

This commit is contained in:
STW_TTTY\stwtt 2024-09-17 15:56:06 +07:00
parent b223c2433e
commit 87e2e3b080
36 changed files with 6139 additions and 6335 deletions

View file

@ -1,4 +1,118 @@
<!-- card ใชสมครสอบ -->
<script setup lang="ts">
import { ref, onMounted, watch, type PropType } from "vue";
import { useQuasar } from "quasar";
import { useRoute } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import type {
DataOption,
Education,
} from "@/modules/03_recruiting/interface/index/Main";
import {
defaultEducation,
changeData,
} from "@/modules/03_recruiting/interface/index/Main";
import HeaderTop from "@/modules/03_recruiting/components/top.vue";
const props = defineProps({
status: {
type: String,
required: true,
},
form: {
type: Object,
required: true,
},
educationLevelOptions: {
type: Array as PropType<DataOption[]>,
required: true,
},
});
const $q = useQuasar();
const route = useRoute();
const edit = ref<boolean>(true);
const showEducationName = ref<boolean>(true);
const myform = ref<object | null>(null);
const candidateId = ref<string>(route.params.candidateId.toString());
const educationTypeOptions = ref<DataOption[]>([
{
name: "รัฐบาล",
id: "รัฐบาล",
},
{
name: "เอกชน",
id: "เอกชน",
},
]);
const mixin = useCounterMixin();
const { messageError, showLoader, hideLoader, date2Thai } = mixin;
const emit = defineEmits(["update:form"]);
watch(myform, async (count: any) => {
emit("update:form", count);
});
watch(defaultEducation, async (count: Education) => {
await changeData("education", count);
});
onMounted(async () => {
await fetchData();
});
const fetchData = async () => {
showLoader();
await http
.get(config.API.candidateEducation(candidateId.value))
.then((res) => {
const data = res.data.result;
if (data != null) {
defaultEducation.value.educationLevelExamId = data.educationLevelExamId;
defaultEducation.value.educationName = data.educationName;
defaultEducation.value.educationMajor = data.educationMajor;
defaultEducation.value.educationLocation = data.educationLocation;
defaultEducation.value.educationType = data.educationType;
defaultEducation.value.educationEndDate = data.educationEndDate;
defaultEducation.value.educationScores = data.educationScores;
defaultEducation.value.educationLevelHighId = data.educationLevelHighId;
checkInputName();
}
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
const checkInputName = () => {
showEducationName.value =
props.educationLevelOptions.filter(
(x) =>
x.id == defaultEducation.value.educationLevelExamId &&
(x.name == "ปริญญาตรี" || x.name == "ปริญญาโท" || x.name == "ปริญญาเอก")
).length == 0
? false
: true;
};
const getClass = (val: boolean) => {
return {
"full-width inputgreen cursor-pointer": val,
"full-width cursor-pointer": !val,
};
};
</script>
<template>
<HeaderTop
v-model:edit="edit"
@ -176,114 +290,3 @@
</div>
</q-form>
</template>
<script setup lang="ts">
import { ref, onMounted, watch, PropType } from "vue";
import http from "@/plugins/http";
import config from "@/app.config";
import type {
DataOption,
Education,
} from "@/modules/03_recruiting/interface/index/Main";
import {
defaultEducation,
changeData,
} from "@/modules/03_recruiting/interface/index/Main";
import HeaderTop from "@/modules/03_recruiting/components/top.vue";
import { useRoute } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
const props = defineProps({
status: {
type: String,
required: true,
},
form: {
type: Object,
required: true,
},
educationLevelOptions: {
type: Array as PropType<DataOption[]>,
required: true,
},
});
const $q = useQuasar();
const edit = ref<boolean>(true);
const showEducationName = ref<boolean>(true);
const myform = ref<any>({});
const route = useRoute();
const candidateId = ref<string>(route.params.candidateId.toString());
const educationTypeOptions = ref<any>([
{
name: "รัฐบาล",
id: "รัฐบาล",
},
{
name: "เอกชน",
id: "เอกชน",
},
]);
const mixin = useCounterMixin();
const { messageError, showLoader, hideLoader, date2Thai } = mixin;
const emit = defineEmits(["update:form"]);
watch(myform, async (count: any, prevCount: any) => {
emit("update:form", count);
});
watch(defaultEducation, async (count: Education, prevCount: Education) => {
await changeData("education", count);
});
onMounted(async () => {
await fetchData();
});
const fetchData = async () => {
showLoader();
await http
.get(config.API.candidateEducation(candidateId.value))
.then((res) => {
const data = res.data.result;
if (data != null) {
defaultEducation.value.educationLevelExamId = data.educationLevelExamId;
defaultEducation.value.educationName = data.educationName;
defaultEducation.value.educationMajor = data.educationMajor;
defaultEducation.value.educationLocation = data.educationLocation;
defaultEducation.value.educationType = data.educationType;
defaultEducation.value.educationEndDate = data.educationEndDate;
defaultEducation.value.educationScores = data.educationScores;
defaultEducation.value.educationLevelHighId = data.educationLevelHighId;
checkInputName();
}
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
const checkInputName = () => {
showEducationName.value =
props.educationLevelOptions.filter(
(x) =>
x.id == defaultEducation.value.educationLevelExamId &&
(x.name == "ปริญญาตรี" || x.name == "ปริญญาโท" || x.name == "ปริญญาเอก")
).length == 0
? false
: true;
};
const getClass = (val: boolean) => {
return {
"full-width inputgreen cursor-pointer": val,
"full-width cursor-pointer": !val,
};
};
</script>