Refactoring code module 02_organization

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-11 17:00:27 +07:00
parent 63b9aafbaf
commit 0f5d772e53
24 changed files with 805 additions and 1033 deletions

View file

@ -1,9 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, watch, defineProps } from "vue"; import { ref, reactive, watch, defineProps } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
/** /**
* importType * importType
@ -12,9 +13,12 @@ import type {
DataOption, DataOption,
FormPositionSelect, FormPositionSelect,
} from "@/modules/02_organization/interface/index/Main"; } from "@/modules/02_organization/interface/index/Main";
import type {
DataPosType,
DataLevel,
} from "@/modules/02_organization/interface/response/Main";
import type { import type {
OptionType, OptionType,
OptionLevel,
OptionExecutive, OptionExecutive,
} from "@/modules/02_organization/interface/response/organizational"; } from "@/modules/02_organization/interface/response/organizational";
@ -33,9 +37,8 @@ const { dialogConfirm, showLoader, hideLoader, messageError, success } = mixin;
/** /**
* props * props
*/ */
const modal = defineModel<boolean>("modalAdd", { required: true }); // , popup
const modal = defineModel<boolean>("modalAdd", { required: true }); const isEditCheck = defineModel<boolean>("isEdit", { required: true }); //
const isEditCheck = defineModel<boolean>("isEdit", { required: true });
const props = defineProps({ const props = defineProps({
emitSearch: Function, emitSearch: Function,
getData: Function, getData: Function,
@ -43,20 +46,20 @@ const props = defineProps({
levelOp: Object, levelOp: Object,
}); });
const dataLevel = ref<any>();
const posExecutive = ref<string>("");
const isSpecial = ref<boolean>(false);
const shape = ref<string>("false");
const isReadonly = ref<boolean>(false); // const isReadonly = ref<boolean>(false); //
const dataLevel = ref<DataPosType[]>([]); //
const posExecutive = ref<string>(""); //
const isSpecial = ref<boolean>(false); //
const shape = ref<string>("false"); //
const isDisValidate = ref<boolean>(false); const isDisValidate = ref<boolean>(false);
const typeOpsMain = ref<DataOption[]>([]); const typeOpsMain = ref<DataOption[]>([]); //
const levelOpsMain = ref<DataOption[]>([]); const levelOpsMain = ref<DataOption[]>([]); //
const executiveOpsMain = ref<DataOption[]>([]); const executiveOpsMain = ref<DataOption[]>([]); //
const executiveOps = ref<DataOption[]>([]); const typeOps = ref<DataOption[]>([]); //
const typeOps = ref<DataOption[]>([]); const levelOps = ref<DataOption[]>([]); //
const levelOps = ref<DataOption[]>([]); const executiveOps = ref<DataOption[]>([]); //
const shapeOp = ref<DataOption[]>([ const shapeOp = ref<DataOption[]>([
{ {
id: "false", id: "false",
@ -67,6 +70,8 @@ const shapeOp = ref<DataOption[]>([
name: "เพิ่มใหม่", name: "เพิ่มใหม่",
}, },
]); ]);
//
const formPositionSelect = reactive<FormPositionSelect>({ const formPositionSelect = reactive<FormPositionSelect>({
positionId: "", positionId: "",
positionName: "", positionName: "",
@ -92,7 +97,7 @@ function validateFormPositionEdit() {
} }
/** /**
* นทกการแกไข * นทกการแกไขตำแหน
*/ */
function saveSelectEdit() { function saveSelectEdit() {
dialogConfirm( dialogConfirm(
@ -150,7 +155,7 @@ function saveSelectEdit() {
); );
} }
/** /**
* งช นท * งชนทการเพมขอมลตำแหน
*/ */
function onSubmitSelectEdit() { function onSubmitSelectEdit() {
dialogConfirm( dialogConfirm(
@ -212,11 +217,13 @@ function onSubmitSelectEdit() {
} }
/** /**
* งช เครยลฟอร * งชนเคลยรฟอรมขอม
*
* กำหนดคาฟอรมขอมลเปนค Default
*/ */
async function clearFormPositionSelect() { async function clearFormPositionSelect() {
isEditCheck.value = false; isEditCheck.value = false;
isDisValidate.value = await true; isDisValidate.value = true;
formPositionSelect.positionId = ""; formPositionSelect.positionId = "";
formPositionSelect.positionName = ""; formPositionSelect.positionName = "";
formPositionSelect.positionField = ""; formPositionSelect.positionField = "";
@ -227,10 +234,76 @@ async function clearFormPositionSelect() {
formPositionSelect.positionArea = ""; formPositionSelect.positionArea = "";
isSpecial.value = false; isSpecial.value = false;
setTimeout(async () => { setTimeout(async () => {
isDisValidate.value = await false; isDisValidate.value = false;
}, 1000); }, 1000);
} }
/**
* งกเรยกขอมลรายการประเภทตำแหน
*/
async function fetchType() {
await http
.get(config.API.orgPosType)
.then(async (res) => {
dataLevel.value = await res.data.result;
typeOpsMain.value = res.data.result.map((e: OptionType) => ({
id: e.id,
name: e.posTypeName,
}));
typeOps.value = typeOpsMain.value;
})
.catch((err) => {
messageError($q, err);
});
}
/**
* งกนกำหนดตวเลอกประเภทตำแหนงตาม id ประเภทตำแหน
* @param val id ประเภทตำแหน
*/
async function updateSelectType(val: string) {
//
const listLevel = dataLevel.value.find((e: DataPosType) => e.id === val);
levelOpsMain.value =
listLevel?.posLevels.map((e: DataLevel) => ({
id: e.id,
name: e.posLevelName ? e.posLevelName.toString() : "",
})) || [];
levelOps.value = levelOpsMain.value;
formPositionSelect.positionLevel = "";
}
/**
* งกเรยกขอมลรายการตำแหนงทางการบรหาร
*/
async function fetchExecutive() {
await http
.get(config.API.orgPosExecutive)
.then(async (res) => {
executiveOpsMain.value = await res.data.result.map(
(e: OptionExecutive) => ({
id: e.id,
name: e.posExecutiveName,
})
);
executiveOps.value = executiveOpsMain.value;
})
.catch((err) => {
messageError($q, err);
});
}
/**
* งกนป Popup
*
* และเรยก clearFormPositionSelect() เพอกำหนดฟอรมขอมลเป Default
*/
function close() {
modal.value = false;
clearFormPositionSelect();
}
/** /**
* งค css ออกไปตามเงอนไข * งค css ออกไปตามเงอนไข
* @param val true/false * @param val true/false
@ -243,57 +316,11 @@ function inputEdit(val: boolean) {
} }
/** /**
* function เลอกประเภทตำแหน * การเปลยนแปลงของ modal.value
* @param val id ประเภทตำแหน *
* าเป true ทำการเรยกขอมลรายการประเภทตำแหน และ อมลรายการตำแหนงทางการบรหาร
* และถาม props.data จะกำหนด formPositionSelect เปนตาม props.data
*/ */
function updateSelectType(val: string) {
//
const listLevel = dataLevel.value.find((e: any) => e.id === val);
levelOpsMain.value = listLevel.posLevels.map((e: OptionLevel) => ({
id: e.id,
name: e.posLevelName,
}));
levelOps.value = levelOpsMain.value;
formPositionSelect.positionLevel = "";
}
function close() {
modal.value = false;
clearFormPositionSelect();
}
async function fetchType() {
http
.get(config.API.orgPosType)
.then((res) => {
dataLevel.value = res.data.result;
typeOpsMain.value = res.data.result.map((e: OptionType) => ({
id: e.id,
name: e.posTypeName,
}));
typeOps.value = typeOpsMain.value;
})
.catch((err) => {
messageError($q, err);
});
}
/** function เรียกรายการตำแหน่งทางการบริหาร */
function fetchExecutive() {
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);
});
}
watch( watch(
() => modal.value, () => modal.value,
async () => { async () => {
@ -303,8 +330,7 @@ watch(
hideLoader(); hideLoader();
if (props.data) { if (props.data) {
const dataList = props.data; const dataList = props.data;
await updateSelectType(dataList.posTypeId);
updateSelectType(dataList.posTypeId);
formPositionSelect.positionId = dataList.id; formPositionSelect.positionId = dataList.id;
formPositionSelect.positionName = dataList.positionName; formPositionSelect.positionName = dataList.positionName;
formPositionSelect.positionField = dataList.positionField; formPositionSelect.positionField = dataList.positionField;

View file

@ -1,20 +1,30 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, watch, computed } from "vue"; import { ref, reactive, watch, computed } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import { useCounterMixin } from "@/stores/mixin";
import type { import type {
FormDataAgency, FormDataAgency,
FormAgencyRef,
DataOption, DataOption,
} from "@/modules/02_organization/interface/index/Main"; } from "@/modules/02_organization/interface/index/Main";
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
import { useOrganizational } from "@/modules/02_organization/store/organizational"; /**
import { useCounterMixin } from "@/stores/mixin"; * use
*/
const $q = useQuasar();
const store = useOrganizational();
const mixin = useCounterMixin();
const { dialogConfirm, showLoader, hideLoader, messageError, success } = mixin;
/**
* props
*/
const level = defineModel<number>("orgLevel", { required: true }); const level = defineModel<number>("orgLevel", { required: true });
const actionType = defineModel<string>("actionType", { required: true }); const actionType = defineModel<string>("actionType", { required: true });
const props = defineProps({ const props = defineProps({
@ -46,11 +56,7 @@ const props = defineProps({
}, },
}); });
const $q = useQuasar(); //
const store = useOrganizational();
const mixin = useCounterMixin();
const { dialogConfirm, showLoader, hideLoader, messageError, success } = mixin;
const orgLevelOptionMain = ref<DataOption[]>([ const orgLevelOptionMain = ref<DataOption[]>([
{ name: "ระดับสำนัก", id: "DEPARTMENT" }, { name: "ระดับสำนัก", id: "DEPARTMENT" },
{ {
@ -60,18 +66,10 @@ const orgLevelOptionMain = ref<DataOption[]>([
{ name: "ระดับส่วน/กลุ่มภารกิจ", id: "DIVISION" }, { name: "ระดับส่วน/กลุ่มภารกิจ", id: "DIVISION" },
{ name: "ระดับฝ่าย/กลุ่มงาน", id: "SECTION" }, { name: "ระดับฝ่าย/กลุ่มงาน", id: "SECTION" },
]); ]);
const orgLevelOption = ref<DataOption[]>([]); //
const orgLevelSubOptionMain = ref<DataOption[]>([]); //
const orgLevelSubOptionMain = ref<DataOption[]>([]); //
const orgLevelOption = ref<DataOption[]>([]);
const orgNameRef = ref<Object | null>(null);
const orgShortNameRef = ref<Object | null>(null);
const orgCodeRef = ref<Object | null>(null);
const orgLevelRef = ref<Object | null>(null);
const orgLevelSubRef = ref<Object | null>(null);
const formData = reactive<FormDataAgency>({ const formData = reactive<FormDataAgency>({
orgName: "", orgName: "",
orgShortName: "", orgShortName: "",
@ -84,35 +82,11 @@ const formData = reactive<FormDataAgency>({
responsibility: "", responsibility: "",
}); });
/** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */ /**
const objectComplaintsRef: FormAgencyRef = { * งกนบนทกขอมลสวนราชการ
orgName: orgNameRef, *
orgShortName: orgShortNameRef, * actionType.value === "ADD" จะบนทกการเพมขอมลสวนราชการ ไม จะบนทกการแกไขขอมลสวนราชการ
orgCode: orgCodeRef, **/
orgLevel: orgLevelRef,
orgLevelSub: orgLevelSubRef,
};
/** ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม */
function validateForm() {
const hasError = [];
for (const key in objectComplaintsRef) {
if (Object.prototype.hasOwnProperty.call(objectComplaintsRef, key)) {
const property = objectComplaintsRef[key];
if (property.value && typeof property.value.validate === "function") {
const isValid = property.value.validate();
hasError.push(isValid);
}
}
}
if (hasError.every((result) => result === true)) {
onSubmit();
} else {
}
}
/** ฟังชั่น บันทึก */
function onSubmit() { function onSubmit() {
dialogConfirm($q, async () => { dialogConfirm($q, async () => {
showLoader(); showLoader();
@ -156,7 +130,7 @@ function onSubmit() {
.then(async () => { .then(async () => {
await props.fetchDataTree(store.draftId); await props.fetchDataTree(store.draftId);
await success($q, "บันทึกข้อมูลสำเร็จ"); await success($q, "บันทึกข้อมูลสำเร็จ");
await closeClear(); closeClear();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -189,7 +163,7 @@ function onSubmit() {
false false
); );
await success($q, "บันทึกข้อมูลสำเร็จ"); await success($q, "บันทึกข้อมูลสำเร็จ");
await closeClear(); closeClear();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -202,7 +176,7 @@ function onSubmit() {
} }
/** /**
* function เช formdata กลบไปคาวาง และป popup * งกนเช formdata กลบไปคาวาง และป popup
*/ */
function closeClear() { function closeClear() {
formData.orgName = ""; formData.orgName = "";
@ -217,73 +191,11 @@ function closeClear() {
} }
/** /**
* callback function ทำงานเมอมการเป popup * งกนเลอกระดบของสวนราชการ
*/ * @param val ระดบของสวนราชการ
watch(
() => props.modal,
() => {
if (props.modal === true) {
if (actionType.value === "ADD") {
if (props.dataNode) {
formData.orgCode =
props?.dataNode?.orgLevel !== 0
? props?.dataNode.orgTreeCode
: undefined;
formData.orgShortName =
props?.dataNode?.orgLevel !== 0
? props?.dataNode.orgTreeShortName
: undefined;
}
if (level.value === 0) {
formData.orgLevel = "DEPARTMENT";
orgLevelOption.value = orgLevelOptionMain.value;
} else {
orgLevelOption.value = orgLevelOptionMain.value.slice(1, 4);
formData.orgLevel = "";
}
formData.orgLevel == "DEPARTMENT" ? selectOrgLevele("DEPARTMENT") : "";
} else {
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;
formData.orgLevelSub = props.dataNode.orgTreeRankSub;
formData.responsibility = props.dataNode.responsibility;
orgLevelOption.value =
props.dataNode.orgTreeRank === "DEPARTMENT"
? orgLevelOptionMain.value
: orgLevelOptionMain.value.slice(1, 4);
selectOrgLevele(formData.orgLevel, false);
}
}
}
}
);
/**
* title ของ popup
*/
const tittleName = computed(() => {
let name = "";
if (actionType.value === "ADD") {
name = level.value === 0 ? "เพิ่มหน่วยงาน" : "เพิ่มส่วนราชการ";
} else {
name = level.value === 0 ? "แก้ไขหน่วยงาน" : "แก้ไขส่วนราชการ";
}
return name;
});
/**
* function เลอกระดบของสวนราชการ
* @param val
* @param status * @param status
*
* กำหนดตวเลอกของระดบของสวนราชการ( )ตามประเภทระดบของสวนราชการ
*/ */
function selectOrgLevele(val: string, status: boolean = true) { function selectOrgLevele(val: string, status: boolean = true) {
formData.orgLevelSub = status ? "" : formData.orgLevelSub; formData.orgLevelSub = status ? "" : formData.orgLevelSub;
@ -338,13 +250,77 @@ function selectOrgLevele(val: string, status: boolean = true) {
break; break;
} }
} }
/**
* กำหนด Title ของ popup จะถกตงตามประเภทการดำเนนการและระดบทกำหนด
*/
const tittleName = computed(() => {
let name = "";
if (actionType.value === "ADD") {
name = level.value === 0 ? "เพิ่มหน่วยงาน" : "เพิ่มส่วนราชการ";
} else {
name = level.value === 0 ? "แก้ไขหน่วยงาน" : "แก้ไขส่วนราชการ";
}
return name;
});
/**
* callback function ทำงานเม props.modal เป true
*/
watch(
() => props.modal,
() => {
if (props.modal === true) {
if (actionType.value === "ADD") {
if (props.dataNode) {
formData.orgCode =
props?.dataNode?.orgLevel !== 0
? props?.dataNode.orgTreeCode
: undefined;
formData.orgShortName =
props?.dataNode?.orgLevel !== 0
? props?.dataNode.orgTreeShortName
: undefined;
}
if (level.value === 0) {
formData.orgLevel = "DEPARTMENT";
orgLevelOption.value = orgLevelOptionMain.value;
} else {
orgLevelOption.value = orgLevelOptionMain.value.slice(1, 4);
formData.orgLevel = "";
}
formData.orgLevel == "DEPARTMENT" ? selectOrgLevele("DEPARTMENT") : "";
} else {
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;
formData.orgLevelSub = props.dataNode.orgTreeRankSub;
formData.responsibility = props.dataNode.responsibility;
orgLevelOption.value =
props.dataNode.orgTreeRank === "DEPARTMENT"
? orgLevelOptionMain.value
: orgLevelOptionMain.value.slice(1, 4);
selectOrgLevele(formData.orgLevel, false);
}
}
}
}
);
</script> </script>
<template> <template>
<template> <template>
<q-dialog v-model="props.modal" persistent> <q-dialog v-model="props.modal" persistent>
<q-card style="min-width: 60vw"> <q-card style="min-width: 60vw">
<form @submit.prevent="validateForm"> <q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader :tittle="tittleName" :close="closeClear" /> <DialogHeader :tittle="tittleName" :close="closeClear" />
<q-separator /> <q-separator />
<q-card-section> <q-card-section>
@ -517,7 +493,7 @@ function selectOrgLevele(val: string, status: boolean = true) {
<q-tooltip>นทกขอม</q-tooltip></q-btn <q-tooltip>นทกขอม</q-tooltip></q-btn
> >
</q-card-actions> </q-card-actions>
</form> </q-form>
</q-card> </q-card>
</q-dialog> </q-dialog>
</template> </template>

View file

@ -1,13 +1,28 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch, computed } from "vue"; import { ref, watch, computed } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
import DialogHeader from "@/components/DialogHeader.vue";
import type { FormDateTimeRef } from "@/modules/02_organization/interface/index/Main";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import DialogHeader from "@/components/DialogHeader.vue";
const $q = useQuasar();
const store = useOrganizational();
const {
dialogConfirm,
date2Thai,
showLoader,
hideLoader,
messageError,
success,
} = useCounterMixin();
/**
* porps
*/
const props = defineProps({ const props = defineProps({
modal: Boolean, modal: Boolean,
close: Function, close: Function,
@ -18,51 +33,20 @@ const props = defineProps({
}, },
}); });
const store = useOrganizational(); const dateTime = ref<Date | null>(null); //
const $q = useQuasar();
const mixin = useCounterMixin();
const {
dialogConfirm,
date2Thai,
showLoader,
hideLoader,
messageError,
success,
} = mixin;
/**
* กำหนดวนทเผยแพรไมใหอยกวาวนปจจ
*/
const minDate = computed(() => { const minDate = computed(() => {
const date = new Date(); const date = new Date();
date.setDate(date.getDate() + 1); date.setDate(date.getDate() + 1);
return date; return date;
}); });
const dateTimeRef = ref<Object | null>(null);
const dateTime = ref<Date | null>(); /**
* งกนบนทกการตงเวลาเผยแพร
/** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */ */
const objectRef: FormDateTimeRef = {
dateTime: dateTimeRef,
};
/** ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม */
function validateForm() {
const hasError = [];
for (const key in objectRef) {
if (Object.prototype.hasOwnProperty.call(objectRef, key)) {
const property = objectRef[key];
if (property.value && typeof property.value.validate === "function") {
const isValid = property.value.validate();
hasError.push(isValid);
}
}
}
if (hasError.every((result) => result === true)) {
onSubmit();
} else {
}
}
/** ฟังชั่น บันทึก */
function onSubmit() { function onSubmit() {
dialogConfirm($q, () => { dialogConfirm($q, () => {
showLoader(); showLoader();
@ -72,8 +56,8 @@ function onSubmit() {
}) })
.then(async () => { .then(async () => {
await props.fetchActive(); await props.fetchActive();
await props.close?.();
await success($q, "บันทึกข้อมูลสำเร็จ"); await success($q, "บันทึกข้อมูลสำเร็จ");
props.close?.();
}) })
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);
@ -84,6 +68,9 @@ function onSubmit() {
}); });
} }
/**
* งกนยนยนการเผยแพรโครงาสราง
*/
function onClickPublish() { function onClickPublish() {
dialogConfirm( dialogConfirm(
$q, $q,
@ -106,20 +93,25 @@ function onClickPublish() {
"ต้องการยืนยันการเผยเเพร่ข้อมูลนี้ใช่หรือไม่?" "ต้องการยืนยันการเผยเเพร่ข้อมูลนี้ใช่หรือไม่?"
); );
} }
/**
* การเปลยนแปลงของ props.modal
*/
watch( watch(
() => props.modal, () => props.modal,
() => { () => {
if (props.modal === true) { if (props.modal) {
dateTime.value = store.orgPublishDate ? store.orgPublishDate : null; dateTime.value = store.orgPublishDate ? store.orgPublishDate : null;
} }
} }
); );
</script> </script>
<template> <template>
<template> <template>
<q-dialog v-model="props.modal" persistent> <q-dialog v-model="props.modal" persistent>
<q-card style="min-width: 18vw"> <q-card style="min-width: 18vw">
<form @submit.prevent="validateForm"> <q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader :tittle="`ตั้งเวลาเผยแพร่`" :close="props.close" /> <DialogHeader :tittle="`ตั้งเวลาเผยแพร่`" :close="props.close" />
<q-separator /> <q-separator />
@ -179,7 +171,7 @@ watch(
<q-space /> <q-space />
<q-btn type="submit" :label="`บันทึก`" color="public" /> <q-btn type="submit" :label="`บันทึก`" color="public" />
</q-card-actions> </q-card-actions>
</form> </q-form>
</q-card> </q-card>
</q-dialog> </q-dialog>
</template> </template>

View file

@ -1,8 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, watch } from "vue"; import { ref, reactive, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
/** /**
* importType * importType
@ -10,16 +12,11 @@ import config from "@/app.config";
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
import type { import type {
FormDataPosition, FormDataPosition,
FormPositionRef,
DataOption, DataOption,
FormPositionSelect, FormPositionSelect,
RowDetailPositions, RowDetailPositions,
ListMenu, ListMenu,
} from "@/modules/02_organization/interface/index/Main"; } from "@/modules/02_organization/interface/index/Main";
import type {
OptionType,
OptionExecutive,
} from "@/modules/02_organization/interface/response/organizational";
import type { FilterMaster } from "@/modules/02_organization/interface/request/organizational"; import type { FilterMaster } from "@/modules/02_organization/interface/request/organizational";
/** /**
@ -28,11 +25,6 @@ import type { FilterMaster } from "@/modules/02_organization/interface/request/o
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
import DialogAddPosition from "@/modules/02_organization/components/DialogAddPosition.vue"; // import DialogAddPosition from "@/modules/02_organization/components/DialogAddPosition.vue"; //
/**
* importStore
*/
import { useCounterMixin } from "@/stores/mixin";
/** /**
* use * use
*/ */
@ -51,7 +43,7 @@ const {
/** /**
* props * props
*/ */
const reqMaster = defineModel<FilterMaster>("reqMaster", { required: true }); const reqMaster = defineModel<FilterMaster>("reqMaster", { required: true }); // qurey
const props = defineProps({ const props = defineProps({
modal: Boolean, modal: Boolean,
close: Function, close: Function,
@ -64,14 +56,15 @@ const props = defineProps({
shortName: { type: String, required: true }, shortName: { type: String, required: true },
}); });
const isEdit = ref<boolean>(false);
const modalAdd = ref<boolean>(false);
const isReadonly = ref<boolean>(false); // const isReadonly = ref<boolean>(false); //
const isDisValidate = ref<boolean>(false); const isEdit = ref<boolean>(false); //
const isPosition = ref<boolean>(false); const modalAdd = ref<boolean>(false); //
const dataCopy = ref<any>(); const isPosition = ref<boolean>(false); //
const search = ref<string>("");
const type = ref<string>("positionName"); const dataCopy = ref<RowDetailPositions>(); //
const search = ref<string>(""); //
const type = ref<string>("positionName"); //
//
const optionFilter = ref<DataOption[]>([ const optionFilter = ref<DataOption[]>([
{ id: "positionName", name: "ตำแหน่งในสายงาน" }, { id: "positionName", name: "ตำแหน่งในสายงาน" },
{ id: "positionField", name: "สายงาน" }, { id: "positionField", name: "สายงาน" },
@ -81,37 +74,8 @@ const optionFilter = ref<DataOption[]>([
{ id: "positionExecutiveField", name: "ด้านทางการบริหาร" }, { id: "positionExecutiveField", name: "ด้านทางการบริหาร" },
{ id: "positionArea", name: "ด้าน/สาขา" }, { id: "positionArea", name: "ด้าน/สาขา" },
]); ]);
const typeOpsMain = ref<DataOption[]>([]);
const executiveOpsMain = ref<DataOption[]>([]);
const executiveOps = ref<DataOption[]>([]);
const typeOps = ref<DataOption[]>([]);
const listMenu = ref<ListMenu[]>([
{
label: "คัดลอก",
icon: "mdi-content-copy",
type: "copy",
color: "blue-6",
},
{
label: "แก้ไข",
icon: "mdi-pencil",
type: "edit",
color: "edit",
},
{
label: "ลบ",
icon: "delete",
type: "remove",
color: "red",
},
]);
const rows = ref<RowDetailPositions[]>([]);
const rowsPositionSelect = ref<RowDetailPositions[]>([]);
const prefixNoRef = ref<Object | null>(null);
const positionNoRef = ref<Object | null>(null);
//
const formData = reactive<FormDataPosition>({ const formData = reactive<FormDataPosition>({
shortName: props.shortName, shortName: props.shortName,
prefixNo: "", prefixNo: "",
@ -122,6 +86,7 @@ const formData = reactive<FormDataPosition>({
isOfficer: false, isOfficer: false,
}); });
//
const formPositionSelect = reactive<FormPositionSelect>({ const formPositionSelect = reactive<FormPositionSelect>({
positionId: "", positionId: "",
positionName: "", positionName: "",
@ -132,12 +97,10 @@ const formPositionSelect = reactive<FormPositionSelect>({
positionExecutiveField: "", positionExecutiveField: "",
positionArea: "", positionArea: "",
}); });
/** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */
const objectPositionRef: FormPositionRef = {
prefixNo: prefixNoRef,
positionNo: positionNoRef,
};
//Table
const rows = ref<RowDetailPositions[]>([]); //
const rowsPositionSelect = ref<RowDetailPositions[]>([]); //
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "no", name: "no",
@ -222,6 +185,27 @@ const visibleColumns = ref<string[]>([
"positionExecutiveField", "positionExecutiveField",
"positionArea", "positionArea",
]); ]);
//
const listMenu = ref<ListMenu[]>([
{
label: "คัดลอก",
icon: "mdi-content-copy",
type: "copy",
color: "blue-6",
},
{
label: "แก้ไข",
icon: "mdi-pencil",
type: "edit",
color: "edit",
},
{
label: "ลบ",
icon: "delete",
type: "remove",
color: "red",
},
]);
/** /**
* function fetch อมลอตรากำล * function fetch อมลอตรากำล
@ -249,219 +233,132 @@ async function fetchPosition(id: string) {
}); });
} }
const dataLevel = ref<any>(); /**
/** function เรียกรายการประเภทตำแหน่ง */ * งกนยนยนการบนทกขอมลอตรากำล
async function fetchType() { *
// showLoader(); * props.actionType เป "ADD" หร "COPY" จะเพมรายการตำแหน ไมจะเปนการแกไขขอม
await http *
.get(config.API.orgPosType) */
.then((res) => {
dataLevel.value = res.data.result;
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 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 = [];
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)) {
if (rows.value.length == 0) {
dialogMessageNotify($q, "กรุณาเลือกตำแหน่งอย่างน้อย 1 ตำแหน่ง");
} else {
onSubmit();
}
}
}
/** ฟังชั่น บันทึก */
function onSubmit() { function onSubmit() {
dialogConfirm($q, async () => { //
const positionsData = rows.value.map((e: any) => ({ if (rows.value.length == 0) {
posDictName: e.positionName, // () dialogMessageNotify($q, "กรุณาเลือกตำแหน่งอย่างน้อย 1 ตำแหน่ง");
posDictField: e.positionField, // } else {
posTypeId: e.posTypeId, //* // dialog
posLevelId: e.posLevelId, //* dialogConfirm($q, async () => {
posExecutiveId: e.posExecutiveId ? e.posExecutiveId : "", // const positionsData = rows.value.map((e: RowDetailPositions) => ({
posDictExecutiveField: e.positionExecutiveField, // posDictName: e.positionName, // ()
posDictArea: e.positionArea, /// posDictField: e.positionField, //
isSpecial: e.isSpecial, posTypeId: e.posTypeId, //*
positionIsSelected: e.positionIsSelected, posLevelId: e.posLevelId, //*
})); posExecutiveId: e.posExecutiveId ? e.posExecutiveId : "", //
const body = { posDictExecutiveField: e.positionExecutiveField, //
posMasterNoPrefix: formData.prefixNo, //*Prefix Optional (/) posDictArea: e.positionArea, ///
posMasterNo: Number(formData.positionNo), //* isSpecial: e.isSpecial,
posMasterNoSuffix: formData.suffixNo, //Suffix . positionIsSelected: e.positionIsSelected,
reason: formData.reason, //Suffix . }));
isDirector: formData.isDirector, const body = {
isOfficer: formData.isOfficer ? formData.isOfficer : false, posMasterNoPrefix: formData.prefixNo, //*Prefix Optional (/)
orgRootId: props.orgLevel === 0 ? props.treeId : null, //Id posMasterNo: Number(formData.positionNo), //*
orgChild1Id: props.orgLevel === 1 ? props.treeId : null, posMasterNoSuffix: formData.suffixNo, //Suffix .
orgChild2Id: props.orgLevel === 2 ? props.treeId : null, reason: formData.reason, //Suffix .
orgChild3Id: props.orgLevel === 3 ? props.treeId : null, isDirector: formData.isDirector,
orgChild4Id: props.orgLevel === 4 ? props.treeId : null, isOfficer: formData.isOfficer ? formData.isOfficer : false,
positions: positionsData, 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,
};
showLoader(); showLoader();
props.actionType === "ADD" || props.actionType === "COPY" props.actionType === "ADD" || props.actionType === "COPY"
? await http ? await http
.post(config.API.orgPosMaster, body) .post(config.API.orgPosMaster, body)
.then(async () => { .then(async () => {
await props.fetchDataTable?.( await props.fetchDataTable?.(
reqMaster.value.id, reqMaster.value.id,
reqMaster.value.type, reqMaster.value.type,
false false
); );
await props.getSummary?.(); await props.getSummary?.();
await close(); await success($q, "เพิ่มข้อมูลสำเร็จ");
await success($q, "เพิ่มข้อมูลสำเร็จ"); close();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
}) })
.finally(() => { .finally(() => {
hideLoader(); hideLoader();
}) })
: props.rowId && : props.rowId &&
(await http (await http
.put(config.API.orgPosMasterById(props.rowId), body) .put(config.API.orgPosMasterById(props.rowId), body)
.then(async () => { .then(async () => {
await props.fetchDataTable?.( await props.fetchDataTable?.(
reqMaster.value.id, reqMaster.value.id,
reqMaster.value.type, reqMaster.value.type,
false false
); );
await close(); await success($q, "แก้ไขข้อมูลสำเร็จ");
await success($q, "แก้ไขข้อมูลสำเร็จ"); close();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
}) })
.finally(() => { .finally(() => {
hideLoader(); hideLoader();
})); }));
}); });
}
/** input ค้นหา */
const searchRef = ref<any>(null);
async function searchInput() {
searchRef.value.validate();
if (!searchRef.value.hasError) {
showLoader();
await http
.get(
config.API.orgPosPosition +
`?keyword=${search.value}&type=${type.value}`
)
.then((res) => {
rowsPositionSelect.value = res.data.result;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
} }
} }
/** /**
* ดลอกขอม * งกนตนหาตำแหนงทองการเพ
* @param data อมลตำแหน */
async function searchInput() {
showLoader();
await http
.get(
config.API.orgPosPosition + `?keyword=${search.value}&type=${type.value}`
)
.then((res) => {
rowsPositionSelect.value = res.data.result;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* งกนคดลอกขอมลตำแหน
* @param data อมลตำแหนงทองการคดลอก
*/ */
function copyDetiail(data: RowDetailPositions) { function copyDetiail(data: RowDetailPositions) {
modalAdd.value = true; modalAdd.value = true;
dataCopy.value = data; dataCopy.value = data;
} }
/** /**
* แกไขขอม * งกแกไขขอมตำแหน
* @param data อมลตำแหน * @param data อมลตำแหนองการแกไข
*/ */
function editDetiail(data: RowDetailPositions) { function editDetiail(data: RowDetailPositions) {
isEdit.value = true; isEdit.value = true;
modalAdd.value = true; modalAdd.value = true;
dataCopy.value = data; dataCopy.value = data;
console.log(isEdit.value);
} }
/** /**
* งค css ออกไปตามเงอนไข * งกนเพมขอมลรายการอตรากำล
* @param val true/false * @param data อมลตำแหนงทองการเพ
*/ */
function inputEdit(val: boolean) {
return {
"full-width cursor-pointer inputgreen ": val,
"full-width cursor-pointer inputgreen": !val,
};
}
watch(
() => props.modal,
async () => {
if (props.modal === true) {
props.actionType === "ADD" && showLoader();
await Promise.all([fetchType(), fetchExecutive()]);
props.actionType === "ADD" && hideLoader();
if (props.actionType === "ADD") {
rowsPositionSelect.value = [];
search.value = "";
rows.value = [];
clearFormPositionSelect();
formData.prefixNo = "";
formData.positionNo = "";
formData.suffixNo = "";
formData.reason = "";
} else {
props.rowId && fetchPosition(props.rowId);
}
}
}
);
async function addPosition(data: RowDetailPositions) { async function addPosition(data: RowDetailPositions) {
const isIdExist = await rows.value.some( const isIdExist = rows.value.some(
(item: any) => (item: RowDetailPositions) =>
item.posExecutiveId == data.posExecutiveId && item.posExecutiveId == data.posExecutiveId &&
item.positionField == data.positionField && item.positionField == data.positionField &&
item.posLevelId == data.posLevelId && item.posLevelId == data.posLevelId &&
@ -478,18 +375,20 @@ async function addPosition(data: RowDetailPositions) {
} }
/** /**
* function ลบอมลอตรากำล * งกนลบรายการอมลอตรากำล
* @param id อมลอตรากำล * @param id รายการอมลอตรากำลองการลบ
*/ */
function deleteData(id: string) { function deleteData(id: string) {
const dataRow = rows.value; const dataRow = rows.value;
const updatedRows = dataRow.filter((item: any) => item.id !== id); const updatedRows = dataRow.filter(
(item: RowDetailPositions) => item.id !== id
);
rows.value = updatedRows; rows.value = updatedRows;
} }
/** /**
* function ลบตำแหน * งกนลบขอมลรายการตำแหน
* @param id ตำแหน * @param id อมลรายการตำแหนงทองการลบ
*/ */
function deletePos(id: string) { function deletePos(id: string) {
dialogRemove($q, () => { dialogRemove($q, () => {
@ -510,10 +409,9 @@ function deletePos(id: string) {
} }
/** /**
* function เคลยร formData * งกนกำหนดตวแปรทงหมดใหเปนค Default
*/ */
async function clearFormPositionSelect() { async function clearFormPositionSelect() {
isDisValidate.value = await true;
formPositionSelect.positionId = ""; formPositionSelect.positionId = "";
formPositionSelect.positionName = ""; formPositionSelect.positionName = "";
formPositionSelect.positionField = ""; formPositionSelect.positionField = "";
@ -522,27 +420,64 @@ async function clearFormPositionSelect() {
formPositionSelect.positionExecutive = ""; formPositionSelect.positionExecutive = "";
formPositionSelect.positionExecutiveField = ""; formPositionSelect.positionExecutiveField = "";
formPositionSelect.positionArea = ""; formPositionSelect.positionArea = "";
search.value = "";
setTimeout(async () => { rows.value = [];
isDisValidate.value = await false; formData.prefixNo = "";
}, 1000); formData.positionNo = "";
} formData.suffixNo = "";
formData.reason = "";
/** formData.isDirector = false;
* function popup rowsPositionSelect.value = [];
*/
function close() {
clearFormPositionSelect();
props.close?.();
isPosition.value = false; isPosition.value = false;
} }
async function emitSearch(keyword: string, typeSelect: string) { /**
search.value = await keyword; * งก popup
type.value = await typeSelect; *
* และกำหนดตวแปรทงหมดใหเปนค Default
*/
function close() {
props.close?.();
clearFormPositionSelect();
}
/**
* งกนคนหาขอมลตำแหน
* @param keyword คำคนหา
* @param typeSelect ปรเภทการคนหา
*/
async function emitSearch(keyword: string, typeSelect: string) {
search.value = keyword;
type.value = typeSelect;
await searchInput(); await searchInput();
} }
/**
* งค css ออกไปตามเงอนไข
* @param val true/false
*/
function inputEdit(val: boolean) {
return {
"full-width cursor-pointer inputgreen ": val,
"full-width cursor-pointer inputgreen": !val,
};
}
/**
* การเปลยยนแปลง props.modal
*
* เม props.modal เป true
*/
watch(
() => props.modal,
async () => {
if (props.modal === true) {
if (props.actionType !== "ADD" && props.rowId) {
fetchPosition(props.rowId);
}
}
}
);
</script> </script>
<template> <template>
@ -555,7 +490,7 @@ async function emitSearch(keyword: string, typeSelect: string) {
:close="close" :close="close"
/> />
<q-separator /> <q-separator />
<form @submit.prevent="validateForm"> <q-form greedy @submit.prevent @validation-success="onSubmit">
<q-card-section class="q-pa-sm fixed-height"> <q-card-section class="q-pa-sm fixed-height">
<div class="row q-col-gutter-sm"> <div class="row q-col-gutter-sm">
<div class="col-12"> <div class="col-12">
@ -754,7 +689,7 @@ async function emitSearch(keyword: string, typeSelect: string) {
flat flat
round round
color="teal" color="teal"
@click="() => ((modalAdd = true), (dataCopy = null))" @click="() => ((modalAdd = true), (dataCopy = undefined))"
><q-tooltip>สรางตำแหน</q-tooltip></q-btn ><q-tooltip>สรางตำแหน</q-tooltip></q-btn
> >
</div> </div>
@ -777,16 +712,15 @@ async function emitSearch(keyword: string, typeSelect: string) {
<div class="col-12 col-sm-6 col-md-6"> <div class="col-12 col-sm-6 col-md-6">
<q-input <q-input
ref="searchRef"
:class="inputEdit(isReadonly)" :class="inputEdit(isReadonly)"
v-model="search" v-model="search"
outlined outlined
clearable clearable
@clear="search = ''"
dense dense
lazy-rules lazy-rules
label="คำค้น" label="คำค้น"
hide-bottom-space hide-bottom-space
:rules="[(val) => !!val || `กรุณากรอกคำค้น`]"
@keydown.enter.prevent="searchInput()" @keydown.enter.prevent="searchInput()"
/> />
</div> </div>
@ -929,7 +863,7 @@ async function emitSearch(keyword: string, typeSelect: string) {
><q-tooltip>นท</q-tooltip></q-btn ><q-tooltip>นท</q-tooltip></q-btn
> >
</q-card-actions> </q-card-actions>
</form> </q-form>
</q-card> </q-card>
</q-dialog> </q-dialog>

View file

@ -1,8 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from "vue"; import { ref, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
/** /**
* importType * importType
@ -15,11 +17,6 @@ import type { HistoryPostType } from "@/modules/02_organization/interface/index/
*/ */
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
/**
* importStore
*/
import { useCounterMixin } from "@/stores/mixin";
/** /**
* use * use
*/ */
@ -37,14 +34,14 @@ const orgId = defineModel<string>("orgId", { required: true });
/** /**
* อม Table * อม Table
*/ */
const rows = ref<HistoryPostType[]>([]); const rows = ref<HistoryPostType[]>([]); //
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "no", name: "no",
align: "left", align: "left",
label: "ลำดับ", label: "ลำดับ",
sortable: false, sortable: false,
field: "no", field: (row) => rows.value.indexOf(row) + 1,
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
}, },
@ -72,7 +69,7 @@ const columns = ref<QTableProps["columns"]>([
align: "left", align: "left",
label: "วันที่แก้ไข", label: "วันที่แก้ไข",
sortable: true, sortable: true,
field: "lastUpdatedAt", field: (v) => date2Thai(v),
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
}, },
@ -85,26 +82,18 @@ const visibleColumns = ref<string[]>([
]); ]);
/** /**
* function เรยกขอม ประวหนวยงาน,ประววนราชการ * function เรยกขอมประวหนวยงาน,ประววนราชการ
*/ */
function postData() { async function fetchHistory() {
showLoader(); showLoader();
http await http
.post(config.API.organizationHistoryPostNew, { .post(config.API.organizationHistoryPostNew, {
id: orgId.value, id: orgId.value,
type: type.value, type: type.value,
}) })
.then((res) => { .then(async (res) => {
const dataList = res.data.result; const data = await res.data.result;
const dataMap = dataList.map((item: HistoryPostType) => ({ rows.value = data;
id: item.id ? item.id : "-",
name: item.name ? item.name : "-",
lastUpdatedAt: item.lastUpdatedAt
? date2Thai(item.lastUpdatedAt as Date, false, true)
: "-",
orgRevisionName: item.orgRevisionName ? item.orgRevisionName : "-",
}));
rows.value = dataMap;
}) })
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);
@ -115,13 +104,13 @@ function postData() {
} }
/** /**
* callback function เม modal = true เรยกขอม ประวหนวยงาน,ประววนราชการ * การเปลยนแปลง modal เมอเป true จะเรยกขอมประวหนวยงาน,ประววนราชการ
*/ */
watch( watch(
() => modal.value, () => modal.value,
() => { () => {
if (modal.value == true) { if (modal.value == true) {
postData(); fetchHistory();
} }
} }
); );
@ -177,43 +166,8 @@ watch(
:key="col.name" :key="col.name"
:props="props" :props="props"
> >
<div v-if="col.name == 'no'"> <div>
{{ props.rowIndex + 1 }} {{ col.value ?? "-" }}
</div>
<div v-else-if="col.name == 'orgRevisionIsCurrent'">
<q-icon
:name="
props.row.orgRevisionIsCurrent == true
? 'mdi-check'
: ''
"
:color="
props.row.orgRevisionIsCurrent == true
? 'positive'
: ''
"
class="text-h5"
/>
</div>
<div v-else-if="col.name == 'orgRevisionIsDraft'">
<q-icon
:name="
props.row.orgRevisionIsDraft == true
? 'mdi-check'
: ''
"
:color="
props.row.orgRevisionIsDraft == true
? 'positive'
: ''
"
class="text-h5"
/>
</div>
<div v-else>
{{ col.value }}
</div> </div>
</q-td> </q-td>
</q-tr> </q-tr>

View file

@ -1,8 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from "vue"; import { ref, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* import Type * import Type
@ -15,16 +18,10 @@ import type { HistoryPos } from "@/modules/02_organization/interface/response/or
*/ */
import Header from "@/components/DialogHeader.vue"; import Header from "@/components/DialogHeader.vue";
/**
* import Store
*/
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** Use*/ /** Use*/
const $q = useQuasar();
const store = useOrganizational(); const store = useOrganizational();
const { showLoader, hideLoader, messageError, date2Thai } = useCounterMixin(); const { showLoader, hideLoader, messageError, date2Thai } = useCounterMixin();
const $q = useQuasar();
/** /**
* props * props
@ -39,7 +36,7 @@ const props = defineProps({
/** /**
* อม Table * อม Table
*/ */
const rows = ref<HistoryPos[]>([]); const rows = ref<HistoryPos[]>([]); //
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "no", name: "no",
@ -156,7 +153,7 @@ function fetchHistoryPos(id: string) {
http http
.get(config.API.orgPosHistory(id)) .get(config.API.orgPosHistory(id))
.then((res) => { .then((res) => {
const data: HistoryPos[] = res.data.result; const data = res.data.result;
rows.value = data; rows.value = data;
}) })
.catch((err) => { .catch((err) => {
@ -168,7 +165,7 @@ function fetchHistoryPos(id: string) {
} }
/** /**
* callback function ทำงานเม modal === true * การเปลยนแปลง modal เมอเป true จะเรยกเรยกขอมลประวตำแหน
*/ */
watch( watch(
() => modal.value, () => modal.value,

View file

@ -1,8 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, watch } from "vue"; import { ref, computed, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* importType * importType
@ -24,12 +27,6 @@ import type { DataTree } from "@/modules/02_organization/interface/index/organiz
*/ */
import HeaderDialog from "@/components/DialogHeader.vue"; import HeaderDialog from "@/components/DialogHeader.vue";
/**
* importStore
*/
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* use * use
*/ */
@ -72,19 +69,24 @@ const props = defineProps({
}, },
}); });
const title = ref<string>("ย้ายตำแหน่งจากหน่วยงาน/ส่วนราชการปัจจุบัน"); const title = ref<string>("ย้ายตำแหน่งจากหน่วยงาน/ส่วนราชการปัจจุบัน"); //title Dialog
const filterTree = ref<string>(""); const filterTree = ref<string>(""); ///
const filterRef = ref(); const filterRef = ref(); //
const selectedTree = ref<string>(""); const selectedTree = ref<string>(""); //
const levelTree = ref<number>(0); const levelTree = ref<number>(0); //
const filterTable = ref<string>(""); const filterTable = ref<string>(""); //
const selectedFilter = ref<PosMaster2[]>([]); const selectedFilter = ref<PosMaster2[]>([]); //
const pagination = ref({ const pagination = ref({
page: reqMaster.value.page, page: reqMaster.value.page,
rowsPerPage: reqMaster.value.pageSize, rowsPerPage: reqMaster.value.pageSize,
}); });
/**
* ดปมยายตำแหน
*
* เมอไมไดเลอกตำแหนงทองการยายและหนวยงานทองการยายปมยายตำแหนงจะป
*/
const isDisable = computed(() => { const isDisable = computed(() => {
if (selectedTree.value === "" && selectedFilter.value.length === 0) { if (selectedTree.value === "" && selectedFilter.value.length === 0) {
return true; return true;
@ -146,6 +148,18 @@ function onClickMovePos() {
} }
} }
/**
* function updatePagination
* @param newPagination อม Pagination ใหม
*/
function updatePagination(newPagination: NewPagination) {
reqMaster.value.pageSize = newPagination.rowsPerPage;
reqMaster.value.page = 1;
}
/**
* การเปลยนแปลง modal เมอเป true
*/
watch( watch(
() => modal.value, () => modal.value,
() => { () => {
@ -164,15 +178,6 @@ watch(
} }
} }
); );
/**
* function updatePagination
* @param newPagination อม Pagination ใหม
*/
function updatePagination(newPagination: NewPagination) {
reqMaster.value.pageSize = newPagination.rowsPerPage;
reqMaster.value.page = 1;
}
</script> </script>
<template> <template>

View file

@ -1,8 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, watch } from "vue"; import { ref, reactive, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* importType * importType
@ -17,12 +20,6 @@ import type {
/** importComponents*/ /** importComponents*/
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
/**
* importStore
*/
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* use * use
*/ */
@ -45,6 +42,7 @@ const props = defineProps({
}, },
}); });
//
const typeOp = ref<DataOption[]>([ const typeOp = ref<DataOption[]>([
{ {
id: "NEW", id: "NEW",
@ -64,10 +62,7 @@ const typeOp = ref<DataOption[]>([
}, },
]); ]);
const orgRevisionNameRef = ref<Object | null>(null); //
const typeRef = ref<Object | null>(null);
const orgRevisionIdRef = ref<Object | null>(null);
const formData = reactive<FormDataNewStructure>({ const formData = reactive<FormDataNewStructure>({
orgRevisionId: "", orgRevisionId: "",
orgRevisionName: "", orgRevisionName: "",
@ -75,42 +70,14 @@ const formData = reactive<FormDataNewStructure>({
}); });
/** /**
* maping ref เขาตวแปรเพอเตรยมตรวจสอบ * งกนยนยนการบนทกการกสรางโครงสราง
*/
const objectRef: FormNewStructureRef = {
orgRevisionName: orgRevisionNameRef,
type: typeRef,
orgRevisionId: orgRevisionIdRef,
};
/**
* งกนตรวจสอบความถกตองของขอมลในฟอร
*/
function validateForm() {
const hasError = [];
for (const key in objectRef) {
if (Object.prototype.hasOwnProperty.call(objectRef, key)) {
const property = objectRef[key];
if (property.value && typeof property.value.validate === "function") {
const isValid = property.value.validate();
hasError.push(isValid);
}
}
}
if (hasError.every((result) => result === true)) {
onSubmit();
}
}
/**
* งช นท
*/ */
function onSubmit() { function onSubmit() {
dialogConfirm( dialogConfirm(
$q, $q,
() => { async () => {
showLoader(); showLoader();
http await http
.post(config.API.createOrganization, formData) .post(config.API.createOrganization, formData)
.then(async (res) => { .then(async (res) => {
await props.fetchActive(); await props.fetchActive();
@ -119,14 +86,13 @@ function onSubmit() {
store.draftId = res.data.result.id; store.draftId = res.data.result.id;
store.statusView = "list"; store.statusView = "list";
success($q, "บันทึกข้อมูลสำเร็จ"); success($q, "บันทึกข้อมูลสำเร็จ");
close();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
}) })
.finally(() => { .finally(() => {
modal.value = false;
hideLoader(); hideLoader();
close();
}); });
}, },
"ยืนยันการเพิ่มโครงสร้าง", "ยืนยันการเพิ่มโครงสร้าง",
@ -137,7 +103,7 @@ function onSubmit() {
} }
/** /**
* popup * popup และกำหนดฟอรมเพมโครงสรางเป Default
*/ */
function close() { function close() {
modal.value = false; modal.value = false;
@ -147,7 +113,7 @@ function close() {
} }
/** /**
* เรยกขอม * งกเรยกขอมประวโครงสราง
*/ */
function fetchOrgRevision() { function fetchOrgRevision() {
showLoader(); showLoader();
@ -159,7 +125,7 @@ function fetchOrgRevision() {
); );
if (data) { if (data) {
const currentStr = await data.find( const currentStr = await data.find(
(x: any) => x.orgRevisionIsCurrent === true (x: HistoryType) => x.orgRevisionIsCurrent === true
); );
formData.orgRevisionId = currentStr ? currentStr.orgRevisionId : null; formData.orgRevisionId = currentStr ? currentStr.orgRevisionId : null;
} }
@ -172,6 +138,11 @@ function fetchOrgRevision() {
}); });
} }
/**
* การเปลยนแปลง modal เมอเป true
*
* type ไมเปนการสรางใหมใหเรยกขอมลประวโครงสราง
*/
watch( watch(
() => modal.value, () => modal.value,
() => { () => {
@ -184,7 +155,7 @@ watch(
<template> <template>
<q-dialog v-model="modal" persistent> <q-dialog v-model="modal" persistent>
<q-card style="min-width: 50vw"> <q-card style="min-width: 50vw">
<form @submit.prevent="validateForm"> <q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader :tittle="`เพิ่มโครงสร้าง`" :close="close" /> <DialogHeader :tittle="`เพิ่มโครงสร้าง`" :close="close" />
<q-separator /> <q-separator />
@ -227,7 +198,7 @@ watch(
<q-card-actions align="right" class="bg-white text-teal"> <q-card-actions align="right" class="bg-white text-teal">
<q-btn type="submit" :label="`บันทึก`" color="public" /> <q-btn type="submit" :label="`บันทึก`" color="public" />
</q-card-actions> </q-card-actions>
</form> </q-form>
</q-card> </q-card>
</q-dialog> </q-dialog>
</template> </template>

View file

@ -2,6 +2,8 @@
import { reactive, watch } from "vue"; import { reactive, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* import type * import type
*/ */
@ -12,11 +14,6 @@ import type { FormDetailPosition } from "@/modules/02_organization/interface/ind
*/ */
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
/**
* importStore
*/
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* use * use
*/ */

View file

@ -1,8 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, watch } from "vue"; import { ref, reactive, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* importType * importType
@ -29,12 +32,6 @@ import type {
*/ */
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
/**
* import*Store
*/
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* use * use
*/ */
@ -70,13 +67,13 @@ const props = defineProps({
}); });
const isReadonly = ref<boolean>(false); // const isReadonly = ref<boolean>(false); //
const typeOpsMain = ref<DataOption[]>([]); const typeOpsMain = ref<DataOption[]>([]); //
const levelOpsMain = ref<DataOption[]>([]); const levelOpsMain = ref<DataOption[]>([]); //
const typeOps = ref<DataOption[]>([]); const typeOps = ref<DataOption[]>([]); //
const levelOps = ref<DataOption[]>([]); const levelOps = ref<DataOption[]>([]); //
const dataLevel = ref<TypePos[]>([]); const dataLevel = ref<TypePos[]>([]); //
const selected = ref<Position[]>([]); const selected = ref<Position[]>([]); //
const isSit = ref<boolean>(false); const isSit = ref<boolean>(false); //
const formData = reactive<FormPositionFilter>({ const formData = reactive<FormPositionFilter>({
positionNo: "", //* positionNo: "", //*
@ -230,13 +227,6 @@ const columnsResult = ref<QTableProps["columns"]>([
}, },
]); ]);
/**
* function closePopup
*/
function close() {
modal.value = false;
}
/** /**
* function เรยกขอมลประเภทตำแหน * function เรยกขอมลประเภทตำแหน
*/ */
@ -260,17 +250,6 @@ function fetchType() {
}); });
} }
/**
* งค css ออกไปตามเงอนไข
* @param val true/false
*/
function inputEdit(val: boolean) {
return {
"full-width cursor-pointer inputgreen ": val,
"full-width cursor-pointer inputgreen": !val,
};
}
/** /**
* function เรยกขแมลระดบตำแหน * function เรยกขแมลระดบตำแหน
*/ */
@ -317,7 +296,7 @@ function onSubmit() {
await props.fetchDataTable?.(store.treeId, store.level, false); await props.fetchDataTable?.(store.treeId, store.level, false);
await props.getSummary(); await props.getSummary();
success($q, "บันทึกข้อมูลสำเร็จ"); success($q, "บันทึกข้อมูลสำเร็จ");
modal.value = false; close();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -381,7 +360,7 @@ function updatePagination(newPagination: NewPagination) {
} }
/** /**
* function เคลยรForm * function เคลยรวแปรเปนค Default
*/ */
function clearForm() { function clearForm() {
formData.positionType = ""; formData.positionType = "";
@ -396,13 +375,39 @@ function clearForm() {
} }
/** /**
* function เคลยรตำแหน * function เคลยรประเภทตำแหนงและระดตำแหน
*/ */
function clearPosition() { function clearPosition() {
formData.positionType = ""; formData.positionType = "";
formData.positionLevel = ""; formData.positionLevel = "";
} }
/**
* function popup
*/
function close() {
modal.value = false;
clearForm();
}
/**
* งค css ออกไปตามเงอนไข
* @param val true/false
*/
function inputEdit(val: boolean) {
return {
"full-width cursor-pointer inputgreen ": val,
"full-width cursor-pointer inputgreen": !val,
};
}
/**
* callback function ทำงานการคนหาขอมลคนครองเมอมการ update Pagination
*/
watch([() => page.value, () => pageSize.value], () => {
searchData();
});
/** /**
* callback function ทำงานเมอเป popup * callback function ทำงานเมอเป popup
*/ */
@ -410,7 +415,6 @@ watch(
() => modal.value, () => modal.value,
async () => { async () => {
if (modal.value == true) { if (modal.value == true) {
await clearForm();
await fetchType(); await fetchType();
if (props.dataDetailPos) { if (props.dataDetailPos) {
@ -440,13 +444,6 @@ watch(
} }
} }
); );
/**
* callback function ทำงานการคนหาขอมลคนครองเมอมการ update Pagination
*/
watch([() => page.value, () => pageSize.value], () => {
searchData();
});
</script> </script>
<template> <template>

View file

@ -1,8 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from "vue"; import { ref, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* importType * importType
@ -15,12 +18,6 @@ import type { DataSortAgency } from "@/modules/02_organization/interface/index/o
*/ */
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
/**
* importStore
*/
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* use * use
*/ */

View file

@ -1,8 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch, defineProps } from "vue"; import { ref, watch, defineProps } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* importType * importType
@ -15,12 +18,6 @@ import type { DataSortPos } from "@/modules/02_organization/interface/index/orga
*/ */
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
/**
* importStore
*/
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** /**
* use * use
*/ */

View file

@ -1,18 +1,18 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, watch } from "vue"; import { reactive, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import DialogHeader from "@/components/DialogHeader.vue";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational"; import { useOrganizational } from "@/modules/02_organization/store/organizational";
import DialogHeader from "@/components/DialogHeader.vue";
const $q = useQuasar(); const $q = useQuasar();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const store = useOrganizational(); const store = useOrganizational();
const { showLoader, hideLoader, messageError, date2Thai } = mixin; const { showLoader, hideLoader, messageError } = mixin;
const modal = defineModel<boolean>("structureDetail", { required: true }); const modal = defineModel<boolean>("structureDetail", { required: true });
const treeId = defineModel<string>("treeId", { required: true }); const treeId = defineModel<string>("treeId", { required: true });
@ -30,12 +30,17 @@ const formData = reactive<any>({
orgShortName: "", orgShortName: "",
}); });
/**
* function งขอมลรายละเอยดโหนดขอโครงสรางตาม ID โหนดโครงสราง
* @param id id โหนดโครงสราง
* @param type ระดบโหนดของโครงอสราง
*/
async function fetchDetailTree(id: string, type: string) { async function fetchDetailTree(id: string, type: string) {
showLoader(); showLoader();
await http await http
.get(config.API.orgLevelByid(type.toLocaleLowerCase(), id)) .get(config.API.orgLevelByid(type.toLocaleLowerCase(), id))
.then((res) => { .then(async (res) => {
const data = res.data.result; const data = await res.data.result;
const range = data[`org${type}Rank`]; const range = data[`org${type}Rank`];
formData.orgName = data.orgRootName ? data.orgRootName : "-"; formData.orgName = data.orgRootName ? data.orgRootName : "-";
formData.agencyName = data.orgName ? data.orgName : "-"; formData.agencyName = data.orgName ? data.orgName : "-";
@ -60,10 +65,19 @@ async function fetchDetailTree(id: string, type: string) {
}); });
} }
/**
* function popup
*/
function close() { function close() {
modal.value = false; modal.value = false;
} }
/**
* การเปลยนแปลงของ modal
*
* เม modal เป true จะสงระดบของโหนดไปเช
* และจะดงขอมลรายละเอยดโหนดขอโครงสรางตาม ID และ ระด โหนดโครงสราง
*/
watch( watch(
() => modal.value, () => modal.value,
async () => { async () => {

View file

@ -3,6 +3,8 @@ import { ref, watch, reactive } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** importType*/ /** importType*/
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
@ -20,10 +22,6 @@ import type {
/** importComponents*/ /** importComponents*/
import Header from "@/components/DialogHeader.vue"; import Header from "@/components/DialogHeader.vue";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/** use*/ /** use*/
const $q = useQuasar(); const $q = useQuasar();
const store = useOrganizational(); const store = useOrganizational();
@ -49,7 +47,9 @@ const selectedTree = ref<string>("");
const filterRef = ref(); const filterRef = ref();
const levelTree = ref<number>(0); const levelTree = ref<number>(0);
/** function เรียกข้อมูล Tree แบบ ปัจจุบัน*/ /**
* function เรยกขอม Tree แบบ จจ
*/
async function fetchTree() { async function fetchTree() {
showLoader(); showLoader();
const id: string = store.activeId ? store.activeId?.toString() : ""; const id: string = store.activeId ? store.activeId?.toString() : "";
@ -66,23 +66,28 @@ async function fetchTree() {
}); });
} }
/** resetFilterTree*/ /**
* resetFilterTree
*/
function resetFilter() { function resetFilter() {
filterTree.value = ""; filterTree.value = "";
filterRef.value.focus(); filterRef.value.focus();
} }
/** function เลือกหน่วยงาน*/ /**
* function เลอกหนวยงาน
*
* และโหลดชอมลตำแหน
*/
async function updateSelected(data: DataTree) { async function updateSelected(data: DataTree) {
levelTree.value = data.orgLevel; levelTree.value = data.orgLevel;
selectedTree.value = data.orgTreeId; selectedTree.value = data.orgTreeId;
reqMaster.id = await data.orgTreeId; reqMaster.id = data.orgTreeId;
reqMaster.type = await data.orgLevel; reqMaster.type = data.orgLevel;
await fetchTable(); await fetchTable();
} }
/*************************** TABLE ***********************************/ /*************************** TABLE ***********************************/
/** columns*/
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "no", name: "no",
@ -103,7 +108,7 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px", style: "font-size: 14px",
}, },
]); ]);
const rows = ref<PosMaster[]>([]); const rows = ref<PosMaster[]>([]); //
const reqMaster = reactive<FilterMaster>({ const reqMaster = reactive<FilterMaster>({
id: "", id: "",
type: 0, type: 0,
@ -116,7 +121,9 @@ const reqMaster = reactive<FilterMaster>({
const totalRow = ref<number>(0); const totalRow = ref<number>(0);
const selectedPos = ref<PosMaster[]>([]); const selectedPos = ref<PosMaster[]>([]);
/** function เรียกข้อมูล Table Position*/ /**
* function เรยกขอมลรายการตำแหน
*/
async function fetchTable() { async function fetchTable() {
selectedPos.value = []; selectedPos.value = [];
await http await http
@ -149,13 +156,17 @@ function updatePagination(newPagination: NewPagination) {
reqMaster.page = 1; reqMaster.page = 1;
} }
/** funcion ค้นหาข้อมูลใน Table*/ /**
* funcion นหาขอมลใน Table
*/
async function filterKeyword() { async function filterKeyword() {
reqMaster.page = 1; reqMaster.page = 1;
fetchTable(); fetchTable();
} }
/** function ยืนยันกาสืบทอดตำแหน่ง */ /**
* function นยนกาสบทอดตำแหน
*/
function onClickConfirm() { function onClickConfirm() {
if (selectedPos.value.length === 0) { if (selectedPos.value.length === 0) {
dialogMessageNotify($q, "กรุณาเลือกตำแหน่งสืบทอด"); dialogMessageNotify($q, "กรุณาเลือกตำแหน่งสืบทอด");
@ -187,20 +198,9 @@ function onClickConfirm() {
} }
} }
/** callblck function ทำการ fetch ข้อมูล tree เมื่อเปิด popup*/ /**
watch( * function clear อม
() => modal.value, */
async () => {
modal.value ? await fetchTree() : clearForm();
}
);
/** callblck function ทำการ fetch ข้อมูล Table เมื่อมีการเปลี่ยนหน้า*/
watch([() => reqMaster.page, () => reqMaster.pageSize], async () => {
await fetchTable();
});
/** function clear ข้อมูล*/
function clearForm() { function clearForm() {
nodeTree.value = []; nodeTree.value = [];
rows.value = []; rows.value = [];
@ -212,6 +212,23 @@ function clearForm() {
reqMaster.pageSize = 10; reqMaster.pageSize = 10;
reqMaster.keyword = ""; reqMaster.keyword = "";
} }
/**
* callblck function ทำการ fetch อม tree เมอเป popup*
*/
watch(
() => modal.value,
async () => {
modal.value ? await fetchTree() : clearForm();
}
);
/**
* callblck function ทำการ fetch อม Table เมอมการเปลยนหน
*/
watch([() => reqMaster.page, () => reqMaster.pageSize], async () => {
await fetchTable();
});
</script> </script>
<template> <template>

View file

@ -1,46 +1,45 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, watch } from "vue"; import { ref, onMounted, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { StructChart } from "structure-chart";
import "structure-chart/structure-chart.css";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { StructChart } from "structure-chart";
import "structure-chart/structure-chart.css";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational"; import { useOrganizational } from "@/modules/02_organization/store/organizational";
const $q = useQuasar();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const store = useOrganizational(); const store = useOrganizational();
const { showLoader, hideLoader, messageError } = mixin; const { showLoader, hideLoader, messageError } = mixin;
const $q = useQuasar(); // show dialog
// import chartData from '@/assets/structChartData'
// const dataSource = ref(chartData)
const dataSource = ref(); // Chart const dataSource = ref(); // Chart
const rootOrgID = ref(); // org id root const rootOrgID = ref(); // org id root
const dataSourceLock = ref(); // Chart home const dataSourceLock = ref(); // Chart home
const chartRef = ref(); // chart const chartRef = ref(); // chart
const savePNG = () => {
chartRef.value.savePNG();
};
const savePDF = () => {
chartRef.value.savePDF();
};
const loader = ref<boolean>(false); // Loader const loader = ref<boolean>(false); // Loader
onMounted(async () => { /**
const id = * function ดาวนโหลดไฟลโครงสราง PNG
store.typeOrganizational === "current" */
? store.activeId function savePNG() {
: store.typeOrganizational === "draft" chartRef.value.savePNG();
? store.draftId }
: store.historyId;
id && (await fetchStructChart(id, "0")); /**
}); * function ดาวนโหลดไฟลโครงสราง PDF
*/
function savePDF() {
chartRef.value.savePDF();
}
/**
* function งขอมลโครงสราง
* @param id id โครงสราง
* @param type
* @param status
*/
async function fetchStructChart( async function fetchStructChart(
id: string, id: string,
type: string, type: string,
@ -49,9 +48,9 @@ async function fetchStructChart(
showLoader(); showLoader();
await http await http
.get(config.API.orgStructChart(id, type)) .get(config.API.orgStructChart(id, type))
.then((res) => { .then(async (res) => {
if (res.data.result.length > 0) { if (res.data.result.length > 0) {
const data = res.data.result[0]; const data = await res.data.result[0];
const struct = []; const struct = [];
struct.push({ ...data, officer: [], heads: [] }); struct.push({ ...data, officer: [], heads: [] });
dataSource.value = struct[0]; dataSource.value = struct[0];
@ -72,14 +71,14 @@ async function fetchStructChart(
* เมอมการคลกท Chart ใหาน ID ของหนวยงานทกคล แลวดงขอม Chart ของหนวยงานน จาก API * เมอมการคลกท Chart ใหาน ID ของหนวยงานทกคล แลวดงขอม Chart ของหนวยงานน จาก API
* @param data * @param data
*/ */
const refreshChart = async (data: any, type: number) => { async function refreshChart(data: any, type: number) {
if (data.value === undefined) { if (data.value === undefined) {
fetchStructChart(data, type.toString()); fetchStructChart(data, type.toString());
rootOrgID.value = data; rootOrgID.value = data;
} else { } else {
searchAndReplace(dataSource.value, data.value); searchAndReplace(dataSource.value, data.value);
} }
}; }
function searchAndReplace(data: any, id: string) { function searchAndReplace(data: any, id: string) {
if (data.deptID === id) { if (data.deptID === id) {
@ -100,7 +99,7 @@ function searchAndReplace(data: any, id: string) {
* @param id OrgID ของหนวยงานทองการหา * @param id OrgID ของหนวยงานทองการหา
* @param chart Array ของ Object ของหนวยงานยอยใน Tree * @param chart Array ของ Object ของหนวยงานยอยใน Tree
*/ */
const chartTraverse = (id: any, chart: any): any => { function chartTraverse(id: any, chart: any): any {
let _returnPath = []; let _returnPath = [];
for (const child of chart) { for (const child of chart) {
if (child.deptID === id) { if (child.deptID === id) {
@ -128,7 +127,7 @@ const chartTraverse = (id: any, chart: any): any => {
} }
} }
} }
}; }
const findPath = (id: any) => { const findPath = (id: any) => {
let _path = []; let _path = [];
@ -149,13 +148,13 @@ const theBreadcrumb = ref();
/** /**
* สราง Path Breadcrumbs * สราง Path Breadcrumbs
*/ */
const breadcrumbsGen = () => { function breadcrumbsGen() {
if (rootOrgID.value !== 0) { if (rootOrgID.value !== 0) {
theBreadcrumb.value = []; theBreadcrumb.value = [];
const newPath = findPath(rootOrgID.value); const newPath = findPath(rootOrgID.value);
theBreadcrumb.value = newPath; theBreadcrumb.value = newPath;
} }
}; }
watch( watch(
() => store.typeOrganizational, () => store.typeOrganizational,
@ -178,6 +177,17 @@ watch(
store.historyId && (await fetchStructChart(store.historyId, "0", true)); store.historyId && (await fetchStructChart(store.historyId, "0", true));
} }
); );
onMounted(async () => {
const id =
store.typeOrganizational === "current"
? store.activeId
: store.typeOrganizational === "draft"
? store.draftId
: store.historyId;
id && (await fetchStructChart(id, "0"));
});
</script> </script>
<template> <template>

View file

@ -1,12 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { OrgChart } from "bma-org-chart";
import "bma-org-chart/org-chart.css";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { OrgChart } from "bma-org-chart";
import "bma-org-chart/org-chart.css";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational"; import { useOrganizational } from "@/modules/02_organization/store/organizational";
import avatar from "@/assets/avatar_user.jpg"; import avatar from "@/assets/avatar_user.jpg";
@ -26,10 +26,10 @@ const chartRef = ref(); // อ้างอิงไปที่ตัว chart
/** /**
* fetch อม Chart โครงสราง * fetch อม Chart โครงสราง
*/ */
function fetchOrgChart() { async function fetchOrgChart() {
showLoader(); showLoader();
let urlRequest = config.API.orgChart(rootOrgID.value); let urlRequest = config.API.orgChart(rootOrgID.value);
http await http
.get(urlRequest) .get(urlRequest)
.then(async (response) => { .then(async (response) => {
if (response.data.result.length > 0) { if (response.data.result.length > 0) {

View file

@ -23,14 +23,8 @@ import { useCounterMixin } from "@/stores/mixin";
/** use*/ /** use*/
const $q = useQuasar(); const $q = useQuasar();
const store = useOrganizational(); const store = useOrganizational();
const { const { dialogRemove, showLoader, hideLoader, messageError, success } =
dialogRemove, useCounterMixin();
showLoader,
hideLoader,
messageError,
success,
date2Thai,
} = useCounterMixin();
/** props*/ /** props*/
const nodeTEST = defineModel<OrgTree[]>("nodeTree", { default: [] }); const nodeTEST = defineModel<OrgTree[]>("nodeTree", { default: [] });
@ -298,8 +292,8 @@ async function onClickEdit(node: OrgTree) {
* @param id ID โครงสราง * @param id ID โครงสราง
* @param rootId RootID * @param rootId RootID
*/ */
function onClickDel(type: number, id: string, rootId: string) { async function onClickDel(type: number, id: string, rootId: string) {
const level = store.checkLevel(type); const level = await store.checkLevel(type);
dialogRemove($q, async () => { dialogRemove($q, async () => {
showLoader(); showLoader();
await http await http

View file

@ -1,22 +1,23 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from "vue"; import { ref, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import config from "@/app.config"; import config from "@/app.config";
import http from "@/plugins/http"; import http from "@/plugins/http";
import genreport from "@/plugins/genreportxlsx"; import genreport from "@/plugins/genreportxlsx";
import { checkPermission } from "@/utils/permissions"; import { checkPermission } from "@/utils/permissions";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import { useCounterMixin } from "@/stores/mixin";
/** importType*/ /** importType*/
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
import type { import type {
ListMenu, ListMenu,
NewPagination, NewPagination,
DataDocument,
} from "@/modules/02_organization/interface/index/Main"; } from "@/modules/02_organization/interface/index/Main";
import type { FilterMaster } from "@/modules/02_organization/interface/request/organizational"; import type { FilterMaster } from "@/modules/02_organization/interface/request/organizational";
import type { import type { PosMaster2 } from "@/modules/02_organization/interface/response/organizational";
PosMaster2,
OrgTree,
} from "@/modules/02_organization/interface/response/organizational";
import type { DataPosition } from "@/modules/02_organization/interface/index/organizational"; import type { DataPosition } from "@/modules/02_organization/interface/index/organizational";
/** importComponents*/ /** importComponents*/
@ -29,8 +30,6 @@ import DialogSelectPerson from "@/modules/02_organization/components/DialogSelec
import DialogSuccession from "@/modules/02_organization/components/DialogSuccession.vue"; // import DialogSuccession from "@/modules/02_organization/components/DialogSuccession.vue"; //
/** importStore*/ /** importStore*/
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import { useCounterMixin } from "@/stores/mixin";
const $q = useQuasar(); const $q = useQuasar();
const store = useOrganizational(); const store = useOrganizational();
@ -64,9 +63,9 @@ const props = defineProps({
}, },
}); });
const modalSelectPerson = ref<boolean>(false); const modalSelectPerson = ref<boolean>(false); //
const rowId = ref<string>(""); const rowId = ref<string>(""); //id
const actionType = ref<string>(""); const actionType = ref<string>(""); //
/** ListMenu Table*/ /** ListMenu Table*/
const listMenu = ref<ListMenu[]>([ const listMenu = ref<ListMenu[]>([
{ {
@ -106,7 +105,7 @@ const listMenu = ref<ListMenu[]>([
color: "deep-purple", color: "deep-purple",
}, },
]); ]);
const document = ref<any>([ const document = ref<DataDocument[]>([
{ {
name: "บัญชี 1", name: "บัญชี 1",
val: "report1", val: "report1",
@ -254,7 +253,7 @@ const columnsExpand = ref<QTableProps["columns"]>([
}, },
]); ]);
const dialogPosition = ref<boolean>(false); const dialogPosition = ref<boolean>(false); //
/** /**
* function openPopup เพมอตรากำล * function openPopup เพมอตรากำล
* @param type ประเภท * @param type ประเภท
@ -266,14 +265,19 @@ function onClickPosition(type: string, id: string) {
dialogPosition.value = !dialogPosition.value; dialogPosition.value = !dialogPosition.value;
} }
/**
* function เป popup เพมแกไข ตรากำล
* @param type ประเภทการกระทำ
* @param id id องการกระทำ
*/
function onClickCopyPosition(type: string, id: string) { function onClickCopyPosition(type: string, id: string) {
rowId.value = id ? id : ""; rowId.value = id ? id : "";
actionType.value = type; actionType.value = type;
dialogPosition.value = !dialogPosition.value; dialogPosition.value = !dialogPosition.value;
} }
const dialogDetail = ref<boolean>(false); const dialogDetail = ref<boolean>(false); //
const dataDetailPos = ref<DataPosition[]>([]); const dataDetailPos = ref<DataPosition[]>([]); //
/** /**
* function รายละเอยดประวตำแหน * function รายละเอยดประวตำแหน
* @param data อม ประวตำแหน * @param data อม ประวตำแหน
@ -351,13 +355,19 @@ function updatePagination(newPagination: NewPagination) {
reqMaster.value.page = 1; reqMaster.value.page = 1;
} }
/** function openPopup เลือกตนครอง*/ /**
* function เป pop เลอกตนครอง
* @param data อมลตำแหนงทองการเพมคนครอง
*/
function openSelectPerson(data: DataPosition[]) { function openSelectPerson(data: DataPosition[]) {
modalSelectPerson.value = true; modalSelectPerson.value = true;
dataDetailPos.value = data; dataDetailPos.value = data;
} }
/** ลบคนครอง */ /**
* function นยนการลบขอมลคนครอง
* @param id รายการทองการลบ
*/
function removePerson(id: string) { function removePerson(id: string) {
dialogRemove( dialogRemove(
$q, $q,
@ -389,13 +399,17 @@ function removePerson(id: string) {
} }
const modalDialogSuccession = ref<boolean>(false); const modalDialogSuccession = ref<boolean>(false);
/** function openPopup สืบทอดตำแหน่ง*/ /**
* function openPopup บทอดตำแหน
*/
function onClickInherit(id: string) { function onClickInherit(id: string) {
modalDialogSuccession.value = !modalDialogSuccession.value; modalDialogSuccession.value = !modalDialogSuccession.value;
rowId.value = id; rowId.value = id;
} }
/** ดึงข้อมูลสถิติจำนวนด้านบน*/ /**
* งขอมลสถจำนวนดานบน
*/
function getSummary() { function getSummary() {
showLoader(); showLoader();
http http
@ -428,7 +442,9 @@ function getSummary() {
}); });
} }
/** function DownloadReport*/ /**
* function DownloadReport
*/
async function onClickDownloadReport(val: string, name: string) { async function onClickDownloadReport(val: string, name: string) {
showLoader(); showLoader();
await http await http

View file

@ -1,8 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, onMounted, watch } from "vue"; import { ref, reactive, onMounted, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import { useCounterMixin } from "@/stores/mixin";
/** importType*/ /** importType*/
import type { import type {
@ -17,10 +20,6 @@ import type { FilterMaster } from "@/modules/02_organization/interface/request/o
import TreeMain from "@/modules/02_organization/components/TreeMain.vue"; import TreeMain from "@/modules/02_organization/components/TreeMain.vue";
import TreeTable from "@/modules/02_organization/components/TreeTable.vue"; import TreeTable from "@/modules/02_organization/components/TreeTable.vue";
/** importStore*/
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import { useCounterMixin } from "@/stores/mixin";
/** use*/ /** use*/
const store = useOrganizational(); const store = useOrganizational();
const $q = useQuasar(); const $q = useQuasar();
@ -133,7 +132,9 @@ async function fetchDataTable(id: string, level: number, action: boolean) {
}); });
} }
/** ดึงข้อมูลสถิติจำนวนด้านบน*/ /**
* งขอมลสถจำนวนดานบน
*/
function getSummary() { function getSummary() {
http http
.post(config.API.orgSummary, { .post(config.API.orgSummary, {
@ -158,13 +159,20 @@ function getSummary() {
}); });
} }
/** funcion ค้นหาข้อมูลใน Table*/ /**
* funcion นหาขอมลใน Table
*/
async function filterKeyword() { async function filterKeyword() {
reqMaster.page = 1; reqMaster.page = 1;
action1.value === false && action1.value === false &&
fetchDataTable(reqMaster.id, reqMaster.type, false); fetchDataTable(reqMaster.id, reqMaster.type, false);
} }
/**
* นหาโครงสรางในขอมลแบบลำดบชนเพอหาทตรงก orgTreeId
* @param data อมลโครงสราง
* @param targetId id ของโครงสรางทองการคนหา
*/
function searchAndReplaceOrgName(data: any, targetId: string) { function searchAndReplaceOrgName(data: any, targetId: string) {
for (const child of data) { for (const child of data) {
if (child.orgTreeId === targetId) { if (child.orgTreeId === targetId) {
@ -179,17 +187,6 @@ function searchAndReplaceOrgName(data: any, targetId: string) {
return false; // Not found in this branch return false; // Not found in this branch
} }
/**lifecycle Hook*/
onMounted(async () => {
const id =
store.typeOrganizational === "current"
? store.activeId
: store.typeOrganizational === "draft"
? store.draftId
: historyId.value;
id && (await fetchDataTree(id));
});
/** callback function ทำงาน ทำการ fetch ข้อมูล Tree เมื่อมีการเลือกประวัติโครงสร้าง*/ /** callback function ทำงาน ทำการ fetch ข้อมูล Tree เมื่อมีการเลือกประวัติโครงสร้าง*/
watch( watch(
() => count.value, () => count.value,
@ -198,7 +195,9 @@ watch(
} }
); );
/** callblck function ทำการ fetch ข้อมูล Tree เมื่อมีการเปลี่ยนโครงสร้าง*/ /**
* callblck function ทำการ fetch อม Tree เมอมการเปลยนโครงสราง
*/
watch( watch(
() => store.typeOrganizational, () => store.typeOrganizational,
() => { () => {
@ -210,13 +209,17 @@ watch(
} }
); );
/** callblck function ทำการ fetch ข้อมูล Table เมื่อมีการเปลี่ยนหน้า*/ /**
* callblck function ทำการ fetch อม Table เมอมการเปลยนหน
*/
watch([() => reqMaster.page, () => reqMaster.pageSize], () => { watch([() => reqMaster.page, () => reqMaster.pageSize], () => {
action1.value === false && action1.value === false &&
fetchDataTable(reqMaster.id, reqMaster.type, false); fetchDataTable(reqMaster.id, reqMaster.type, false);
}); });
/** callblck function ทำการ fetch ข้อมูล Table เมื่อแสดงตำแหน่งทั้งหมด*/ /**
* callblck function ทำการ fetch อม Table เมอแสดงตำแหนงทงหมด
*/
watch( watch(
() => reqMaster.isAll, () => reqMaster.isAll,
() => { () => {
@ -235,6 +238,21 @@ watch(
store.draftId && fetchDataTree(store.draftId?.toString()); store.draftId && fetchDataTree(store.draftId?.toString());
} }
); );
/**
* lifecycle Hook ทำเม Components กเรยกใชงาน
*
* และดงชอมลโครงสรางตาม ID ของประเภทโครงสราง จจ,แบบราง
*/
onMounted(async () => {
const id =
store.typeOrganizational === "current"
? store.activeId
: store.typeOrganizational === "draft"
? store.draftId
: historyId.value;
id && (await fetchDataTree(id));
});
</script> </script>
<template> <template>

View file

@ -7,6 +7,11 @@ interface DataOption {
name: string; name: string;
} }
interface DataDocument {
name: string;
val: string;
}
interface ListMenu { interface ListMenu {
label: string; label: string;
icon: string; icon: string;
@ -121,6 +126,7 @@ interface RowDetailPositions {
posLevelId: string; posLevelId: string;
posExecutiveId: string; posExecutiveId: string;
isSpecial: boolean; isSpecial: boolean;
positionIsSelected: string;
} }
interface NewPagination { interface NewPagination {
@ -147,4 +153,5 @@ export type {
HistoryPostType, HistoryPostType,
FormPositionSelectRef, FormPositionSelectRef,
NewPagination, NewPagination,
DataDocument,
}; };

View file

@ -8,10 +8,10 @@ interface DataPosType {
interface DataLevel { interface DataLevel {
id: string; id: string;
posLevelName: number; posLevelName: number | string;
posTypeName: string; posTypeName: string;
posTypeId: string; posTypeId: string;
posLevelAuthority: string; posLevelAuthority: string;
} }
export type { DataPosType }; export type { DataPosType, DataLevel };

View file

@ -9,17 +9,17 @@ import type {
} from "@/modules/02_organization/interface/response/organizational"; } from "@/modules/02_organization/interface/response/organizational";
export const useOrganizational = defineStore("organizationalStore", () => { export const useOrganizational = defineStore("organizationalStore", () => {
const typeOrganizational = ref<string>("current"); const typeOrganizational = ref<string>("current"); // ประเภทโครงสร้าง
const statusView = ref<string>("list"); const statusView = ref<string>("list"); // การแสดงผล รายการ,map
const dataActive = ref<DataActive>(); const dataActive = ref<DataActive>(); //ข้อมูลโครงสร้าง
const activeId = ref<string>(); const activeId = ref<string>(); // id โครงสร้างปัจจุบัน
const draftId = ref<string>(); const draftId = ref<string>(); // id แบบร่างโครงสร้าง
const historyId = ref<string>(); const historyId = ref<string>(); // id ประวัติโครงสร้าง
const treeId = ref<string>(); const isPublic = ref<boolean>(false); // การเผยแพร่
const level = ref<number>(); const treeId = ref<string>(); // id โหนด
const isPublic = ref<boolean>(false); const level = ref<number>(); // ระดับโหนด
const orgPublishDate = ref<Date | null>(null); const orgPublishDate = ref<Date | null>(null); // วันเผยแพร่
const sumPosition = reactive({ const sumPosition = reactive({
total: 0, total: 0,
use: 0, use: 0,
@ -29,6 +29,10 @@ export const useOrganizational = defineStore("organizationalStore", () => {
vacantRoot: 0, vacantRoot: 0,
}); });
/**
*
* @param data
*/
function getSumPosition(data: SumPosition) { function getSumPosition(data: SumPosition) {
sumPosition.total = data.totalPosition; sumPosition.total = data.totalPosition;
sumPosition.totalRoot = data.totalRootPosition ? data.totalRootPosition : 0; sumPosition.totalRoot = data.totalRootPosition ? data.totalRootPosition : 0;
@ -56,14 +60,23 @@ export const useOrganizational = defineStore("organizationalStore", () => {
} }
} }
function fetchDataActive(data: DataActive) { /**
*
* @param data
*/
async function fetchDataActive(data: DataActive) {
dataActive.value = data;
activeId.value = data.activeId; activeId.value = data.activeId;
draftId.value = data.draftId; draftId.value = data.draftId;
dataActive.value = data;
isPublic.value = data.isPublic; isPublic.value = data.isPublic;
orgPublishDate.value = data.orgPublishDate; orgPublishDate.value = data.orgPublishDate;
} }
/**
*
* @param data
* @returns
*/
function fetchPosMaster(data: PosMaster[]) { function fetchPosMaster(data: PosMaster[]) {
const newPosMaster = data.map((e: PosMaster) => ({ const newPosMaster = data.map((e: PosMaster) => ({
...e, ...e,
@ -89,7 +102,12 @@ export const useOrganizational = defineStore("organizationalStore", () => {
return newPosMaster; return newPosMaster;
} }
function checkLevel(type: number) { /**
*
* @param type
* @returns
*/
async function checkLevel(type: number) {
switch (type) { switch (type) {
case 0: case 0:
return "Root"; return "Root";
@ -104,6 +122,11 @@ export const useOrganizational = defineStore("organizationalStore", () => {
} }
} }
/**
*
* @param type
* @returns
*/
function convertType(type: string) { function convertType(type: string) {
switch (type) { switch (type) {
case "DEPARTMENT": case "DEPARTMENT":

View file

@ -1,165 +0,0 @@
<script setup lang="ts">
import { ref, onMounted, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import type { ListMenu } from "@/modules/02_organization/interface/index/Main";
import type { OrgTree } from "@/modules/02_organization/interface/response/organizational";
/** importStore*/
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import { useCounterMixin } from "@/stores/mixin";
const store = useOrganizational();
const { dialogRemove, showLoader, hideLoader, messageError, success } =
useCounterMixin();
const $q = useQuasar();
const filter = ref<string>("");
const nodes = ref<Array<any>>([]);
const lazy = ref(nodes);
const expanded = ref<Array<any>>([]);
const notFound = ref<string>("ไม่พบข้อมูลที่ค้นหา");
const noData = ref<string>("ไม่มีข้อมูล");
const selected = ref("");
const idVal = ref("");
async function fetchDataTree(id: string) {
showLoader();
await http
.get(config.API.orgByid(id))
.then((res) => {
const data = res.data.result;
nodes.value = data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
const breakLoop = ref<boolean>(false);
const dataObject = ref([]);
async function onSort(orgRootId: string) {
if (orgRootId) {
idVal.value = "children => " + orgRootId;
breakLoop.value = false;
const targetNodeId = orgRootId;
for (let index = 0; index < nodes.value.length; index++) {
const element = nodes.value[index];
searchAndReplace(element, targetNodeId);
if (breakLoop.value) break;
}
} else {
idVal.value = "root";
}
}
function searchAndReplace(treeNode: any, organizationId: string) {
if (treeNode.orgTreeId === organizationId) {
dataObject.value = treeNode.children;
breakLoop.value = true;
} else if (treeNode.children) {
for (const child of treeNode.children) {
searchAndReplace(child, organizationId);
}
}
}
const listAdd = ref<ListMenu[]>([
{
label: "จัดลำดับ",
icon: "filter_list",
type: "SORT",
color: "green-7",
},
]);
onMounted(async () => {
await fetchDataTree("a449eac0-93a5-4ccc-8fbc-2974ca8ee61b");
});
</script>
<template>
<div class="col-12 q-py-md q-px-lg">
<q-tree
class="q-pa-md q-gutter-sm"
dense
default-expand-all
selected-color="primary"
:nodes="lazy"
node-key="orgTreeId"
label-key="orgTreeName"
:filter="filter"
:no-results-label="notFound"
:no-nodes-label="noData"
v-model:expanded="expanded"
v-model:selected="selected"
>
<template v-slot:default-header="prop">
<!-- {{ prop.node.orgTreeName }} -->
<div class="row items-center q-px-xs q-pt-xs q-gutter-sm">
<!--แสดงชอแผนก มพวหนา คลกแลวกาง/ Tree-->
<div>
<div class="text-weight-medium">
{{ prop.node.orgTreeName }}
</div>
<div class="text-weight-light">
{{ prop.node.orgCode == null ? null : prop.node.orgCode }}
{{
prop.node.orgTreeShortName == null
? null
: prop.node.orgTreeShortName
}}
</div>
</div>
</div>
<q-btn
flat
dense
icon="mdi-dots-vertical"
class="q-pa-none q-ml-xs"
color="grey-13"
>
<q-menu>
<q-list
dense
v-for="(item, index) in prop.node.orgLevel === 4
? listAdd.slice(1, 6)
: listAdd"
:key="index"
style="min-width: 100px"
>
<q-item
clickable
v-close-popup
@click="onSort(prop.node.orgRootId)"
>
<q-item-section avatar>
<q-icon :color="item.color" :name="item.icon" />
</q-item-section>
<div>
<q-item-section> {{ item.label }}หนวยงาน </q-item-section>
</div>
</q-item>
</q-list>
</q-menu>
</q-btn>
</template>
</q-tree>
<h5>orgRootId = {{ idVal }}</h5>
<div>
{{ dataObject }}
</div>
</div>
</template>
<style scoped></style>

View file

@ -1,9 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { checkPermission } from "@/utils/permissions";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { checkPermission } from "@/utils/permissions";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import { useCounterMixin } from "@/stores/mixin";
/** /**
* importType * importType
@ -20,12 +23,6 @@ import StructureOrgMain from "@/modules/02_organization/components/StructureOrgM
import DialogFormNewStructure from "@/modules/02_organization/components/DialogNewStructure.vue"; import DialogFormNewStructure from "@/modules/02_organization/components/DialogNewStructure.vue";
import DialogDateTime from "@/modules/02_organization/components/DialogFormDateTime.vue"; import DialogDateTime from "@/modules/02_organization/components/DialogFormDateTime.vue";
/**
* importStore
*/
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import { useCounterMixin } from "@/stores/mixin";
/** /**
* use * use
*/ */
@ -46,9 +43,7 @@ const historyId = ref<string>(""); // ID ประวัติโครงสร
const labelHistory = ref<string>("ประวัติโครงสร้าง"); // const labelHistory = ref<string>("ประวัติโครงสร้าง"); //
const count = ref<number>(0); const count = ref<number>(0);
/** //
* List เพมโครงสราง
*/
const itemStructure = ref<DataOption[]>([ const itemStructure = ref<DataOption[]>([
{ {
id: "NEW", id: "NEW",
@ -70,15 +65,17 @@ const itemStructure = ref<DataOption[]>([
/** /**
* function เรยกขอมลโครงสราง แบบปนและ แบบราง * function เรยกขอมลโครงสราง แบบปนและ แบบราง
*
* เกบขอมลใน store
*/ */
function fetchOrganizationActive() { async function fetchOrganizationActive() {
showLoader(); showLoader();
http await http
.get(config.API.activeOrganization) .get(config.API.activeOrganization)
.then((res) => { .then(async (res) => {
const data = res.data.result; const data = await res.data.result;
if (data) { if (data) {
store.fetchDataActive(data); await store.fetchDataActive(data);
if (data.activeName === null && data.draftName === null) { if (data.activeName === null && data.draftName === null) {
isStatusData.value = false; isStatusData.value = false;
} else { } else {
@ -100,13 +97,13 @@ function fetchOrganizationActive() {
} }
/** /**
* function เรยกขอมลประวโครงสราง * function เรยกขอมรายการลประวโครงสราง
*/ */
function fetchHistory() { async function fetchHistory() {
http await http
.get(config.API.organizationHistoryNew) .get(config.API.organizationHistoryNew)
.then((res) => { .then(async (res) => {
const data = res.data.result; const data = await res.data.result;
const filterData = data.filter( const filterData = data.filter(
(e: OrgRevision) => !e.orgRevisionIsDraft && !e.orgRevisionIsCurrent (e: OrgRevision) => !e.orgRevisionIsDraft && !e.orgRevisionIsCurrent
); );
@ -150,12 +147,13 @@ function onClickHistory(id: string, name: string) {
} }
/** /**
* lifecycleHook * lifecycleHook ทำงานเมอมการเรยกใช Components
*
* งขอมลโครงสรางและรายการประวโครงสราง
*/ */
onMounted(async () => { onMounted(async () => {
store.typeOrganizational = "current"; store.typeOrganizational = "current";
await fetchOrganizationActive(); await Promise.all([fetchOrganizationActive(), fetchHistory()]);
await fetchHistory();
}); });
</script> </script>
<template> <template>
@ -370,11 +368,8 @@ onMounted(async () => {
<DialogDateTime <DialogDateTime
:modal="modalDateTime" :modal="modalDateTime"
:close="onClickDateTime" :close="onClickDateTime"
:fetchActive="fetchOrganizationActive" :fetch-active="fetchOrganizationActive"
/> />
<!-- รายละเอยดตำแหน -->
<!-- <DialogPositionDetail v-model:position-detail="modalPositionDetail" /> -->
</template> </template>
<style scoped></style> <style scoped></style>