From f236159522ac367df8e93f9fe28993f821390b7c Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Tue, 30 Jan 2024 14:18:44 +0700 Subject: [PATCH] =?UTF-8?q?=20API=20=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA=E0=B8=A3?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=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 | 1 + .../components/DialogFormAgency.vue | 147 +++++++--- .../components/listView.vue | 180 +++--------- .../components/mainTree.vue | 259 ++++++++++++------ .../store/organizational.ts | 16 ++ 5 files changed, 338 insertions(+), 265 deletions(-) diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index cff33b2ff..3adff540b 100644 --- a/src/api/02_organizational/api.organization.ts +++ b/src/api/02_organizational/api.organization.ts @@ -5,6 +5,7 @@ const organization = `${env.API_URI}/org`; export default { /** โครงสร้างอัตรากำลัง*/ activeOrganization: `${organization}/active`, + orgByid: (id: string) => `${organization}/${id}`, createOrganization: `${organization}/draft`, createOrgLevel: (type: string) => `${organization}/${type}`, orgLevelByid: (type: string, id: string) => `${organization}/${type}/${id}`, diff --git a/src/modules/02_organizationalNew/components/DialogFormAgency.vue b/src/modules/02_organizationalNew/components/DialogFormAgency.vue index a4f33f7cf..18295dc3c 100644 --- a/src/modules/02_organizationalNew/components/DialogFormAgency.vue +++ b/src/modules/02_organizationalNew/components/DialogFormAgency.vue @@ -15,16 +15,31 @@ import DialogHeader from "@/components/DialogHeader.vue"; import { useOrganizational } from "@/modules/02_organizationalNew/store/organizational"; import { useCounterMixin } from "@/stores/mixin"; -const level = defineModel("orgLevel", { required: true }); +const level = defineModel("orgLevel", { required: true }); +const actionType = defineModel("actionType", { required: true }); const props = defineProps({ - modal: Boolean, - close: Function, + modal: { + type: Boolean, + require: true, + }, + close: { + type: Function, + require: true, + }, + fetchDataTree: { + type: Function, + require: true, + }, + dataNode: { + type: Object, + require: true, + }, }); const $q = useQuasar(); const store = useOrganizational(); const mixin = useCounterMixin(); -const { dialogConfirm, showLoader, hideLoader } = mixin; +const { dialogConfirm, showLoader, hideLoader, messageError, success } = mixin; const orgLevelOptionMain = ref([ { name: "ระดับสำนัก", id: "DEPARTMENT" }, @@ -87,29 +102,28 @@ function validateForm() { /** ฟังชั่น บันทึก */ function onSubmit() { + console.log(level.value); dialogConfirm($q, async () => { - showLoader(); - const type = - level.value === "DEPARTMENT" - ? "Root" - : level.value === "OFFICE" - ? "Child1" - : level.value === "DIVISION" - ? "Child2" - : level.value === "SECTION" - ? "Child3" - : "child4"; - + // showLoader(); + const type = store.checkLevel(level.value); const nameId = - level.value === "DEPARTMENT" + level.value === 0 ? "orgRevisionId" - : level.value === "OFFICE" + : level.value === 1 ? "orgRootId" - : level.value === "DIVISION" + : level.value === 2 ? "orgChild1Id" - : level.value === "SECTION" + : level.value === 3 ? "orgChild2Id" : "orgChild3Id"; + + let rootId: string = ""; + if (actionType.value === "ADD") { + rootId = level.value === 0 ? store.draftId : props.dataNode?.orgTreeId; + } else { + rootId = level.value === 0 ? store.draftId : props.dataNode?.orgRootId; + } + const body = { ["org" + type + "Name"]: formData.orgName, ["org" + type + "ShortName"]: formData.orgShortName, @@ -118,34 +132,87 @@ function onSubmit() { ["org" + type + "PhoneIn"]: formData.orgPhoneIn, ["org" + type + "Fax"]: formData.orgFax, ["org" + type + "Rank"]: formData.orgLevel, - [nameId]: store.draftId, + [nameId]: rootId, }; console.log(body); - await http - .post(config.API.createOrgLevel(type.toLocaleLowerCase()), body) - .then((res) => { - console.log(res); - }) - .catch((err) => { - console.log(err); - }) - .finally(() => { - close(); - hideLoader(); - }); + + if (actionType.value === "ADD") { + await http + .post(config.API.createOrgLevel(type.toLocaleLowerCase()), body) + .then((res) => { + console.log(res); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + console.log(err); + messageError($q, err); + }) + .finally(async () => { + await props.fetchDataTree?.(); + await closeClear(); + await hideLoader(); + }); + } else { + props.dataNode && + (await http + .put( + config.API.orgLevelByid( + type.toLocaleLowerCase(), + props.dataNode.orgTreeId + ), + body + ) + .then((res) => { + console.log(res); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + console.log(err); + messageError($q, err); + }) + .finally(async () => { + await props.fetchDataTree?.(); + await closeClear(); + await hideLoader(); + })); + } }); } +function closeClear() { + formData.orgName = ""; + formData.orgShortName = ""; + formData.orgCode = ""; + formData.orgPhoneEx = ""; + formData.orgPhoneIn = ""; + formData.orgFax = ""; + formData.orgLevel = ""; + props.close?.(); +} + watch( () => props.modal, () => { if (props.modal === true) { - if (level.value === "DEPARTMENT") { - formData.orgLevel = level.value; - orgLevelOption.value = orgLevelOptionMain.value; + if (actionType.value === "ADD") { + if (level.value === 0) { + formData.orgLevel = "DEPARTMENT"; + orgLevelOption.value = orgLevelOptionMain.value; + } else { + orgLevelOption.value = orgLevelOptionMain.value.slice(1, 4); + formData.orgLevel = ""; + } } else { - orgLevelOption.value = orgLevelOptionMain.value.slice(1, 4); - formData.orgLevel = ""; + if (props.dataNode) { + formData.orgName = props.dataNode.orgTreeName; + formData.orgShortName = props.dataNode.orgTreeShortName; + formData.orgCode = props.dataNode.orgTreeCode; + formData.orgPhoneEx = props.dataNode.orgTreePhoneEx; + formData.orgPhoneIn = props.dataNode.orgTreePhoneIn; + formData.orgFax = props.dataNode.orgTreeFax; + formData.orgLevel = props.dataNode.orgTreeRank; + orgLevelOption.value = orgLevelOptionMain.value; + } } } } @@ -156,7 +223,7 @@ watch(
- +
@@ -198,7 +265,7 @@ watch(
-import { ref, onMounted } from "vue"; +import { ref, onMounted, watch } from "vue"; +import { useQuasar } from "quasar"; +import http from "@/plugins/http"; +import config from "@/app.config"; /** importType*/ import type { DataActive } from "@/modules/02_organizationalNew/interface/response/organizational"; @@ -7,158 +10,59 @@ import type { DataActive } from "@/modules/02_organizationalNew/interface/respon import TreeView from "@/modules/02_organizationalNew/components/mainTree.vue"; import TableView from "@/modules/02_organizationalNew/components/tableTree.vue"; +import { useOrganizational } from "@/modules/02_organizationalNew/store/organizational"; +import { useCounterMixin } from "@/stores/mixin"; + +const store = useOrganizational(); +const $q = useQuasar(); +const { showLoader, hideLoader, messageError } = useCounterMixin(); + const showData = ref(false); const nodeTree = ref(); // defineProps<{ dataActive: DataActive }>(); async function fetchDataTree() { - const data = [ - { - organizationName: "สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร", - organizationId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx01", - organizationLevel: 0, - lazy: true, - }, - { - organizationName: "สำนักปลัดกรุงเทพมหานคร", - organizationId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx02", - organizationLevel: 0, - lazy: true, - }, - ]; - - // const data = [ - // { - // orgRootId: "00000000-0000-0000-0000-000000000000", - // orgLevel: 0, - // orgRootName: "ปลัดกรุงเทพ", - // orgRootShortName: "ก.น.", - // orgRootCode: "04", - // orgCode: "0400", - // orgRootOrder: 1, - // orgRootPhoneEx: "0849562355", - // orgRootPhoneIn: "0845124512", - // orgRootFax: "021576452", - // orgRevisionId: "00000000-0000-0000-0000-000000000000", - // orgChild1: [ - // { - // orgChild1Id: "00000000-0000-0000-0000-000000000000", - // orgLevel: 1, - // orgChild1Name: "ปลัดกรุงเทพ", - // orgChild1ShortName: "ก.น.", - // orgChild1Code: "01", - // orgCode: "0401", - // orgChild1Order: 1, - // orgRootCode: "04", - // orgChild1PhoneEx: "0849562355", - // orgChild1PhoneIn: "0845124512", - // orgChild1Fax: "021576452", - // orgRevisionId: "00000000-0000-0000-0000-000000000000", - // orgChild2: [ - // { - // orgChild2Id: "00000000-0000-0000-0000-000000000000", - // orgLevel: 2, - // orgChild2Name: "ปลัดกรุงเทพ", - // orgChild2ShortName: "ก.น.", - // orgChild2Code: "01", - // orgCode: "0401", - // orgChild2Order: 1, - // orgRootCode: "04", - // orgChild2PhoneEx: "0849562355", - // orgChild2PhoneIn: "0845124512", - // orgChild2Fax: "021576452", - // orgRevisionId: "00000000-0000-0000-0000-000000000000", - // orgChild3: [ - // { - // orgChild3Id: "00000000-0000-0000-0000-000000000000", - // orgLevel: 3, - // orgChild3Name: "ปลัดกรุงเทพ", - // orgChild3ShortName: "ก.น.", - // orgChild3Code: "01", - // orgCode: "0401", - // orgChild3Order: 1, - // orgRootCode: "04", - // orgChild3PhoneEx: "0849562355", - // orgChild3PhoneIn: "0845124512", - // orgChild3Fax: "021576452", - // orgRevisionId: "00000000-0000-0000-0000-000000000000", - // lazy: true, - // orgChild4: [ - // { - // orgChild4Id: "00000000-0000-0000-0000-000000000000", - // orgLevel: 4, - // orgChild4Name: "ปลัดกรุงเทพ", - // orgChild4ShortName: "ก.น.", - // orgChild4Code: "01", - // orgCode: "0401", - // orgChild4Order: 1, - // orgChild4PhoneEx: "0849562355", - // orgChild4PhoneIn: "0845124512", - // orgChild4Fax: "021576452", - // orgRevisionId: "00000000-0000-0000-0000-000000000000", - // lazy: true, - // orgRootCode: "04", - // }, - // ], - // }, - // ], - // }, - // ], - // }, - // ], - // }, - - // { - // orgRootId: "00000000-0000-0000-0000-000000000001", - // orgLevel: 0, - // orgRootName: "ปลัดกรุงเทพ2", - // orgRootShortName: "ก.น.", - // orgRootCode: "04", - // orgCode: "0400", - // orgRootOrder: 1, - // orgRootPhoneEx: "0849562355", - // orgRootPhoneIn: "0845124512", - // orgRootFax: "021576452", - // orgRevisionId: "00000000-0000-0000-0000-000000000000", - // orgChild1: [ - // { - // orgChild1Id: "00000000-0000-0000-0000-000000000000", - // orgLevel: 1, - // orgChild1Name: "ปลัดกรุงเทพ2", - // orgChild1ShortName: "ก.น.", - // orgChild1Code: "01", - // orgCode: "0401", - // orgChild1Order: 1, - // orgRootCode: "04", - // orgChild1PhoneEx: "0849562355", - // orgChild1PhoneIn: "0845124512", - // orgChild1Fax: "021576452", - // orgRevisionId: "00000000-0000-0000-0000-000000000000", - // orgChild2: [], - // }, - // ], - // }, - // ]; - - - - nodeTree.value = data; - console.log(nodeTree.value); + showLoader(); + const id = + store.typeOrganizational === "current" ? store.activeId : store.draftId; + id && + (await http + .get(config.API.orgByid(id.toString())) + .then((res) => { + const data = res.data.result; + nodeTree.value = data; + console.log(res); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + })); + // console.log(nodeTree.value); } - - -onMounted(() => { - fetchDataTree(); +onMounted(async () => { + await fetchDataTree(); }); + +watch( + () => store.typeOrganizational, + () => { + fetchDataTree(); + } +);