From 8c1bfb7a75678a020f11522d2f407857abcb0d78 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 29 Jan 2024 11:19:48 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=20UI=20?= =?UTF-8?q?=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA=E0=B8=A3=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/DialogFormAgency.vue | 106 +++++++++------- .../components/DialogNewStructure.vue | 118 +++++++++++++++--- .../components/mainTree.vue | 15 ++- .../interface/index/Main.ts | 76 +++++------ .../store/organizational.ts | 15 +++ .../02_organizationalNew/views/main.vue | 18 ++- 6 files changed, 237 insertions(+), 111 deletions(-) diff --git a/src/modules/02_organizationalNew/components/DialogFormAgency.vue b/src/modules/02_organizationalNew/components/DialogFormAgency.vue index 0d569ccf0..84660ee43 100644 --- a/src/modules/02_organizationalNew/components/DialogFormAgency.vue +++ b/src/modules/02_organizationalNew/components/DialogFormAgency.vue @@ -9,6 +9,7 @@ import type { DataOption, } from "@/modules/02_organizationalNew/interface/index/Main"; +const level = defineModel("orgLevel", { required: true }); const props = defineProps({ modal: Boolean, close: Function, @@ -18,35 +19,46 @@ const $q = useQuasar(); const mixin = useCounterMixin(); const { dialogConfirm } = mixin; -const ocLevelOp = ref([]); +const orgLevelOptionMain = ref([ + { name: "ระดับสำนัก", id: "DEPARTMENT" }, + { + name: "ระดับกอง/สำนักงาน/ส่วนราชการ/โรงพยาบาล/เทียบเท่ากอง", + id: "OFFICE", + }, + { name: "ระดับส่วน/กลุ่มภารกิจ", id: "DIVISION" }, + { name: "ระดับฝ่าย/กลุ่มงาน", id: "SECTION" }, +]); -const ocNameRef = ref(null); -const shortNameRef = ref(null); -const ocNoRef = ref(null); -const ocLevelRef = ref(null); -const telOutRef = ref(null); -const telInRef = ref(null); -const telRef = ref(null); +const orgLevelOption = ref([]); + +const orgNameRef = ref(null); +const orgShortNameRef = ref(null); +const orgCodeRef = ref(null); +const orgPhoneExRef = ref(null); +const orgPhoneInRef = ref(null); +const orgFaxRef = ref(null); +const orgLevelRef = ref(null); const formData = reactive({ - ocName: "", - shortName: "", - ocNo: "", - ocLevel: "", - telOut: "", - telIn: "", - tel: "", + orgName: "", + orgShortName: "", + orgCode: "", + orgPhoneEx: "", + orgPhoneIn: "", + orgFax: "", + orgRevisionId: "", + orgLevel: "", }); /** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */ const objectComplaintsRef: FormAgencyRef = { - ocName: ocNameRef, - shortName: shortNameRef, - ocNo: ocNoRef, - ocLevel: ocLevelRef, - telOut: telOutRef, - telIn: telInRef, - tel: telRef, + orgName: orgNameRef, + orgShortName: orgShortNameRef, + orgCode: orgCodeRef, + orgPhoneEx: orgPhoneExRef, + orgPhoneIn: orgPhoneInRef, + orgFax: orgFaxRef, + orgLevel: orgLevelRef, }; /** ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม */ @@ -70,7 +82,7 @@ function validateForm() { /** ฟังชั่น บันทึก */ function onSubmit() { dialogConfirm($q, () => { - console.log(formData) + console.log(formData); }); } @@ -78,16 +90,13 @@ watch( () => props.modal, () => { if (props.modal === true) { - ocLevelOp.value = [ - { - id: "id1", - name: "id1", - }, - { - id: "id2", - name: "id2", - }, - ]; + if (level.value === "DEPARTMENT") { + formData.orgLevel = level.value; + orgLevelOption.value = orgLevelOptionMain.value; + } else { + orgLevelOption.value = orgLevelOptionMain.value.splice(1, 4); + formData.orgLevel = ""; + } } } ); @@ -104,8 +113,8 @@ watch(
("newStructure", { required: true }); const status = defineModel("status", { required: true }); +const type = defineModel("type", { default: "NEW" }); const typeOp = ref([ { @@ -41,19 +43,25 @@ const typeOp = ref([ name: "ทำสำเนาโครงสร้าง ตำแหน่ง และคนครอง", }, ]); +const orgRevisionId = ref(""); +const orgRevisionOpMain = ref([]); +const orgRevisionOp = ref([]); const orgRevisionNameRef = ref(null); const typeRef = ref(null); +const orgRevisionIdRef = ref(null); const formData = reactive({ + orgRevisionId: "", orgRevisionName: "", - type: "", + typeDraft: "", }); /** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */ const objectRef: FormNewStructureRef = { orgRevisionName: orgRevisionNameRef, type: typeRef, + orgRevisionId: orgRevisionIdRef, }; /** ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม */ @@ -77,31 +85,75 @@ function validateForm() { /** ฟังชั่น บันทึก */ function onSubmit() { dialogConfirm($q, () => { - // http - // .post(config.API.createOrganization, formData) - // .then(() => { - status.value = true; - store.typeOrganizational = "draft"; - success($q, "บันทึกข้อมูลสำเร็จ"); - // }) - // .catch((err) => { - // messageError($q, err); - // }) - // .finally(() => {}); - - console.log(formData); + showLoader(); + http + .post(config.API.createOrganization, formData) + .then(() => { + status.value = true; + store.typeOrganizational = "draft"; + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(async () => { + modal.value = await false; + await close(); + await hideLoader(); + }); }); - modal.value = false; } function close() { modal.value = false; + formData.orgRevisionId = ""; + formData.orgRevisionName = ""; + formData.typeDraft = ""; +} + +async function fetchOrgRevision() { + showLoader(); + await http + .get(config.API.organizationHistoryNew) + .then((res) => { + const data = res.data.result.filter( + (e: HistoryType) => e.orgRevisionIsDraft === false + ); + if (data) { + const listOption = data.map((e: HistoryType) => ({ + id: e.orgRevisionId, + name: e.orgRevisionName, + })); + orgRevisionOpMain.value = listOption; + } + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +function filterSelector(val: any, update: Function, refData: string) { + switch (refData) { + case "orgRevisionId": + update(() => { + orgRevisionOp.value = orgRevisionOpMain.value.filter( + (v: DataOption) => v.name.indexOf(val) > -1 + ); + }); + break; + default: + break; + } } watch( () => modal.value, () => { - modal.value && !status.value && (formData.type = "NEW"); + modal.value && (formData.typeDraft = type.value); + modal.value && type.value !== "NEW" && fetchOrgRevision(); } ); @@ -131,7 +183,7 @@ watch( +
+ + + +
diff --git a/src/modules/02_organizationalNew/components/mainTree.vue b/src/modules/02_organizationalNew/components/mainTree.vue index 1ad991898..4846cb152 100644 --- a/src/modules/02_organizationalNew/components/mainTree.vue +++ b/src/modules/02_organizationalNew/components/mainTree.vue @@ -64,6 +64,7 @@ const expanded = ref>([]); const notFound = ref("ไม่พบข้อมูลที่ค้นหา"); const noData = ref("ไม่มีข้อมูล"); const selected = ref(""); +const orgLevel = ref(""); const filterData = (node: any, filter: string) => { // ให้ทาง API ค้นหาให้ @@ -225,8 +226,9 @@ function searchAndReplace( } const dialogAgency = ref(false); -function onClickAgency() { +function onClickAgency(level: string) { dialogAgency.value = !dialogAgency.value; + orgLevel.value = level; } watch( @@ -277,7 +279,7 @@ onMounted(async () => { round color="primary" icon="add" - @click="onClickAgency" + @click="onClickAgency('DEPARTMENT')" > เพิ่มหน่วยงาน @@ -347,6 +349,8 @@ onMounted(async () => { @click=" item.val === 'EDIT' ? edit(prop.node.organizationId) + : item.val === 'ADD' + ? onClickAgency('TEST') : null " > @@ -370,7 +374,12 @@ onMounted(async () => { - + + diff --git a/src/modules/02_organizationalNew/interface/index/Main.ts b/src/modules/02_organizationalNew/interface/index/Main.ts index 37302deba..b5f3da8a3 100644 --- a/src/modules/02_organizationalNew/interface/index/Main.ts +++ b/src/modules/02_organizationalNew/interface/index/Main.ts @@ -8,36 +8,37 @@ interface DataOption { } interface FormDataAgency { - ocName: string - shortName: string - ocNo: string - ocLevel: string - telOut: string - telIn: string - tel: string + orgName: string; + orgShortName: string; + orgCode: string; + orgPhoneEx: string; + orgPhoneIn: string; + orgFax: string; + orgRevisionId: string; + orgLevel: string; } interface FormDataPosition { - prefixNo: string - positionNo: string - suffixNo: string - confirm: boolean + prefixNo: string; + positionNo: string; + suffixNo: string; + confirm: boolean; } interface FormDataNewStructure { - orgRevisionName: string - type: string - + orgRevisionId: string; + orgRevisionName: string; + typeDraft: string; } interface FormAgencyRef { - ocName: object | null; - shortName: object | null; - ocNo: object | null; - ocLevel: object | null; - telOut: object | null; - telIn: object | null; - tel: object | null; + orgName: object | null; + orgShortName: object | null; + orgCode: object | null; + orgPhoneEx: object | null; + orgPhoneIn: object | null; + orgFax: object | null; + orgLevel: object | null; [key: string]: any; } @@ -54,26 +55,27 @@ interface FormDateTimeRef { interface FormNewStructureRef { orgRevisionName: object | null; + orgRevisionId: object | null; type: object | null; [key: string]: any; } interface HistoryType { - orgRevisionId: string - orgRevisionName: string - orgRevisionIsCurrent: boolean - orgRevisionIsDraft: boolean - orgRevisionCreatedAt: any + orgRevisionId: string; + orgRevisionName: string; + orgRevisionIsCurrent: boolean; + orgRevisionIsDraft: boolean; + orgRevisionCreatedAt: any; } -export type { - Pagination, - DataOption, - FormDataAgency, - FormDataPosition, - FormAgencyRef, - FormPositionRef, - FormDateTimeRef, - FormDataNewStructure, - FormNewStructureRef, - HistoryType +export type { + Pagination, + DataOption, + FormDataAgency, + FormDataPosition, + FormAgencyRef, + FormPositionRef, + FormDateTimeRef, + FormDataNewStructure, + FormNewStructureRef, + HistoryType, }; diff --git a/src/modules/02_organizationalNew/store/organizational.ts b/src/modules/02_organizationalNew/store/organizational.ts index 303455ecb..efa6b313b 100644 --- a/src/modules/02_organizationalNew/store/organizational.ts +++ b/src/modules/02_organizationalNew/store/organizational.ts @@ -1,12 +1,27 @@ import { defineStore } from "pinia"; import { ref } from "vue"; +/** importType*/ +import type { DataActive } from "@/modules/02_organizationalNew/interface/response/organizational"; + export const useOrganizational = defineStore("organizationalStore", () => { const typeOrganizational = ref("current"); const statusView = ref("list"); + const dataActive = ref(); + const activeId = ref(); + const draftId = ref(); + function fetchDataActive(data: DataActive) { + activeId.value = data.activeId; + draftId.value = data.draftId; + dataActive.value = data; + } + return { typeOrganizational, statusView, + + // + fetchDataActive, }; }); diff --git a/src/modules/02_organizationalNew/views/main.vue b/src/modules/02_organizationalNew/views/main.vue index a13d418c3..4e5c52f64 100644 --- a/src/modules/02_organizationalNew/views/main.vue +++ b/src/modules/02_organizationalNew/views/main.vue @@ -5,7 +5,6 @@ import http from "@/plugins/http"; import config from "@/app.config"; /** importType*/ -import type { DataActive } from "@/modules/02_organizationalNew/interface/response/organizational"; /** importComponents*/ import ListView from "@/modules/02_organizationalNew/components/listView.vue"; @@ -21,7 +20,6 @@ import { useCounterMixin } from "@/stores/mixin"; const $q = useQuasar(); const { showLoader, hideLoader, messageError } = useCounterMixin(); -const modalNewStructure = ref(false); const stroe = useOrganizational(); const isStatusData = ref(false); @@ -45,16 +43,15 @@ const itemStructure = ref([ name: "ทำสำเนาโครงสร้าง ตำแหน่งและคนครอง", }, ]); -const dataActive = ref(); async function fetchOrganizationActive() { showLoader(); await http .get(config.API.activeOrganization) .then((res) => { - console.log(res); const data = res.data.result; if (data) { + stroe.fetchDataActive(data); if (data.activeName === null && data.draftName === null) { isStatusData.value = false; } else { @@ -79,6 +76,13 @@ async function fetchOrganizationActive() { }); } +const modalNewStructure = ref(false); +const typeStructure = ref(""); +function ocClickAddStructure(type: string) { + modalNewStructure.value = !modalNewStructure.value; + typeStructure.value = type; +} + const modalDateTime = ref(false); function onClickDateTime() { modalDateTime.value = !modalDateTime.value; @@ -137,7 +141,7 @@ onMounted(async () => { color="primary" size="lg" icon="add" - @click="modalNewStructure = true" + @click="ocClickAddStructure('NEW')" > เพิ่มโครงสร้าง @@ -175,6 +179,7 @@ onMounted(async () => { v-close-popup v-for="(item, index) in itemStructure" :key="index" + @click="ocClickAddStructure(item.val)" > {{ item.name }} @@ -222,10 +227,13 @@ onMounted(async () => { + +