From e92997302b40fd56a44d14cad3a70290d4f94ea3 Mon Sep 17 00:00:00 2001 From: setthawutttty Date: Wed, 29 Jan 2025 09:56:04 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=AD=E0=B8=B1?= =?UTF-8?q?=E0=B8=9E=E0=B9=84=E0=B8=9F=E0=B8=A5=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/registry/api.registry.ts | 5 + .../detail/Achievement/03_Insignia.vue | 197 +++++++++++++----- .../Achievement/04_DeclarationHonor.vue | 83 +++++++- .../04_PerformSpecialWork.vue | 85 +++++++- .../components/detail/Other/03_Document7.vue | 10 +- .../PersonalInformation/06_SpecialSkill.vue | 85 +++++++- .../04_registryPerson/interface/index/Main.ts | 39 ++++ .../interface/index/performSpecialWork.ts | 1 + .../interface/request/DeclarationHonor.ts | 1 + .../interface/request/Insignia.ts | 1 + .../interface/response/DeclarationHonor.ts | 1 + .../interface/response/Insignia.ts | 1 + .../04_registryPerson/stores/insignia.ts | 47 +++-- 13 files changed, 448 insertions(+), 108 deletions(-) diff --git a/src/api/registry/api.registry.ts b/src/api/registry/api.registry.ts index b4042f38d..60bf53e6a 100644 --- a/src/api/registry/api.registry.ts +++ b/src/api/registry/api.registry.ts @@ -1,6 +1,7 @@ import env from "../index"; const registryNew = `${env.API_URI}/org/profile`; +const org = `${env.API_URI}/org`; const metadata = `${env.API_URI}/org/metadata/`; export default { @@ -42,6 +43,10 @@ export default { profileNewInsign: (type: string) => `${registryNew}${type}/insignia`, profileNewInsignByProfileId: (profileId: string, type: string) => `${registryNew}${type}/insignia/${profileId}`, + + orgInsigniaActive: () => + `${org}/insignia/insignia-type/active`, + profileNewInsignById: (dataId: string, type: string) => `${registryNew}${type}/insignia/${dataId}`, profileNewInsignHisById: (dataId: string, type: string) => diff --git a/src/modules/04_registryPerson/components/detail/Achievement/03_Insignia.vue b/src/modules/04_registryPerson/components/detail/Achievement/03_Insignia.vue index 786cc67b9..bde2c4bcc 100644 --- a/src/modules/04_registryPerson/components/detail/Achievement/03_Insignia.vue +++ b/src/modules/04_registryPerson/components/detail/Achievement/03_Insignia.vue @@ -15,6 +15,9 @@ import type { DataOption, DataOptionInsignia, InsigniaOps, + InsigniasType, + InsigniasTypeSub, + ResFileData, } from "@/modules/04_registryPerson/interface/index/Main"; import type { RequestItemsObject } from "@/modules/04_registryPerson/interface/request/Insignia"; import type { ResponseObject } from "@/modules/04_registryPerson/interface/response/Insignia"; @@ -37,7 +40,9 @@ const { onSearchDataTable, } = mixin; -const fileUpload = ref(); +const isUpload = ref(false); +const fileUpload = ref(null); +const fileData = ref(null); const uploadUrl = ref(""); /** props*/ const isLeave = defineModel("isLeave", { @@ -76,8 +81,10 @@ const OpsFilter = ref({ insigniaOptions: [], }); -const insigniaOptions = ref([]); -const insigniaOptionsMain = ref([]); +const insigniaOptions = ref([]); +const insigniaOptionsMain = ref([]); +const insigniaOptionsName = ref([]); +const insigniaOptionsNameMain = ref([]); //ต้วลือกรายการครื่องราช const Ops = ref({ insigniaOptions: [], @@ -118,7 +125,7 @@ const columns = ref([ field: "insigniaId", headerStyle: "font-size: 14px", style: "font-size: 14px", - format: (v) => Ops.value.insigniaOptions.find((r) => r.id === v)?.name, + format: (v) => store.allNameInsignia.find((r) => r.id === v)?.name, sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -305,7 +312,7 @@ const columnsHistory = ref([ field: "insigniaId", headerStyle: "font-size: 14px", style: "font-size: 14px", - format: (v) => Ops.value.insigniaOptions.find((r) => r.id === v)?.name, + format: (v) => store.allNameInsignia.find((r) => r.id === v)?.name, sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -487,18 +494,21 @@ async function fetchData() { } } -/** fetch ข้อมูลเครื่องราชอิสริยาภรณ์*/ -async function fetchInsignia() { +/** ดึง */ +async function getInsigniaActive() { showLoader(); - try { - const res = await http.get(config.API.insigniaOrg); - const data = res.data.result; - mapInsigniaOption(data); - } catch (error) { - messageError($q, error); - } finally { - hideLoader(); - } + http + .get(config.API.orgInsigniaActive()) + .then((res) => { + const data = res.data.result; + mapInsigniaOption(data); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); } /** @@ -514,15 +524,18 @@ async function addEditData(editStatus: boolean = false) { const method = editStatus ? "patch" : "post"; const reqBody: RequestItemsObject = { ...insigniaForm, + isUpload: !isEdit.value ? undefined : isUpload.value, profileEmployeeId: !editStatus && empType.value !== "" ? profileId.value : undefined, + profileId: !editStatus && empType.value === "" ? profileId.value : undefined, + }; try { await http[method](url, reqBody).then(async (res) => { - if (fileUpload.value && res.data.result) { - await uploadProfile(res.data.result); + if ((fileUpload.value && id.value) || res.data.result) { + await uploadProfile(id.value); } }); @@ -574,19 +587,37 @@ async function uploadFileURL(uploadUrl: string, file: any) { "Content-Type": file.type, }, }) - .then(() => { - fileUpload.value = undefined; + .then(async (res) => { + if (res.status == 200) { + await isUploadFn(); + } + fileUpload.value = null; }) .catch((err) => { messageError($q, err); }); } +async function isUploadFn() { + await http + .patch(config.API.profileNewInsignById(id.value, empType.value), { + isUpload: fileUpload.value ? true : false, + }) + .then(async (res) => {}) + + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); +} + /** * ฟังก์ชันโหลไฟลเอกสารหลักฐาน * @param id รายการที่ต้องการโหลด */ - async function onDownloadFile(id: string) { +async function onDownloadFile(id: string, isLoad: boolean = true) { showLoader(); await http .get( @@ -599,8 +630,11 @@ async function uploadFileURL(uploadUrl: string, file: any) { ) ) .then(async (res) => { - const data = res.data.downloadUrl; - window.open(data, "_blank"); + const data = res.data; + fileData.value = data; + if (isLoad) { + window.open(data.downloadUrl, "_blank"); + } }) .catch((err) => { messageError($q, err); @@ -631,13 +665,28 @@ function onClickOpenDialog(editStatus: boolean = false, row?: ResponseObject) { insigniaForm.refCommandDate = row.refCommandDate; insigniaForm.refCommandNo = row.refCommandNo; insigniaForm.note = row.note; + isUpload.value = row.isUpload; - const insigniaTypeFilter = insigniaOptionsMain.value.filter( - (r: any) => r.typeId === insigniaType.value + if (isUpload.value) { + onDownloadFile(row.id, false); + } + const list = store.insigniaTypeOpMain; + + const insigniaTypeFilter = list.filter( + (r: InsigniasType) => r.id === insigniaType.value ); if (insigniaTypeFilter.length > 0) { - OpsFilter.value.insigniaOptions = insigniaTypeFilter; - insigniaOptions.value = OpsFilter.value.insigniaOptions; + const type = insigniaTypeFilter; + const name = insigniaTypeFilter[0].insignias.map( + (item: InsigniasTypeSub) => ({ + ...item, + name: `${item.name} (${item.shortName})`, + }) + ); + insigniaOptions.value = type; + insigniaOptionsMain.value = type; + insigniaOptionsName.value = name; + insigniaOptionsNameMain.value = name; } } else { clearData(); @@ -687,29 +736,46 @@ function onSubmit() { * @param refData type ที่กำหนด ของ input นั้นๆ */ function filterSelector(val: string, update: Function, refData: string) { - switch (refData) { - case "insigniaOptions": - update(() => { - insigniaOptions.value = OpsFilter.value.insigniaOptions.filter( - (v: DataOption) => v.name.indexOf(val) > -1 - ); - }); - break; - default: - break; + if (refData == "type") { + update(() => { + insigniaOptions.value = store.insigniaTypeOpMain.filter( + (v: DataOption) => v.name.indexOf(val) > -1 + ); + }); + } else if (refData == "insigniaOptions") { + update(() => { + insigniaOptionsName.value = insigniaOptionsNameMain.value.filter( + (v: DataOption) => v.name.indexOf(val) > -1 + ); + }); } } /** ค้นหาลำดับชั้น*/ -function insigniaTypeSelection(check: boolean) { +function insigniaTypeSelection(check: boolean, id: string) { if (check) { insigniaForm.insigniaId = ""; - } - const insigniaTypeFilter = insigniaOptionsMain.value.filter( - (r: any) => r.typeId === insigniaType.value - ); - if (insigniaTypeFilter.length > 0) { - OpsFilter.value.insigniaOptions = insigniaTypeFilter; + const data = store.insigniaTypeOpMain.find( + (item: InsigniasType) => item.id == id + ); + if (data) { + const listData = data.insignias.map((item: InsigniasTypeSub) => ({ + id: item.id, + createdAt: item.createdAt, + createdUserId: item.createdUserId, + lastUpdatedAt: item.lastUpdatedAt, + lastUpdateUserId: item.lastUpdateUserId, + createdFullName: item.createdFullName, + lastUpdateFullName: item.lastUpdateFullName, + name: `${item.name} (${item.shortName})`, + shortName: item.shortName, + level: item.level, + isActive: item.isActive, + note: item.note, + insigniaTypeId: item.insigniaTypeId, + })); + insigniaOptionsNameMain.value = listData; + } } } @@ -729,7 +795,9 @@ function clearData() { insigniaForm.refCommandNo = ""; insigniaForm.refCommandDate = null; insigniaForm.note = ""; - fileUpload.value = undefined; + fileUpload.value = null; + isUpload.value = false; + fileData.value = null; } function serchDataTable() { @@ -751,10 +819,9 @@ function serchDataTableHistory() { /** ทำงานเมื่อ Components ถูกเรียกใช้งาน*/ onMounted(async () => { await fetchData(); - store.insigniaOption.length === 0 ? await fetchInsignia() : ""; - Ops.value.insigniaOptions = store.insigniaOption; + store.insigniaTypeOpMain.length === 0 ? await getInsigniaActive() : ""; - insigniaOptionsMain.value = store.insigniaOption; + insigniaOptionsMain.value = store.insigniaTypeOpMain; insigniaOptions.value = store.insigniaOption; }); @@ -1064,12 +1131,12 @@ onMounted(async () => { v-model="insigniaType" class="inputgreen" :label="`${'ลำดับชั้น'}`" - :options="store.insigniaTypeOp" + :options="insigniaOptions" :rules="[(val:string) => !!val || `${'กรุณาเลือกลำดับชั้น'}`]" @filter="(inputValue:string, - doneFn:Function) => filterSelector(inputValue, doneFn,'insigniaOptions' + doneFn:Function) => filterSelector(inputValue, doneFn,'type' ) " - @update:modelValue="insigniaTypeSelection(true)" + @update:modelValue="(val:any)=>insigniaTypeSelection(true,val)" > + + + + {{ fileData?.fileName }} + +
+ + + +
+
+
+
diff --git a/src/modules/04_registryPerson/components/detail/Achievement/04_DeclarationHonor.vue b/src/modules/04_registryPerson/components/detail/Achievement/04_DeclarationHonor.vue index 98649d300..bbd549ce8 100644 --- a/src/modules/04_registryPerson/components/detail/Achievement/04_DeclarationHonor.vue +++ b/src/modules/04_registryPerson/components/detail/Achievement/04_DeclarationHonor.vue @@ -11,7 +11,10 @@ import config from "@/app.config"; import type { QTableProps } from "quasar"; import type { RequestItemsObject } from "@/modules/04_registryPerson/interface/request/DeclarationHonor"; -import type { DataOption } from "@/modules/04_registryPerson/interface/index/Main"; +import type { + DataOption, + ResFileData, +} from "@/modules/04_registryPerson/interface/index/Main"; import type { ResponseObject } from "@/modules/04_registryPerson/interface/response/DeclarationHonor"; import DialogHeader from "@/components/DialogHeader.vue"; @@ -34,13 +37,14 @@ const profileId = ref( route.params.id ? route.params.id.toString() : "" ); const empType = ref(pathRegistryEmp(route.name?.toString() ?? "")); - +const isUpload = ref(false); +const fileUpload = ref(null); +const fileData = ref(null); /** props*/ const isLeave = defineModel("isLeave", { required: true, }); -const fileUpload = ref(); const uploadUrl = ref(""); const typeOp = ref([ @@ -282,6 +286,7 @@ async function addEditData(editStatus: boolean = false) { const method = editStatus ? "patch" : "post"; const reqBody: RequestItemsObject = { ...declHonorForm, + isUpload: !isEdit.value ? undefined : isUpload.value, profileEmployeeId: !editStatus && empType.value !== "" ? profileId.value : undefined, profileId: @@ -295,8 +300,8 @@ async function addEditData(editStatus: boolean = false) { try { await http[method](url, reqBody).then(async (res) => { - if (fileUpload.value && res.data.result) { - await uploadProfile(res.data.result); + if ((fileUpload.value && id.value) || res.data.result) { + await uploadProfile(id.value); } }); await fetchData(); @@ -352,19 +357,38 @@ async function uploadFileURL(uploadUrl: string, file: any) { "Content-Type": file.type, }, }) - .then(() => { - fileUpload.value = undefined; + .then(async (res) => { + if (res.status == 200) { + await isUploadFn(); + } + fileUpload.value = null; }) .catch((err) => { messageError($q, err); }); } +async function isUploadFn() { + await http + .patch(config.API.profileNewHonorById(id.value, empType.value), { + isUpload: fileUpload.value ? true : false, + isDate: declHonorForm.isDate === "true" ? true : false, + }) + .then(async (res) => {}) + + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); +} + /** * ฟังก์ชันโหลไฟลเอกสารหลักฐาน * @param id รายการที่ต้องการโหลด */ -async function onDownloadFile(id: string) { +async function onDownloadFile(id: string, isLoad: boolean = true) { showLoader(); await http .get( @@ -377,8 +401,11 @@ async function onDownloadFile(id: string) { ) ) .then(async (res) => { - const data = res.data.downloadUrl; - window.open(data, "_blank"); + const data = res.data; + fileData.value = data; + if (isLoad) { + window.open(data.downloadUrl, "_blank"); + } }) .catch((err) => { messageError($q, err); @@ -404,6 +431,12 @@ function onClickOpenDialog(editStatus: boolean = false, row?: ResponseObject) { declHonorForm.refCommandDate = row.refCommandDate; declHonorForm.type = row.type; declHonorForm.isDate = row.isDate ? "true" : "false"; + + isUpload.value = row.isUpload; + + if (isUpload.value) { + onDownloadFile(row.id, false); + } } else { clearData(); } @@ -456,6 +489,10 @@ function clearData() { declHonorForm.type = ""; declHonorForm.refCommandDate = null; declHonorForm.isDate = "false"; + + fileUpload.value = null; + isUpload.value = false; + fileData.value = null; } function serchDataTable() { @@ -890,6 +927,7 @@ onMounted(() => {
{
+ + + + {{ fileData?.fileName }} + +
+ + + +
+
+
+
diff --git a/src/modules/04_registryPerson/components/detail/GovernmentInformation/04_PerformSpecialWork.vue b/src/modules/04_registryPerson/components/detail/GovernmentInformation/04_PerformSpecialWork.vue index 3937c6d79..4fc0bdbdd 100644 --- a/src/modules/04_registryPerson/components/detail/GovernmentInformation/04_PerformSpecialWork.vue +++ b/src/modules/04_registryPerson/components/detail/GovernmentInformation/04_PerformSpecialWork.vue @@ -10,6 +10,7 @@ import http from "@/plugins/http"; import config from "@/app.config"; import type { RequestItemsObject } from "@/modules/04_registryPerson/interface/index/performSpecialWork"; +import type { ResFileData } from "@/modules/04_registryPerson/interface/index/Main"; import DialogHeader from "@/components/DialogHeader.vue"; import DialogHistory from "@/modules/04_registryPerson/components/detail/GovernmentInformation/04_PerformSpecialWorkHistory.vue"; @@ -33,8 +34,13 @@ const profileId = ref( route.params.id ? route.params.id.toString() : "" ); const empType = ref(pathRegistryEmp(route.name?.toString() ?? "")); -const fileUpload = ref(); + const uploadUrl = ref(""); + +const isUpload = ref(false); +const fileUpload = ref(null); +const fileData = ref(null); + /** props*/ const isLeave = defineModel("isLeave", { required: true, @@ -51,7 +57,8 @@ const dutyData = reactive({ detail: "", //รายละเอียด reference: "", //เอกสารอ้างอิง refCommandNo: "", //เลขที่คำสั่ง - refCommandDate: null, //'เอกสารอ้างอิง (ลงวันที่)' + refCommandDate: null, //'เอกสารอ้างอิง (ลงวันที่)', + isUpload: false, }); const mode = ref("table"); //การแสดงผล Table card @@ -158,6 +165,12 @@ function openDialogEdit(props: RequestItemsObject) { dutyData.reference = props.reference; dutyData.refCommandNo = props.refCommandNo; dutyData.refCommandDate = props.refCommandDate; + + isUpload.value = props.isUpload; + + if (isUpload.value && props.id) { + onDownloadFile(props.id, false); + } } /** @@ -179,7 +192,11 @@ function closeDialog() { dutyData.reference = ""; dutyData.refCommandNo = ""; dutyData.refCommandDate = null; - fileUpload.value = undefined; + fileUpload.value = null; + + fileUpload.value = null; + isUpload.value = false; + fileData.value = null; } /** fetch ข้อมูลรายการพิเศษ*/ @@ -211,6 +228,7 @@ function addData() { reference: dutyData.reference, refCommandNo: dutyData.refCommandNo, refCommandDate: dutyData.refCommandDate, + isUpload: !edit.value ? undefined : isUpload.value, }; http .post(config.API.profileNewDuty(empType.value), body) @@ -239,8 +257,8 @@ function editData(idData: string) { profileId: undefined, }) .then(async (res) => { - if (fileUpload.value && res.data.result) { - await uploadProfile(res.data.result); + if (fileUpload.value && id.value) { + await uploadProfile(id.value); } await fetchData(profileId.value); await success($q, "บันทึกข้อมูลสำเร็จ"); @@ -297,19 +315,37 @@ async function uploadFileURL(uploadUrl: string, file: any) { "Content-Type": file.type, }, }) - .then(() => { - fileUpload.value = undefined; + .then(async (res) => { + if (res.status == 200) { + await isUploadFn(); + } + fileUpload.value = null; }) .catch((err) => { messageError($q, err); }); } +async function isUploadFn() { + await http + .patch(config.API.profileNewDutyByDutyId(id.value, empType.value), { + isUpload: fileUpload.value ? true : false, + }) + .then(async (res) => {}) + + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); +} + /** * ฟังก์ชันโหลไฟลเอกสารหลักฐาน * @param id รายการที่ต้องการโหลด */ -async function onDownloadFile(id: string) { +async function onDownloadFile(id: string, isLoad: boolean = true) { showLoader(); await http .get( @@ -322,8 +358,11 @@ async function onDownloadFile(id: string) { ) ) .then(async (res) => { - const data = res.data.downloadUrl; - window.open(data, "_blank"); + const data = res.data; + fileData.value = data; + if (isLoad) { + window.open(data.downloadUrl, "_blank"); + } }) .catch((err) => { messageError($q, err); @@ -756,6 +795,7 @@ onMounted(() => {
{
+ + + + {{ fileData?.fileName }} + +
+ + + +
+
+
+
diff --git a/src/modules/04_registryPerson/components/detail/Other/03_Document7.vue b/src/modules/04_registryPerson/components/detail/Other/03_Document7.vue index 410eb9b31..c7c69e9cb 100644 --- a/src/modules/04_registryPerson/components/detail/Other/03_Document7.vue +++ b/src/modules/04_registryPerson/components/detail/Other/03_Document7.vue @@ -43,10 +43,10 @@ async function getData() { showLoader(); await http .get( - config.API.file("ระบบทะเบียนประวัติ", "เอกสาร ก.พ.7", profileId.value) + config.API.file("ระบบทะเบียนประวัติ", "เอกสารหลักฐานเพิ่มเติม", profileId.value) ) .then((res) => { - console.log("ระบบทะเบียนประวัติ", "เอกสาร ก.พ.7", profileId.value) + console.log("ระบบทะเบียนประวัติ", "เอกสารหลักฐานเพิ่มเติม", profileId.value) fileList.value = res.data; }) .catch((e) => { @@ -73,7 +73,7 @@ function clickUpload(file: any) { .post( config.API.file( "ระบบทะเบียนประวัติ", - "เอกสาร ก.พ.7", + "เอกสารหลักฐานเพิ่มเติม", profileId.value ), { @@ -135,7 +135,7 @@ function downloadFile(fileName: string) { .get( config.API.fileByFile( "ระบบทะเบียนประวัติ", - "เอกสาร ก.พ.7", + "เอกสารหลักฐานเพิ่มเติม", profileId.value, fileName ) @@ -163,7 +163,7 @@ function deleteFile(fileName: string) { .delete( config.API.fileByFile( "ระบบทะเบียนประวัติ", - "เอกสาร ก.พ.7", + "เอกสารหลักฐานเพิ่มเติม", profileId.value, fileName ) diff --git a/src/modules/04_registryPerson/components/detail/PersonalInformation/06_SpecialSkill.vue b/src/modules/04_registryPerson/components/detail/PersonalInformation/06_SpecialSkill.vue index 545248ac4..0f1e10b7a 100644 --- a/src/modules/04_registryPerson/components/detail/PersonalInformation/06_SpecialSkill.vue +++ b/src/modules/04_registryPerson/components/detail/PersonalInformation/06_SpecialSkill.vue @@ -13,6 +13,7 @@ import { useCounterMixin } from "@/stores/mixin"; import type { QTableProps } from "quasar"; import type { RequestItemsObject } from "@/modules/04_registryPerson/interface/request/SpecialSkill"; import type { ResponseObject } from "@/modules/04_registryPerson/interface/response/SpecialSkill"; +import type { ResFileData } from "@/modules/04_registryPerson/interface/index/Main"; import dialogHeader from "@/components/DialogHeader.vue"; @@ -35,9 +36,12 @@ const profileId = ref( route.params.id ? route.params.id.toString() : "" ); const empType = ref(pathRegistryEmp(route.name?.toString() ?? "")); -const fileUpload = ref(); -const uploadUrl = ref(""); +const uploadUrl = ref(""); +const isUpload = ref(false); +const fileUpload = ref(null); +const fileData = ref(null); +const isEdit = ref(false); const mode = ref("table"); //การแสดงของ Table card /** * props @@ -227,7 +231,11 @@ function clearForm() { specialSkill.field = ""; specialSkill.reference = ""; specialSkill.remark = ""; - fileUpload.value = undefined; + isEdit.value = false; + + fileUpload.value = null; + isUpload.value = false; + fileData.value = null; } /** @@ -242,6 +250,12 @@ function editForm(row: any) { specialSkill.reference = row.reference; specialSkill.remark = row.remark; dialog.value = true; + isEdit.value = true; + isUpload.value = row.isUpload; + + if (isUpload.value) { + onDownloadFile(row.id, false); + } } /** function fetch ข้อมูลความสามรรถพิเศษ*/ @@ -291,6 +305,7 @@ async function addData() { dateEnd: null, profileId: empType.value === "" ? id.value : undefined, profileEmployeeId: empType.value !== "" ? id.value : undefined, + isUpload: !isEdit.value ? undefined : isUpload.value, }) .then(async (res) => { if (fileUpload.value && res.data.result) { @@ -322,8 +337,8 @@ async function editData(idData: string) { profileId: undefined, }) .then(async (res) => { - if (fileUpload.value && res.data.result) { - await uploadProfile(res.data.result); + if (fileUpload.value && id.value) { + await uploadProfile(id.value); } await fetchData(id.value); await success($q, "บันทึกข้อมูลสำเร็จ"); @@ -380,19 +395,37 @@ async function uploadFileURL(uploadUrl: string, file: any) { "Content-Type": file.type, }, }) - .then(() => { - fileUpload.value = undefined; + .then(async (res) => { + if (res.status == 200) { + await isUploadFn(); + } + fileUpload.value = null; }) .catch((err) => { messageError($q, err); }); } +async function isUploadFn() { + await http + .patch(config.API.profileNewAbilityByAbilityId(editId.value, empType.value), { + isUpload: fileUpload.value ? true : false, + }) + .then(async (res) => {}) + + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); +} + /** * ฟังก์ชันโหลไฟลเอกสารหลักฐาน * @param id รายการที่ต้องการโหลด */ -async function onDownloadFile(id: string) { +async function onDownloadFile(id: string, isLoad: boolean = true) { showLoader(); await http .get( @@ -405,8 +438,11 @@ async function onDownloadFile(id: string) { ) ) .then(async (res) => { - const data = res.data.downloadUrl; - window.open(data, "_blank"); + const data = res.data; + fileData.value = data; + if (isLoad) { + window.open(data.downloadUrl, "_blank"); + } }) .catch((err) => { messageError($q, err); @@ -419,6 +455,7 @@ async function onDownloadFile(id: string) { /** function ปิด popup ข้อมูลความสามารถพิเศษ*/ function closeDialog() { dialog.value = false; + clearForm(); } /** function ปิด popup รายการประวัติ*/ @@ -590,7 +627,7 @@ onMounted(() => { dense round icon="mdi-file-document-outline" - @click="onDownloadFile(props.row.id)" + @click="onDownloadFile(props.row.profileId)" > ดาวน์โหลด @@ -713,6 +750,7 @@ onMounted(() => {
{
+ + + + {{ fileData?.fileName }} + +
+ + + +
+
+
+
diff --git a/src/modules/04_registryPerson/interface/index/Main.ts b/src/modules/04_registryPerson/interface/index/Main.ts index b3008f377..8a4b1d88e 100644 --- a/src/modules/04_registryPerson/interface/index/Main.ts +++ b/src/modules/04_registryPerson/interface/index/Main.ts @@ -83,6 +83,41 @@ interface Request { topic: string; } +interface InsigniasType { + id: string; + createdAt: Date; + createdUserId: string; + lastUpdatedAt: Date; + lastUpdateUserId: string; + createdFullName: string; + lastUpdateFullName: string; + name: string; + isActive: boolean; + insignias: InsigniasTypeSub[]; +} + +interface InsigniasTypeSub { + id:string; + createdAt:Date; + createdUserId:string; + lastUpdatedAt:Date; + lastUpdateUserId:string; + createdFullName:string; + lastUpdateFullName:string; + name:string; + shortName:string; + level:string; + isActive:string; + note:string; + insigniaTypeId:string; +} + +interface ResFileData { + downloadUrl: string; + fileName: string; + path: string; + pathname: string; +} export type { Pagination, DataOption, @@ -97,4 +132,8 @@ export type { DataOptionEducation, DataOptionEducationLevel, Request, + + InsigniasType, + InsigniasTypeSub, + ResFileData }; diff --git a/src/modules/04_registryPerson/interface/index/performSpecialWork.ts b/src/modules/04_registryPerson/interface/index/performSpecialWork.ts index 556605b34..91ddf78de 100644 --- a/src/modules/04_registryPerson/interface/index/performSpecialWork.ts +++ b/src/modules/04_registryPerson/interface/index/performSpecialWork.ts @@ -21,6 +21,7 @@ interface RequestItemsObject { reference: string; refCommandNo: string; refCommandDate: Date | null; + isUpload: boolean; } interface MyObjectRef { diff --git a/src/modules/04_registryPerson/interface/request/DeclarationHonor.ts b/src/modules/04_registryPerson/interface/request/DeclarationHonor.ts index 33eb39b71..e2b750b2d 100644 --- a/src/modules/04_registryPerson/interface/request/DeclarationHonor.ts +++ b/src/modules/04_registryPerson/interface/request/DeclarationHonor.ts @@ -8,6 +8,7 @@ interface RequestItemsObject { refCommandNo: string; type: string; isDate: boolean | string; + isUpload?: boolean|undefined; } export type { RequestItemsObject }; diff --git a/src/modules/04_registryPerson/interface/request/Insignia.ts b/src/modules/04_registryPerson/interface/request/Insignia.ts index 868cca232..4a27f11aa 100644 --- a/src/modules/04_registryPerson/interface/request/Insignia.ts +++ b/src/modules/04_registryPerson/interface/request/Insignia.ts @@ -14,6 +14,7 @@ interface RequestItemsObject { refCommandNo: string; note: string; profileEmployeeId?: string | null; + isUpload?: boolean | undefined; } export type { RequestItemsObject }; diff --git a/src/modules/04_registryPerson/interface/response/DeclarationHonor.ts b/src/modules/04_registryPerson/interface/response/DeclarationHonor.ts index 9a8182574..c925a8365 100644 --- a/src/modules/04_registryPerson/interface/response/DeclarationHonor.ts +++ b/src/modules/04_registryPerson/interface/response/DeclarationHonor.ts @@ -14,6 +14,7 @@ interface ResponseObject { profileId: string; type: string; refCommandDate: Date; + isUpload: boolean; refCommandNo: string; } diff --git a/src/modules/04_registryPerson/interface/response/Insignia.ts b/src/modules/04_registryPerson/interface/response/Insignia.ts index 5f6901993..29328196a 100644 --- a/src/modules/04_registryPerson/interface/response/Insignia.ts +++ b/src/modules/04_registryPerson/interface/response/Insignia.ts @@ -20,6 +20,7 @@ interface ResponseObject { volumeNo: string; refCommandDate: Date | null; refCommandNo: string; + isUpload: boolean; note: string; } diff --git a/src/modules/04_registryPerson/stores/insignia.ts b/src/modules/04_registryPerson/stores/insignia.ts index ce94db30a..b8cca347e 100644 --- a/src/modules/04_registryPerson/stores/insignia.ts +++ b/src/modules/04_registryPerson/stores/insignia.ts @@ -1,30 +1,37 @@ import { ref, computed } from "vue"; import { defineStore } from "pinia"; -import type { DataOptionInsignia,DataOption } from "@/modules/04_registryPerson/interface/index/Main"; +import type { + DataOptionInsignia, + DataOption, + InsigniasType, + InsigniasTypeSub, +} from "@/modules/04_registryPerson/interface/index/Main"; import type { ResponseObject as Insignia } from "@/modules/07_insignia/interface/response/Main"; export const useInsigniaDataStore = defineStore("insigniaDataStore", () => { - const insigniaOption = ref([]); - const insigniaTypeOp = ref([]); - const insigniaTypeOpMain = ref([]); + const insigniaOption = ref([]); - function mapInsigniaOption(resData: any) { - insigniaTypeOp.value = Array.from( - new Map( - resData.map((item:any) => [item.insigniaTypeName, { id: item.insigniaTypeId, name: item.insigniaTypeName }]) - ).values() - ) as DataOption[]; + const insigniaTypeOp = ref([]); + const insigniaTypeOpMain = ref([]); + const allNameInsignia = ref([]); - insigniaOption.value = []; - resData.map((r: Insignia) => { - insigniaOption.value.push({ - id: r.id.toString(), - name: r.name.toString() + ` (${r.shortName})`, - typeId: r.insigniaTypeId.toString(), - typeName: r.insigniaTypeName.toString(), - }); - }); + function mapInsigniaOption(resData: InsigniasType[]) { + insigniaTypeOpMain.value = resData; + insigniaTypeOp.value = resData; + + allNameInsignia.value = resData + .flatMap((item: InsigniasType) => item.insignias) + .map((i: InsigniasTypeSub) => ({ + ...i, + name: `${i.name} (${i.shortName})`, + })); } - return { insigniaOption, mapInsigniaOption,insigniaTypeOp }; + return { + insigniaOption, + mapInsigniaOption, + insigniaTypeOp, + insigniaTypeOpMain, + allNameInsignia, + }; });