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] =?UTF-8?q?=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA?= =?UTF-8?q?=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B8=AD=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=81=E0=B8=B3=E0=B8=A5=E0=B8=B1=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); +}