diff --git a/src/interface/Main.ts b/src/interface/Main.ts index d73d63f..6d31fa4 100644 --- a/src/interface/Main.ts +++ b/src/interface/Main.ts @@ -10,7 +10,7 @@ interface ProfileData { posNo: string; profileId: string; citizenId?: string; - salary?: number|null; + salary?: number | null; birthDate?: string; keycloakId?: string; org?: string; @@ -35,4 +35,36 @@ interface InformationData { email: string; } -export type { ProfileData, InformationData }; +interface DataProfile { + profileId: string | null; + prefix: string; + rank: string; + firstName: string; + lastName: string; + citizenId: string; + position: string; + posMaster: string | null; + posLevelName: string | null; + posLevelRank: string | null; + posLevelId: string | null; + posTypeName: string | null; + posTypeRank: string | null; + posTypeId: string | null; + posExecutiveName: string; + posExecutivePriority: string | null; + posExecutiveId: string | null; + rootId: string | null; + root: string; + child1Id: string | null; + child1: string | null; + child2Id: string | null; + child2: string | null; + child3Id: string | null; + child3: string | null; + child4Id: string | null; + child4: string | null; + node: string | null; + nodeId: string | null; +} + +export type { ProfileData, InformationData, DataProfile }; diff --git a/src/modules/06_evaluate/views/EvaluateMain.vue b/src/modules/06_evaluate/views/EvaluateMain.vue index 6c44144..b9bf856 100644 --- a/src/modules/06_evaluate/views/EvaluateMain.vue +++ b/src/modules/06_evaluate/views/EvaluateMain.vue @@ -86,7 +86,6 @@ async function fetchEvaluteList() { ); total.value = res.data.result.total; store.fetchEvaluateList(res.data.result.data); - await getProfileCheck(); }) .catch((err) => { messageError($q, err); @@ -191,6 +190,7 @@ watch( /** hook lifecycle*/ onMounted(async () => { await fetchEvaluteList(); + await getProfileCheck(); }); diff --git a/src/modules/08_KPI/store.ts b/src/modules/08_KPI/store.ts index 25eb139..f9fc0a0 100644 --- a/src/modules/08_KPI/store.ts +++ b/src/modules/08_KPI/store.ts @@ -2,6 +2,7 @@ import { defineStore } from "pinia"; import { ref, reactive } from "vue"; import type { DataOptions } from "./interface/index/Main"; import type { FormQuery } from "@/modules/08_KPI/interface/request/index"; +import type { DataProfile } from "@/interface/Main"; export const useKpiDataStore = defineStore("KPIDate", () => { const mainRowData = ref(); @@ -17,7 +18,7 @@ export const useKpiDataStore = defineStore("KPIDate", () => { const selected = ref([]); const work = ref(false); const tabMain = ref(""); - const dataProfile = ref({ + const dataProfile = ref({ profileId: null, prefix: "", rank: "", diff --git a/src/modules/08_KPI/views/form.vue b/src/modules/08_KPI/views/form.vue index 5ee322d..b29ab9c 100644 --- a/src/modules/08_KPI/views/form.vue +++ b/src/modules/08_KPI/views/form.vue @@ -478,15 +478,17 @@ async function fetchProfileEvaluator(id: string) { /** ดึงข้อมูลโปรไฟล์ */ async function getProfile() { - await http - .get(config.API.profilePosition()) - .then(async (res) => { - const data = await res.data.result; - store.dataProfile = await data; - }) - .catch((e) => { - messageError($q, e); - }); + if (store.dataProfile.profileId) { + await http + .get(config.API.profilePosition()) + .then(async (res) => { + const data = await res.data.result; + store.dataProfile = await data; + }) + .catch((e) => { + messageError($q, e); + }); + } } async function downloadReport() { diff --git a/src/modules/08_KPI/views/main.vue b/src/modules/08_KPI/views/main.vue index 5712266..fd8079b 100644 --- a/src/modules/08_KPI/views/main.vue +++ b/src/modules/08_KPI/views/main.vue @@ -9,6 +9,7 @@ import http from "@/plugins/http"; import { useCounterMixin } from "@/stores/mixin"; import { useKpiDataStore } from "@/modules/08_KPI/store"; +import type { DataProfile } from "@/interface/Main"; import type { DataOptions, MainListKpi, @@ -285,26 +286,34 @@ function onSubmit() { } /** ดึงข้อมูล */ -function getProfile() { - http - .get(config.API.profilePosition()) - .then(async (res) => { - const data = await res.data.result; - store.dataProfile = data; +async function getProfile() { + if (store.dataProfile.profileId) { + assignProfileToForm(store.dataProfile); + } else { + await http + .get(config.API.profilePosition()) + .then(async (res) => { + const data = await res.data.result; + store.dataProfile = data; + assignProfileToForm(data); + }) + .catch((e) => { + messageError($q, e); + }); + } +} - formRound.profileId = data.profileId; - formRound.prefix = data.prefix; - formRound.firstName = data.firstName; - formRound.lastName = data.lastName; - formRound.position = data.position; - formRound.posLevelName = data.posLevelName; - formRound.posTypeName = data.posTypeName; - formRound.posExecutiveName = data.posExecutiveName; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => {}); +function assignProfileToForm(profile: DataProfile) { + formRound.profileId = profile.profileId ? profile.profileId : ""; + formRound.prefix = profile.prefix ? profile.prefix : ""; + formRound.firstName = profile.firstName ? profile.firstName : ""; + formRound.lastName = profile.lastName ? profile.lastName : ""; + formRound.position = profile.position ? profile.position : ""; + formRound.posLevelName = profile.posLevelName ? profile.posLevelName : ""; + formRound.posTypeName = profile.posTypeName ? profile.posTypeName : ""; + formRound.posExecutiveName = profile.posExecutiveName + ? profile.posExecutiveName + : ""; } /** เช็ครอบการประเมิน ปิด */ diff --git a/src/modules/09_scholarship/views/main.vue b/src/modules/09_scholarship/views/main.vue index be093ef..ad8856d 100644 --- a/src/modules/09_scholarship/views/main.vue +++ b/src/modules/09_scholarship/views/main.vue @@ -5,6 +5,7 @@ import { useQuasar, type QTableProps } from "quasar"; import http from "@/plugins/http"; import config from "@/app.config"; +import { useDataStore } from "@/stores/data"; import { useCounterMixin } from "@/stores/mixin"; import type { @@ -17,7 +18,7 @@ const { showLoader, hideLoader, messageError } = mixin; const router = useRouter(); const $q = useQuasar(); - +const dataStore = useDataStore(); const profilId = ref(""); const currentPage = ref(1); const page = ref(1); @@ -123,19 +124,22 @@ function onEdit(id: string) { // ); async function getProfileId() { - showLoader(); - await http - .get(config.API.profilePosition()) - .then(async (res) => { - profilId.value = res.data.result.profileId; - await getData(); - }) - .catch((e) => { + if (dataStore.profileId) { + profilId.value = dataStore.profileId; + } else { + showLoader(); + try { + const res = await http.get(config.API.profilePosition()); + dataStore.profileId = res.data.result.profileId; + profilId.value = dataStore.profileId; + } catch (e) { messageError($q, e); - }) - .finally(() => { + } finally { hideLoader(); - }); + } + } + + await getData(); } function convertType(val: string) { diff --git a/src/modules/10_registry/components/DialogAddRequestEdit.vue b/src/modules/10_registry/components/DialogAddRequestEdit.vue index 81b06d0..7df4b27 100644 --- a/src/modules/10_registry/components/DialogAddRequestEdit.vue +++ b/src/modules/10_registry/components/DialogAddRequestEdit.vue @@ -16,7 +16,7 @@ import { useCounterMixin } from "@/stores/mixin"; * use */ const $q = useQuasar(); -const link = ref('') +const link = ref(""); const store = useRequestEditStore(); const dataStore = useDataStore(); const { dialogConfirm, showLoader, hideLoader, messageError, success } = @@ -167,20 +167,16 @@ function filterOption(val: string, update: Function) { /** * function fetch profileId */ -function fetchProfile() { - showLoader(); - http - .get(config.API.profilePosition()) - .then((res) => { - const data = res.data.result; - profileId.value = data.profileId; - }) - .catch((err) => { - messageError($q, err); - }) - .finally(() => { - hideLoader(); - }); +async function fetchProfile() { + try { + isReadOnly.value = dataStore.officerType === "OFFICER"; + const res = await http.get(config.API.profilePosition()); + return res.data.result.profileId; + } catch (err) { + messageError($q, err); + } finally { + hideLoader(); + } } /** popup รายละเอียดของ ขอปรับปรุงข้อมูลจากกรมการปกครอง */ @@ -194,7 +190,10 @@ function onInfo(val: string) { watch( () => modal.value, async () => { - modal.value && fetchProfile(); + profileId.value = dataStore.profileId + ? dataStore.profileId + : await fetchProfile(); + link.value = await dataStore.getProFileType(); } ); diff --git a/src/modules/11_probation/views/main.vue b/src/modules/11_probation/views/main.vue index 86245ea..c27501a 100644 --- a/src/modules/11_probation/views/main.vue +++ b/src/modules/11_probation/views/main.vue @@ -23,7 +23,7 @@ const { showLoader, hideLoader, date2Thai, - onSearchDataTable + onSearchDataTable, } = mixin; const filter = ref(""); diff --git a/src/stores/data.ts b/src/stores/data.ts index 29e9851..0da8015 100644 --- a/src/stores/data.ts +++ b/src/stores/data.ts @@ -16,6 +16,7 @@ export const useDataStore = defineStore("dataMain", () => { const { messageError, showLoader, hideLoader, findPosMasterNo, findOrgName } = mixin; // ref() คือการประกาศ state เหมือน vuex + const profileId = ref(""); const formData = reactive({ profileId: "", rank: "", @@ -101,6 +102,7 @@ export const useDataStore = defineStore("dataMain", () => { async function getData(dataPerson: any) { const data = await dataPerson; + profileId.value = data.profileId; isProbation.value = data.isProbation; formData.profileId = data.profileId; formData.rank = data.rank; @@ -166,6 +168,7 @@ export const useDataStore = defineStore("dataMain", () => { officerLink, getProFileType, dataProfile, + profileId, }; });