From 115455cc8f0a4202cfa0d79b71320479d3329b3d Mon Sep 17 00:00:00 2001 From: setthawutttty Date: Wed, 31 Jan 2024 11:02:24 +0700 Subject: [PATCH 1/8] =?UTF-8?q?pop=20up=20=E0=B8=AA=E0=B8=B3=E0=B8=AB?= =?UTF-8?q?=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B8=88=E0=B8=B1=E0=B8=94=E0=B8=A5?= =?UTF-8?q?=E0=B8=B3=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B9=82=E0=B8=84=E0=B8=A3?= =?UTF-8?q?=E0=B8=87=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/DialogSortAgency.vue | 130 ++++++++++++++++++ .../components/StructureDetail.vue | 2 - 2 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 src/modules/02_organizationalNew/components/DialogSortAgency.vue diff --git a/src/modules/02_organizationalNew/components/DialogSortAgency.vue b/src/modules/02_organizationalNew/components/DialogSortAgency.vue new file mode 100644 index 000000000..bed77d4e5 --- /dev/null +++ b/src/modules/02_organizationalNew/components/DialogSortAgency.vue @@ -0,0 +1,130 @@ + + diff --git a/src/modules/02_organizationalNew/components/StructureDetail.vue b/src/modules/02_organizationalNew/components/StructureDetail.vue index bf30060de..c3e2e84ce 100644 --- a/src/modules/02_organizationalNew/components/StructureDetail.vue +++ b/src/modules/02_organizationalNew/components/StructureDetail.vue @@ -4,8 +4,6 @@ import { useQuasar } from "quasar"; import http from "@/plugins/http"; import config from "@/app.config"; -import type { HistoryType } from "@/modules/02_organizationalNew/interface/index/Main"; - import DialogHeader from "@/components/DialogHeader.vue"; import { useCounterMixin } from "@/stores/mixin"; From 9355b54882e34efb04653ddefb61b3024473501b Mon Sep 17 00:00:00 2001 From: setthawutttty Date: Wed, 31 Jan 2024 15:33:22 +0700 Subject: [PATCH 2/8] no message --- .../components/DialogSortAgency.vue | 65 +++++++++---------- .../components/mainTree.vue | 60 +++++++++++++++++ 2 files changed, 92 insertions(+), 33 deletions(-) diff --git a/src/modules/02_organizationalNew/components/DialogSortAgency.vue b/src/modules/02_organizationalNew/components/DialogSortAgency.vue index bed77d4e5..3abe050da 100644 --- a/src/modules/02_organizationalNew/components/DialogSortAgency.vue +++ b/src/modules/02_organizationalNew/components/DialogSortAgency.vue @@ -23,29 +23,16 @@ const { dialogConfirm, showLoader, success, hideLoader, messageError } = useCounterMixin(); const modal = defineModel("sortAgency", { required: true }); +const modalSort = defineModel>("data", { required: true }); +const modalType = defineModel("type", { required: true }); const rows = ref([]); const columns = ref([ { - name: "id", + name: "name", required: true, - label: "ชื่อเครื่องราชฯ", + label: "ชื่อ", align: "left", - field: "id", - sortable: true, - }, - { - name: "shortName", - align: "center", - label: "ชื่อย่อ", - field: "shortName", - }, - { - name: "insigniaType", - align: "left", - label: "ลำดับชั้นเครื่องราชฯ", - field: "insigniaType", - headerStyle: "font-size: 14px", - style: "font-size: 14px", + field: "name", sortable: true, }, ]); @@ -61,7 +48,7 @@ function onDropRow(from: any, to: any) { function save() { dialogConfirm($q, () => { const data = rows.value; - const dataId = data.map((item: any) => item.id); + const dataId = data.map((item: any) => item.orgTreeId); console.log(dataId); }); } @@ -69,20 +56,32 @@ watch( () => modal.value, () => { if (modal.value == true) { - const dataList = [ - { - id: "x1", - shortName: "test1", - insigniaType: "test1", - }, - { - id: "x2", - shortName: "test2", - insigniaType: "test2", - }, - ]; + const dataStandant = modalSort.value; + if (modalType.value === 0) { + const mappedData = dataStandant.map((item: any) => ({ + orgLevel: item.orgLevel, + name: `${item.orgTreeName} (${item.orgTreeShortName})`, + orgRevisionId: item.orgRevisionId, + orgTreeId: item.orgTreeId, + orgTreeName: item.orgTreeName, + orgTreeShortName: item.orgTreeShortName, + })); + rows.value = mappedData; + console.log("row", rows.value); + } else if (modalType.value === 1) { + const mappedData = dataStandant.map((item: any) => ({ + name: `${item.orgTreeName} (${item.orgTreeShortName})`, + orgRootId: item.orgRootId, + orgTreeId: item.orgTreeId, + orgLevel: item.orgLevel, + orgTreeName: item.orgTreeName, + orgTreeShortName: item.orgTreeShortName, + orgRevisionId: item.orgRevisionId, + })); + rows.value = mappedData; - rows.value = dataList; + console.log("row", dataStandant); + } } } ); @@ -113,7 +112,7 @@ watch( :rows="rows" :columns="columns" :rows-per-page-options="[100]" - row-key="name" + row-key="orgTreeId" hide-bottom hide-pagination hide-header diff --git a/src/modules/02_organizationalNew/components/mainTree.vue b/src/modules/02_organizationalNew/components/mainTree.vue index 84afe164a..4b059f2f6 100644 --- a/src/modules/02_organizationalNew/components/mainTree.vue +++ b/src/modules/02_organizationalNew/components/mainTree.vue @@ -10,6 +10,7 @@ import type { OrgTree } from "@/modules/02_organizationalNew/interface/response/ /** importComponents*/ import DialogAgency from "@/modules/02_organizationalNew/components/DialogFormAgency.vue"; import DialogStructureDetail from "@/modules/02_organizationalNew/components/StructureDetail.vue"; +import DialogSortAgency from "@/modules/02_organizationalNew/components/DialogSortAgency.vue"; /** importStore*/ import { useOrganizational } from "@/modules/02_organizationalNew/store/organizational"; @@ -80,7 +81,9 @@ const listAdd = ref([ const nodeTEST = defineModel("nodeTree", { default: [] }); const filter = ref(""); +const level = ref(0); const nodes = ref>([]); +const dataSort = ref>([]); const lazy = ref(nodes); const expanded = ref>([]); const notFound = ref("ไม่พบข้อมูลที่ค้นหา"); @@ -165,6 +168,7 @@ function deleteNode(treeNode: any, organizationId: any): boolean { return false; } +const modalSortAgency = ref(false); const dialogAgency = ref(false); const actionType = ref(""); const dataNode = ref(); @@ -214,6 +218,54 @@ async function onClickDel(type: number, id: string) { }); } +function onClickSort(type: number, id: string) { + modalSortAgency.value = true; + level.value = type; + if (type === 0) { + const dataList = nodes.value; + const dataMap = dataList.map((item: any) => ({ + orgTreeId: item.orgTreeId, + orgLevel: item.orgLevel, + orgTreeName: item.orgTreeName, + orgTreeShortName: item.orgTreeShortName, + orgRevisionId: item.orgRevisionId, + })); + + dataSort.value = dataMap; + } else if (type === 1) { + const dataList = nodes.value; + const dataMap = dataList.map((item: any) => ({ + orgTreeId: item.orgTreeId, + orgRevisionId: item.orgRevisionId, + children: item.children, + })); + const dataChild = dataMap + .filter((item: any) => item.orgTreeId === id) + .reduce((acc: any, item: any) => { + return acc.concat( + item.children.map((child: any) => ({ + orgRootId: child.orgRootId, + orgTreeId: child.orgTreeId, + orgLevel: child.orgLevel, + orgTreeName: child.orgTreeName, + orgTreeShortName: child.orgTreeShortName, + orgRevisionId: child.orgRevisionId, + })) + ); + }, []); + dataSort.value = dataChild; + } else if (type === 2) { + + const dataList = nodes.value; + const dataMap = dataList.map((item: any) => ({ + orgTreeId: item.orgTreeId, + children: item.children, + })) + + console.log(dataMap) + + } +} watch( () => nodeTEST.value, () => { @@ -328,6 +380,8 @@ onMounted(async () => {}); ? onClickDetail(prop.node.orgTreeId, prop.node.orgLevel) : item.type === 'DEL' ? onClickDel(prop.node.orgLevel, prop.node.orgTreeId) + : item.type === 'SORT' + ? onClickSort(prop.node.orgLevel, prop.node.orgRootId) : null " > @@ -451,6 +505,12 @@ onMounted(async () => {}); v-model:treeId="treeId" v-model:orgLevel="orgLevel" /> + + From 3eb1a41bdb91dbaa1db7b62afba330aeaaf217d9 Mon Sep 17 00:00:00 2001 From: setthawutttty Date: Wed, 31 Jan 2024 16:10:07 +0700 Subject: [PATCH 3/8] =?UTF-8?q?pop=20up=20=E0=B8=88=E0=B8=B1=E0=B8=94?= =?UTF-8?q?=E0=B8=A5=E0=B8=B3=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B8=9C=E0=B8=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/02_organizational/api.organization.ts | 1 + .../components/DialogSortAgency.vue | 52 ++++++++------- .../components/mainTree.vue | 63 ++++++++----------- 3 files changed, 51 insertions(+), 65 deletions(-) diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index 25ee73b01..f9a7faf4b 100644 --- a/src/api/02_organizational/api.organization.ts +++ b/src/api/02_organizational/api.organization.ts @@ -12,4 +12,5 @@ export default { orgSetDateTime:(id:string) => `${organization}/set/publish/${id}`, organizationHistoryNew: `${organization}/history`, + organizationShortName: `${organization}/sort`, }; diff --git a/src/modules/02_organizationalNew/components/DialogSortAgency.vue b/src/modules/02_organizationalNew/components/DialogSortAgency.vue index 3abe050da..4d21409e8 100644 --- a/src/modules/02_organizationalNew/components/DialogSortAgency.vue +++ b/src/modules/02_organizationalNew/components/DialogSortAgency.vue @@ -24,7 +24,6 @@ const { dialogConfirm, showLoader, success, hideLoader, messageError } = const modal = defineModel("sortAgency", { required: true }); const modalSort = defineModel>("data", { required: true }); -const modalType = defineModel("type", { required: true }); const rows = ref([]); const columns = ref([ { @@ -49,39 +48,38 @@ function save() { dialogConfirm($q, () => { const data = rows.value; const dataId = data.map((item: any) => item.orgTreeId); - console.log(dataId); + http + .put(config.API.organizationShortName, { + id: data[0].orgLevel === 0 ? data[0].orgRevisionId : data[0].orgRootId, + type: data[0].orgLevel, + sortId: dataId, + }) + .then((res) => { + modal.value = false; + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => {}); }); } watch( () => modal.value, () => { if (modal.value == true) { + rows.value = []; const dataStandant = modalSort.value; - if (modalType.value === 0) { - const mappedData = dataStandant.map((item: any) => ({ - orgLevel: item.orgLevel, - name: `${item.orgTreeName} (${item.orgTreeShortName})`, - orgRevisionId: item.orgRevisionId, - orgTreeId: item.orgTreeId, - orgTreeName: item.orgTreeName, - orgTreeShortName: item.orgTreeShortName, - })); - rows.value = mappedData; - console.log("row", rows.value); - } else if (modalType.value === 1) { - const mappedData = dataStandant.map((item: any) => ({ - name: `${item.orgTreeName} (${item.orgTreeShortName})`, - orgRootId: item.orgRootId, - orgTreeId: item.orgTreeId, - orgLevel: item.orgLevel, - orgTreeName: item.orgTreeName, - orgTreeShortName: item.orgTreeShortName, - orgRevisionId: item.orgRevisionId, - })); - rows.value = mappedData; - - console.log("row", dataStandant); - } + const mappedData = dataStandant.map((item: any) => ({ + name: `${item.orgTreeName} (${item.orgTreeShortName})`, + orgRootId: item.orgRootId, + orgTreeId: item.orgTreeId, + orgLevel: item.orgLevel, + orgTreeName: item.orgTreeName, + orgTreeShortName: item.orgTreeShortName, + orgRevisionId: item.orgRevisionId, + })); + rows.value = mappedData; } } ); diff --git a/src/modules/02_organizationalNew/components/mainTree.vue b/src/modules/02_organizationalNew/components/mainTree.vue index cb0dab00f..6f3f388ae 100644 --- a/src/modules/02_organizationalNew/components/mainTree.vue +++ b/src/modules/02_organizationalNew/components/mainTree.vue @@ -212,16 +212,25 @@ async function onClickDel(type: number, id: string) { messageError($q, err); }) .finally(async () => { - props.fetchDataTree?.(); - hideLoader(); + props.fetchDataTree?.(); + hideLoader(); }); }); } -function onClickSort(type: number, id: string) { +async function onClickSort(id: string) { modalSortAgency.value = true; - level.value = type; - if (type === 0) { + if (id) { + breakLoop.value = false; + + const orgId = id; + + for (let index = 0; index < nodes.value.length; index++) { + const data = nodes.value[index]; + searchAndReplace(data, orgId); + if (breakLoop.value) break; + } + } else { const dataList = nodes.value; const dataMap = dataList.map((item: any) => ({ orgTreeId: item.orgTreeId, @@ -232,38 +241,17 @@ function onClickSort(type: number, id: string) { })); dataSort.value = dataMap; - } else if (type === 1) { - const dataList = nodes.value; - const dataMap = dataList.map((item: any) => ({ - orgTreeId: item.orgTreeId, - orgRevisionId: item.orgRevisionId, - children: item.children, - })); - const dataChild = dataMap - .filter((item: any) => item.orgTreeId === id) - .reduce((acc: any, item: any) => { - return acc.concat( - item.children.map((child: any) => ({ - orgRootId: child.orgRootId, - orgTreeId: child.orgTreeId, - orgLevel: child.orgLevel, - orgTreeName: child.orgTreeName, - orgTreeShortName: child.orgTreeShortName, - orgRevisionId: child.orgRevisionId, - })) - ); - }, []); - dataSort.value = dataChild; - } else if (type === 2) { - - const dataList = nodes.value; - const dataMap = dataList.map((item: any) => ({ - orgTreeId: item.orgTreeId, - children: item.children, - })) - - console.log(dataMap) + } + function searchAndReplace(data: any, id: string) { + if (data.orgTreeId === id) { + dataSort.value = data.children; + breakLoop.value = true; + } else if (data.children) { + for (const child of data.children) { + searchAndReplace(child, id); + } + } } } watch( @@ -381,7 +369,7 @@ onMounted(async () => {}); : item.type === 'DEL' ? onClickDel(prop.node.orgLevel, prop.node.orgTreeId) : item.type === 'SORT' - ? onClickSort(prop.node.orgLevel, prop.node.orgRootId) + ? onClickSort(prop.node.orgRootId) : null " > @@ -509,7 +497,6 @@ onMounted(async () => {}); From 80b40ead8517540ea4f92b39d7271af8b9a3fd49 Mon Sep 17 00:00:00 2001 From: setthawutttty Date: Wed, 31 Jan 2024 16:23:21 +0700 Subject: [PATCH 4/8] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=A3?= =?UTF-8?q?=E0=B8=B9=E0=B8=9B=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B8=82=E0=B8=B6?= =?UTF-8?q?=E0=B9=89=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/resign/ResignByid.vue | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/modules/06_retirement/components/resign/ResignByid.vue b/src/modules/06_retirement/components/resign/ResignByid.vue index 5542de9b3..2ffe37424 100644 --- a/src/modules/06_retirement/components/resign/ResignByid.vue +++ b/src/modules/06_retirement/components/resign/ResignByid.vue @@ -17,6 +17,7 @@ import type { import type { QTableProps } from "quasar"; import PopupPersonal from "@/components/Dialogs/PopupPersonal.vue"; +const avatar = ref('') const modalPersonal = ref(false); const personId = ref(""); /** Use */ @@ -179,6 +180,7 @@ const fetchData = async (id: string) => { location.value = data.location ?? ""; status.value = data.status ?? ""; remarkHorizontal.value = data.remarkHorizontal ?? "-"; + getAvatar(data.profileId) }) .catch((e) => { messageError($q, e); @@ -187,6 +189,23 @@ const fetchData = async (id: string) => { hideLoader(); }); }; + +function getAvatar(id:string){ + if(id){ + http + .get(config.API.profileAvaId(id)) + .then((res)=>{ + console.log(res) + const dataList = res.data.result + avatar.value = dataList.avatar + }).catch((e)=>{ + + }).finally(()=>{ + + }) + } +} + // const downloadFile = (response: any, filename: string) => { // const link = document.createElement("a"); // var fileName = filename; @@ -435,7 +454,8 @@ function updatemodalPersonal(modal: boolean) {
- + +
From aa46396728f2bf603f92fcbb7193d3c1d6bd43d2 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Wed, 31 Jan 2024 16:59:28 +0700 Subject: [PATCH 5/8] =?UTF-8?q?=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87?= =?UTF-8?q?=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B8=AD=E0=B8=B1?= =?UTF-8?q?=E0=B8=95=E0=B8=A3=E0=B8=B2=E0=B8=81=E0=B8=B3=E0=B8=A5=E0=B8=B1?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/02_organizational/api.organization.ts | 11 +- .../components/DialogFormPosition.vue | 402 ++++++++++++++---- .../components/listView.vue | 47 +- .../components/mainTree.vue | 25 +- .../components/tableTree.vue | 15 +- .../interface/index/Main.ts | 36 +- .../interface/response/organizational.ts | 40 +- 7 files changed, 458 insertions(+), 118 deletions(-) diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index 25ee73b01..74d20d111 100644 --- a/src/api/02_organizational/api.organization.ts +++ b/src/api/02_organizational/api.organization.ts @@ -1,6 +1,7 @@ import env from "../index"; const organization = `${env.API_URI}/org`; +const orgPos = `${env.API_URI}/org/pos`; export default { /** โครงสร้างอัตรากำลัง*/ @@ -10,6 +11,14 @@ export default { createOrgLevel: (type: string) => `${organization}/${type}`, orgLevelByid: (type: string, id: string) => `${organization}/${type}/${id}`, - orgSetDateTime:(id:string) => `${organization}/set/publish/${id}`, + orgSetDateTime: (id: string) => `${organization}/set/publish/${id}`, organizationHistoryNew: `${organization}/history`, + + /** position*/ + orgPosPosition: `${orgPos}/position`, + orgPosPositionById: (id: string) => `${orgPos}/position/${id}`, + orgPosExecutive: `${orgPos}/executive`, + orgPosType: `${orgPos}/type`, + orgPosLevel: `${orgPos}/level`, + orgPosMaster: `${orgPos}/master`, }; diff --git a/src/modules/02_organizationalNew/components/DialogFormPosition.vue b/src/modules/02_organizationalNew/components/DialogFormPosition.vue index ea8e6cfab..254a2dd22 100644 --- a/src/modules/02_organizationalNew/components/DialogFormPosition.vue +++ b/src/modules/02_organizationalNew/components/DialogFormPosition.vue @@ -10,22 +10,42 @@ import type { DataOption, FormPositionSelect, RowDetailPositions, + FormPositionSelectRef, ListMenu, } from "@/modules/02_organizationalNew/interface/index/Main"; +import type { + OptionType, + OptionLevel, + OptionExecutive, + DataPosition, +} from "@/modules/02_organizationalNew/interface/response/organizational"; +import http from "@/plugins/http"; +import config from "@/app.config"; const props = defineProps({ modal: Boolean, close: Function, + orgLevel: Number, + treeId: String, }); const isReadonly = ref(false); // อ่านได้อย่างเดียว +const isDisValidate = ref(false); + const $q = useQuasar(); const mixin = useCounterMixin(); -const { dialogConfirm } = mixin; +const { + dialogConfirm, + showLoader, + hideLoader, + messageError, + success, + dialogRemove, +} = mixin; const selected = ref([]); const search = ref(""); const type = ref("positionName"); -const typeOps = ref([ +const optionFilter = ref([ { id: "positionName", name: "ตำแหน่งในสายงาน" }, { id: "positionField", name: "สายงาน" }, { id: "positionType", name: "ประเภทตำแหน่ง" }, @@ -35,6 +55,13 @@ const typeOps = ref([ { id: "positionArea", name: "ด้าน/สาขา" }, ]); +const typeOpsMain = ref([]); +const levelOpsMain = ref([]); +const executiveOpsMain = ref([]); +const typeOps = ref([]); +const levelOps = ref([]); +const executiveOps = ref([]); + const listMenu = ref([ { label: "คัดลอก", @@ -57,12 +84,19 @@ const ocLevelOp = ref([]); const prefixNoRef = ref(null); const positionNoRef = ref(null); +const positionNameRef = ref(null); +const positionFieldRef = ref(null); +const positionTypeRef = ref(null); +const positionLevelRef = ref(null); +const positionExecutiveRef = ref(null); +const positionExecutiveFieldRef = ref(null); +const positionAreaRef = ref(null); + const formData = reactive({ shortName: "สกจ.", prefixNo: "", positionNo: "", suffixNo: "", - confirm: false, }); const formPositionSelect = reactive({ @@ -81,6 +115,16 @@ const objectPositionRef: FormPositionRef = { positionNo: positionNoRef, }; +const objectPositionSelectRef: FormPositionSelectRef = { + positionName: positionNameRef, + positionField: positionFieldRef, + positionType: positionTypeRef, + positionLevel: positionLevelRef, + positionExecutive: positionExecutiveRef, + positionExecutiveField: positionExecutiveFieldRef, + positionArea: positionAreaRef, +}; + const columns = ref([ { name: "no", @@ -110,29 +154,29 @@ const columns = ref([ style: "font-size: 14px", }, { - name: "positionType", + name: "posTypeName", align: "left", label: "ประเภทตำเเหน่ง", sortable: true, - field: "positionType", + field: "posTypeName", headerStyle: "font-size: 14px", style: "font-size: 14px", }, { - name: "positionLevel", + name: "posLevelName", align: "left", label: "ระดับตำแหน่ง", sortable: true, - field: "positionLevel", + field: "posLevelName", headerStyle: "font-size: 14px", style: "font-size: 14px", }, { - name: "positionExecutive", + name: "posExecutiveName", align: "left", label: "ตำแหน่งทางการบริหาร", sortable: true, - field: "positionExecutive", + field: "posExecutiveName", headerStyle: "font-size: 14px", style: "font-size: 14px", }, @@ -159,13 +203,73 @@ const visibleColumns = ref([ "no", "positionName", "positionField", - "positionType", - "positionLevel", - "positionExecutive", + "posTypeName", + "posLevelName", + "posExecutiveName", "positionExecutiveField", "positionArea", ]); +/** function เรียกรายการประเภทตำแหน่ง */ +async function fetchType() { + showLoader(); + await http + .get(config.API.orgPosType) + .then((res) => { + typeOpsMain.value = res.data.result.map((e: OptionType) => ({ + id: e.id, + name: e.posTypeName, + })); + typeOps.value = typeOpsMain.value; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +/** function เรียกรายการระดับตำแหน่ง */ +async function fetchLevel() { + showLoader(); + await http + .get(config.API.orgPosLevel) + .then((res) => { + levelOpsMain.value = res.data.result.map((e: OptionLevel) => ({ + id: e.id, + name: e.posLevelName, + })); + levelOps.value = levelOpsMain.value; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +/** function เรียกรายการตำแหน่งทางการบริหาร */ +async function fetchExecutive() { + showLoader(); + await http + .get(config.API.orgPosExecutive) + .then((res) => { + executiveOpsMain.value = res.data.result.map((e: OptionExecutive) => ({ + id: e.id, + name: e.posExecutiveName, + })); + executiveOps.value = executiveOpsMain.value; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + /** ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม */ function validateForm() { const hasError = []; @@ -186,31 +290,33 @@ function validateForm() { /** ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม */ function validateFormPositionEdit() { - // const hasError = []; - // for (const key in objectPositionRef) { - // if (Object.prototype.hasOwnProperty.call(objectPositionRef, key)) { - // const property = objectPositionRef[key]; - // if (property.value && typeof property.value.validate === "function") { - // const isValid = property.value.validate(); - // hasError.push(isValid); - // } - // } - // } - // if (hasError.every((result) => result === true)) { - onSubmitSelectEdit(); - // } else { - // } + isDisValidate.value = false; + const hasError = []; + for (const key in objectPositionSelectRef) { + if (Object.prototype.hasOwnProperty.call(objectPositionSelectRef, key)) { + const property = objectPositionSelectRef[key]; + if (property.value && typeof property.value.validate === "function") { + const isValid = property.value.validate(); + hasError.push(isValid); + } + } + } + if (hasError.every((result) => result === true)) { + onSubmitSelectEdit(); + } } /** ฟังชั่น บันทึก */ function onSubmit() { - dialogConfirm($q, () => { + console.log(props.orgLevel); + + dialogConfirm($q, async () => { const positionsData = rows.value.map((e) => ({ posDictName: e.positionName, //ชื่อตำแหน่งในสายงาน (ชื่อตำแหน่ง) posDictField: e.positionField, //สายงาน - posTypeId: e.positionName, //*ประเภทตำแหน่ง - posLevelId: e.positionName, //*ระดับตำแหน่ง - posExecutiveId: e.positionName, //ตำแหน่งทางการบริหาร + posTypeId: e.posTypeId, //*ประเภทตำแหน่ง + posLevelId: e.posLevelId, //*ระดับตำแหน่ง + posExecutiveId: e.posExecutiveId, //ตำแหน่งทางการบริหาร posDictExecutiveField: e.positionName, //ด้านทางการบริหาร posDictArea: e.positionArea, //ด้าน/สาขา })); @@ -218,22 +324,57 @@ function onSubmit() { posMasterNoPrefix: formData.prefixNo, //*Prefix นำหน้าเลขที่ตำแหน่ง เป็น Optional (ไม่ใช่อักษรย่อของหน่วยงาน/ส่วนราชการ) posMasterNo: Number(formData.positionNo), //*เลขที่ตำแหน่ง เป็นตัวเลข posMasterNoSuffix: formData.suffixNo, //Suffix หลังเลขที่ตำแหน่ง เช่น ช. - // orgRootId: Guid, //Id สำนัก - // orgChild1Id: Guid, //Id โครงสร้างระดับ1 - // orgChild2Id: Guid, //Id โครงสร้างระดับ2 - // orgChild3Id: Guid, //Id โครงสร้างระดับ3 - // orgChild4Id: Guid, //Id โครงสร้างระดับ4 + orgRootId: props.orgLevel === 0 ? props.treeId : null, //Id สำนัก + orgChild1Id: props.orgLevel === 1 ? props.treeId : null, + orgChild2Id: props.orgLevel === 2 ? props.treeId : null, + orgChild3Id: props.orgLevel === 3 ? props.treeId : null, + orgChild4Id: props.orgLevel === 4 ? props.treeId : null, positions: [positionsData], }; console.log(body); + // showLoader(); + // await http + // .post(config.API.orgPosMaster, body) + // .then((res) => { + // success($q, "เพิ่มข้อมูลสำเร็จ"); + // }) + // .catch((err) => { + // messageError($q, err); + // }) + // .finally(() => { + // props.close?.(); + // hideLoader(); + // }); }); } /** ฟังชั่น บันทึก */ function onSubmitSelectEdit() { dialogConfirm( $q, - () => { - console.log(formPositionSelect); + async () => { + showLoader(); + const body = { + posDictName: formPositionSelect.positionName, + posDictField: formPositionSelect.positionField, //สายงาน + posTypeId: formPositionSelect.positionType, //*ประเภทตำแหน่ง + posLevelId: formPositionSelect.positionLevel, //*ระดับตำแหน่ง + posExecutiveId: formPositionSelect.positionExecutive, //ตำแหน่งทางการบริหาร + posDictExecutiveField: formPositionSelect.positionExecutiveField, //ด้านทางการบริหาร + posDictArea: formPositionSelect.positionArea, //ด้าน/สาขา + }; + await http + .post(config.API.orgPosPosition, body) + .then(() => { + success($q, "เพิ่มข้อมูลสำเร็จ"); + + clearFormPositionSelect(); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); }, "ยืนยันการเพิ่มตำแหน่ง", "ต้องการยืนยันการเพิ่มตำแหน่งนี้ใช่หรือไม่?" @@ -250,40 +391,22 @@ const searchRef = ref(null); async function searchInput() { searchRef.value.validate(); if (!searchRef.value.hasError) { - // จำลอง - const dataList = [ - { - positionId: "x1", - positionName: "นักกายภาพบำบัด", - positionField: "จัดการงานทั่วไป", - positionType: "วิชาการ", - positionLevel: "ชำนาญการ", - positionExecutive: "การพยาบาลทั่วไป", - positionExecutiveField: "การพยาบาลทั่วไป", - positionArea: "การพยาบาลทั่วไป", - }, - { - positionId: "x2", - positionName: "นักทรัพยากรบุคคล", - positionField: "จัดการงานทั่วไป", - positionType: "ทั่วไป", - positionLevel: "ชำนาญการ", - positionExecutive: "-", - positionExecutiveField: "-", - positionArea: "-", - }, - { - positionId: "x3", - positionName: "นักทรัพยากรบุคคล", - positionField: "จัดการงานทั่วไป", - positionType: "วิชาการ", - positionLevel: "ชำนาญการพิเศษ", - positionExecutive: "-", - positionExecutiveField: "-", - positionArea: "-", - }, - ]; - rowsPositionSelect.value = dataList; + showLoader(); + await http + .get( + config.API.orgPosPosition + + `?keyword=${search.value}&type=${type.value}` + ) + .then((res) => { + console.log(res); + rowsPositionSelect.value = res.data.result; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); } } @@ -295,9 +418,9 @@ function copyDetiail(data: RowDetailPositions) { formPositionSelect.positionId = data.positionId; formPositionSelect.positionName = data.positionName; formPositionSelect.positionField = data.positionField; - formPositionSelect.positionType = data.positionType; - formPositionSelect.positionLevel = data.positionLevel; - formPositionSelect.positionExecutive = data.positionExecutive; + formPositionSelect.positionType = data.posTypeId; + formPositionSelect.positionLevel = data.posLevelId; + formPositionSelect.positionExecutive = data.posExecutiveId; formPositionSelect.positionExecutiveField = data.positionExecutiveField; formPositionSelect.positionArea = data.positionArea; } @@ -317,14 +440,19 @@ watch( () => props.modal, () => { if (props.modal === true) { + fetchType(); + fetchLevel(); + fetchExecutive(); + rowsPositionSelect.value = []; + search.value = ""; + rows.value = []; + clearFormPositionSelect(); } } ); function addPosition(data: RowDetailPositions) { - const isIdExist = rows.value.some( - (item) => item.positionId === data.positionId - ); + const isIdExist = rows.value.some((item) => item.id === data.id); if (!isIdExist) { rows.value = [data, ...rows.value]; @@ -333,9 +461,42 @@ function addPosition(data: RowDetailPositions) { function deleteData(id: string) { const dataRow = rows.value; - const updatedRows = dataRow.filter((item: any) => item.positionId !== id); + const updatedRows = dataRow.filter((item: any) => item.id !== id); rows.value = updatedRows; } + +function deletePos(id: string) { + dialogRemove($q, () => { + showLoader(); + http + .delete(config.API.orgPosPositionById(id)) + .then((res) => { + success($q, "ลบข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + searchInput(); + hideLoader(); + }); + }); +} + +async function clearFormPositionSelect() { + isDisValidate.value = await true; + formPositionSelect.positionId = ""; + formPositionSelect.positionName = ""; + formPositionSelect.positionField = ""; + formPositionSelect.positionType = ""; + formPositionSelect.positionLevel = ""; + formPositionSelect.positionExecutive = ""; + formPositionSelect.positionExecutiveField = ""; + formPositionSelect.positionArea = ""; + setTimeout(async () => { + isDisValidate.value = await false; + }, 1000); +}