Refactoring code module 01_metadata => 03_positionEmployee

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-05 16:44:08 +07:00
parent a8d794abe6
commit 24c0b87ec8
22 changed files with 324 additions and 348 deletions

View file

@ -1,31 +1,22 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, onMounted } from "vue"; import { ref, reactive, onMounted } 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*/
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
import type { import type { FormQuery } from "@/modules/01_metadata/interface/index/positionEmployee";
ObjectPosRef, import type { DataOption } from "@/modules/01_metadata/interface/request/position/index";
FormQuery,
} from "@/modules/01_metadata/interface/index/positionEmployee";
import type {
DataOption,
RowDetailPositions,
} from "@/modules/01_metadata/interface/request/position/index";
import type { import type {
ResGroup, ResGroup,
ResLevel, ResLevel,
ResPossition, ResPossition,
} from "@/modules/01_metadata/interface/response/positionEmployee/Main"; } from "@/modules/01_metadata/interface/response/positionEmployee/Main";
/**importComponets*/
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
/**importStore*/
import { useCounterMixin } from "@/stores/mixin";
/**use*/ /**use*/
const $q = useQuasar(); const $q = useQuasar();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
@ -38,6 +29,7 @@ const {
dialogRemove, dialogRemove,
} = mixin; } = mixin;
//table
const rows = ref<ResPossition[]>([]); const rows = ref<ResPossition[]>([]);
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
@ -83,47 +75,80 @@ const visibleColumns = ref<string[]>([
"posTypeName", "posTypeName",
"posLevelName", "posLevelName",
]); ]);
//
const formQuery = reactive<FormQuery>({
type: "positionName",
keyword: "",
});
const optionFilter = ref<DataOption[]>([ const optionFilter = ref<DataOption[]>([
{ id: "positionName", name: "ชื่อตำแหน่ง" }, { id: "positionName", name: "ชื่อตำแหน่ง" },
{ id: "positionType", name: "กลุ่มงาน" }, { id: "positionType", name: "กลุ่มงาน" },
{ id: "positionLevel", name: "ระดับชั้นงาน" }, { id: "positionLevel", name: "ระดับชั้นงาน" },
]); ]);
const formQuery = reactive<FormQuery>({
type: "positionName",
keyword: "",
});
const modalDialog = ref<boolean>(false); const modalDialog = ref<boolean>(false);
const isStatusEdit = ref<boolean>(false); const isStatusEdit = ref<boolean>(false);
const posId = ref<string>(""); const posId = ref<string>("");
const formDataPos = reactive({ const formDataPos = reactive({
posName: "", posName: "",
posTypeName: "", posTypeName: "",
posLevelName: "", posLevelName: "",
}); });
const posNameRef = ref<object | null>(null);
const posTypeNameRef = ref<object | null>(null);
const posLevelNameRef = ref<object | null>(null);
const objectRef: ObjectPosRef = {
posName: posNameRef,
posTypeName: posTypeNameRef,
posLevelName: posLevelNameRef,
};
const posTypeMain = ref<ResGroup[]>([]); const posTypeMain = ref<ResGroup[]>([]);
const posTypeOp = ref<DataOption[]>([]); const posTypeOp = ref<DataOption[]>([]);
const posLevelOp = ref<DataOption[]>([]); const posLevelOp = ref<DataOption[]>([]);
function deletePos(id: string) { /**
dialogRemove($q, () => { * งกนดงขอมลรายการตำแหนงจาก API
* @param statusType สถานะการสงประเภทคนหา (true = ไมงประเภทคนหา)
*
* เกบขอมลรายการตำแหนงจากไวใน rows.value
*/
async function fetchData(statusType: boolean = false) {
showLoader();
await http
.get(
config.API.orgEmployeePos +
`?keyword=${formQuery.keyword}&type=${statusType ? "" : formQuery.type}`
)
.then(async (res) => {
rows.value = await res.data.result;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* งกนยนยนการบนทกขอมลตำแหน
*
* เม isStatusEdit เป false จะทำการเพมขอมลรายการขอมลตำแหน าไมจะทำการแกไขขอม
* และเมอเพมขอมลเสรจจำทำการดงขอมลรายการตำแหนงใหม
*/
function onSubmit() {
dialogConfirm($q, async () => {
const body = {
posDictName: formDataPos.posName,
posTypeId: formDataPos.posTypeName,
posLevelId: formDataPos.posLevelName,
};
showLoader(); showLoader();
http // Phat API
.delete(config.API.orgEmployeePosById(id)) const url = !isStatusEdit.value
.then(() => { ? config.API.orgEmployeePos
success($q, "ลบข้อมูลสำเร็จ"); : config.API.orgEmployeePosById(posId.value);
fetchData();
await http[!isStatusEdit.value ? "post" : "put"](url, body)
.then(async () => {
await fetchData();
success($q, "บันทีกข้อมูลสำเร็จ");
closeDialog();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -134,41 +159,61 @@ function deletePos(id: string) {
}); });
} }
async function onClickOpenDialog(typeEdit: boolean = false, data: any = []) { /**
modalDialog.value = true; * งกนยนยนการลบรายการขอมลตำแหน
*
* @param id รายการขอมลตำแหนงทจะลบ
* เมอลบขอมลเสรจจำทำการดงขอมลรายการตำแหนงใหม
*/
function deletePos(id: string) {
dialogRemove($q, async () => {
showLoader();
await http
.delete(config.API.orgEmployeePosById(id))
.then(async () => {
await fetchData();
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
}
/**
* งกนเป popup เพอแกไขหรอคดลอกขอมลตำแหน
* @param typeEdit สถานะการแกไข (true = แกไข, false = เพมใหมหรอคดลอก)
* @param data อมลตำแหนงทองการแกไขหรอคดลอก
*/
async function onClickOpenDialog(
typeEdit: boolean = false,
data: ResPossition = {} as ResPossition
) {
isStatusEdit.value = typeEdit; isStatusEdit.value = typeEdit;
modalDialog.value = true;
//
await fetchType(); await fetchType();
updatePosTypeName(data.posTypeId);
isStatusEdit.value = typeEdit;
modalDialog.value = true;
// id
await updatePosTypeName(data.posTypeId);
if (data) { if (data) {
posId.value = data.id; posId.value = data.id;
setTimeout(() => { formDataPos.posName = data.posDictName;
formDataPos.posName = data.posDictName; formDataPos.posTypeName = data.posTypeId;
formDataPos.posTypeName = data.posTypeId; formDataPos.posLevelName = data.posLevelId;
formDataPos.posLevelName = data.posLevelId;
}, 200);
} }
} }
async function fetchData(statusFetch: boolean = false) { /**
showLoader(); * งกนดงขอมลกลมงาน
await http */
.get(
config.API.orgEmployeePos +
`?keyword=${formQuery.keyword}&type=${
statusFetch ? "" : formQuery.type
}`
)
.then((res) => {
rows.value = res.data.result;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function fetchType() { async function fetchType() {
if (posTypeMain.value.length === 0) { if (posTypeMain.value.length === 0) {
showLoader(); showLoader();
@ -191,47 +236,11 @@ async function fetchType() {
} }
} }
async function onClickSubmit() { /**
const hasError = []; * งกนหาตวเลอกระดบชนงานตาม ID กลมงาน
for (const key in objectRef) { * @param id กลมงาน
if (Object.prototype.hasOwnProperty.call(objectRef, key)) { */
const property = objectRef[key]; async function updatePosTypeName(id: string) {
if (property.value && typeof property.value.validate === "function") {
const isValid = property.value.validate();
hasError.push(isValid);
}
}
}
if (hasError.every((result) => result === true)) {
dialogConfirm($q, () => {
submit();
});
}
}
async function submit() {
const body = {
posDictName: formDataPos.posName,
posTypeId: formDataPos.posTypeName,
posLevelId: formDataPos.posLevelName,
};
showLoader();
try {
const url = !isStatusEdit.value
? config.API.orgEmployeePos
: config.API.orgEmployeePosById(posId.value);
await http[!isStatusEdit.value ? "post" : "put"](url, body);
success($q, "บันทีกข้อมูลสำเร็จ");
fetchData();
} catch (err) {
messageError($q, err);
} finally {
hideLoader();
closeDialog();
}
}
function updatePosTypeName(id: string) {
const posLevel = posTypeMain.value.find((e: ResGroup) => e.id === id); const posLevel = posTypeMain.value.find((e: ResGroup) => e.id === id);
posLevelOp.value = posLevelOp.value =
posLevel?.posLevels.map((e: ResLevel) => ({ posLevel?.posLevels.map((e: ResLevel) => ({
@ -241,6 +250,10 @@ function updatePosTypeName(id: string) {
formDataPos.posLevelName = ""; formDataPos.posLevelName = "";
} }
/**
* งกนป Popup แกไขหรอคดลอกขอมลตำแหน
* และกำหนด formDataPos ไปเปนคาวาง
*/
function closeDialog() { function closeDialog() {
modalDialog.value = false; modalDialog.value = false;
formDataPos.posName = ""; formDataPos.posName = "";
@ -248,8 +261,11 @@ function closeDialog() {
formDataPos.posLevelName = ""; formDataPos.posLevelName = "";
} }
onMounted(() => { /**
fetchData(true); * hook ทำงานเม Components กเรยกใชงาน
*/
onMounted(async () => {
await fetchData(true);
}); });
</script> </script>
<template> <template>
@ -403,7 +419,7 @@ onMounted(() => {
<q-dialog v-model="modalDialog" class="dialog" persistent> <q-dialog v-model="modalDialog" class="dialog" persistent>
<q-card style="width: 350px"> <q-card style="width: 350px">
<form @submit.prevent="onClickSubmit"> <q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader <DialogHeader
:tittle="`${ :tittle="`${
isStatusEdit isStatusEdit
@ -426,7 +442,7 @@ onMounted(() => {
label="ชื่อตำแหน่ง" label="ชื่อตำแหน่ง"
lazy-rules lazy-rules
hide-bottom-space hide-bottom-space
:rules="[(val) => !!val || `${'กรุณากรอกชื่อตำแหน่ง'}`]" :rules="[(val:string) => !!val || `${'กรุณากรอกชื่อตำแหน่ง'}`]"
class="inputgreen" class="inputgreen"
/> />
</div> </div>
@ -445,7 +461,7 @@ onMounted(() => {
option-value="id" option-value="id"
lazy-rules lazy-rules
hide-bottom-space hide-bottom-space
:rules="[(val) => !!val || `${'กรุณาเลือกกลุ่มงาน'}`]" :rules="[(val:string) => !!val || `${'กรุณาเลือกกลุ่มงาน'}`]"
@update:model-value="updatePosTypeName" @update:model-value="updatePosTypeName"
class="inputgreen" class="inputgreen"
/> />
@ -466,7 +482,7 @@ onMounted(() => {
option-value="id" option-value="id"
lazy-rules lazy-rules
hide-bottom-space hide-bottom-space
:rules="[(val) => !!val || `${'กรุณาเลือกระดับชั้นงาน'}`]" :rules="[(val:string) => !!val || `${'กรุณาเลือกระดับชั้นงาน'}`]"
class="inputgreen" class="inputgreen"
/> />
</div> </div>
@ -476,7 +492,7 @@ onMounted(() => {
<q-card-actions align="right"> <q-card-actions align="right">
<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,28 +1,22 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, reactive } from "vue"; import { ref, onMounted, reactive } from "vue";
import { useRouter } from "vue-router";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
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*/
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
import type { ObjectGroupRef } from "@/modules/01_metadata/interface/index/positionEmployee";
import type { ResGroup } from "@/modules/01_metadata/interface/response/positionEmployee/Main"; import type { ResGroup } from "@/modules/01_metadata/interface/response/positionEmployee/Main";
import type { FrmDataGroup } from "@/modules/01_metadata/interface/request/positionEmployee"; import type { FrmDataGroup } from "@/modules/01_metadata/interface/request/positionEmployee";
/** importComponents*/ /** importComponents*/
import dialogHeader from "@/components/DialogHeader.vue"; import dialogHeader from "@/components/DialogHeader.vue";
/** importStore*/
import { usePositionEmployeeDataStore } from "@/modules/01_metadata/stores/positionEmployeeStore";
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const $q = useQuasar(); const $q = useQuasar();
const store = usePositionEmployeeDataStore();
const router = useRouter(); const router = useRouter();
const mixin = useCounterMixin();
const { const {
dialogRemove, dialogRemove,
dialogConfirm, dialogConfirm,
@ -30,8 +24,11 @@ const {
messageError, messageError,
showLoader, showLoader,
hideLoader, hideLoader,
} = mixin; } = useCounterMixin();
//Table
const rows = ref<ResGroup[]>([]); //
const filterKeyword = ref<string>(""); //
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "posTypeName", name: "posTypeName",
@ -67,35 +64,28 @@ const visibleColumns = ref<string[]>([
"posTypeRank", "posTypeRank",
]); ]);
/** from เพิ่มข้อมูลกลุ่มงาน */ //
const formDataGroup = reactive<FrmDataGroup>({ const formDataGroup = reactive<FrmDataGroup>({
posTypeName: "", posTypeName: "",
posTypeShortName: "", posTypeShortName: "",
posTypeRank: null, posTypeRank: null,
}); });
/** formRef*/
const posTypeNameRef = ref<Object | null>(null);
const posTypeShortNameRef = ref<Object | null>(null);
const posTypeRankRef = ref<Object | null>(null);
const objectGroupRef: ObjectGroupRef = {
posTypeName: posTypeNameRef,
posTypeShortName: posTypeShortNameRef,
posTypeRank: posTypeRankRef,
};
const editId = ref<string>(""); const editId = ref<string>("");
const filterKeyword = ref<string>("");
const dialog = ref<boolean>(false); const dialog = ref<boolean>(false);
const dialogStatus = ref<string>(""); const dialogStatus = ref<string>("");
const rows = ref<ResGroup[]>([]);
/**
* งกนดงขอมลรายการกลมงาน API
*
* เกบขอมลรรายการกลมงานไวใน rows.value
*/
async function fetchData() { async function fetchData() {
showLoader(); showLoader();
await http await http
.get(config.API.orgEmployeeType) .get(config.API.orgEmployeeType)
.then(async (res) => { .then(async (res) => {
rows.value = res.data.result; rows.value = await res.data.result;
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -105,54 +95,47 @@ async function fetchData() {
}); });
} }
async function onClickSubmit() { /**
const hasError = []; * งกนเป popup แกไขขอมลกลมงาน
for (const key in objectGroupRef) { * @param data อมลกลมงานทจะแกไข
if (Object.prototype.hasOwnProperty.call(objectGroupRef, key)) { *
const property = objectGroupRef[key]; * กำหนด dialogStatus เป edit และกำหนดให ฟอรมขอมลกลมงาน เป อมลทจะแกไข
if (property.value && typeof property.value.validate === "function") { *
const isValid = property.value.validate(); */
hasError.push(isValid); function onClickOpenDialogEdit(data: ResGroup) {
} dialogStatus.value = "edit";
} dialog.value = true;
} editId.value = data.id;
if (hasError.every((result) => result === true)) { formDataGroup.posTypeName = data.posTypeName;
dialogConfirm($q, () => { formDataGroup.posTypeShortName = data.posTypeShortName;
submit(); formDataGroup.posTypeRank = data.posTypeRank;
});
}
} }
async function submit() { /**
const body: FrmDataGroup = { * นยนการบนทกขอมลรายการกลมงาน
posTypeName: formDataGroup.posTypeName, *
posTypeShortName: formDataGroup.posTypeShortName, * dialogStatus เป 'create' จะทำการเพมขอมลรายการกลมงาน าไมจะทำการแกไขขอม
posTypeRank: Number(formDataGroup.posTypeRank), * เมอบนทกขอมลเสรจจะเรยก function fetchData() เพอดงขอมลรายการกลมงานใหม
}; *
showLoader(); */
try { function onSubmit() {
dialogConfirm($q, async () => {
showLoader();
const body: FrmDataGroup = {
posTypeName: formDataGroup.posTypeName,
posTypeShortName: formDataGroup.posTypeShortName,
posTypeRank: Number(formDataGroup.posTypeRank),
};
// Path API
const url = const url =
dialogStatus.value === "create" dialogStatus.value === "create"
? config.API.orgEmployeeType ? config.API.orgEmployeeType
: config.API.orgEmployeeTypeById(editId.value); : config.API.orgEmployeeTypeById(editId.value);
await http[dialogStatus.value === "create" ? "post" : "put"](url, body); await http[dialogStatus.value === "create" ? "post" : "put"](url, body)
success($q, "บันทีกข้อมูลสำเร็จ"); .then(async () => {
fetchData(); await fetchData();
} catch (err) { success($q, "บันทีกข้อมูลสำเร็จ");
messageError($q, err); closeDialog();
} finally {
hideLoader();
closeDialog();
}
}
function onClickDelete(id: string) {
dialogRemove($q, () => {
showLoader();
http
.delete(config.API.orgEmployeeTypeById(id))
.then(() => {
fetchData();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -163,32 +146,31 @@ function onClickDelete(id: string) {
}); });
} }
function onClickOpenDialogEdit(data: ResGroup) { /**
dialogStatus.value = "edit"; * งกนไปหนารายการระดบชนงาน
dialog.value = true; * @param id กลมงาน
editId.value = data.id; */
formDataGroup.posTypeName = data.posTypeName;
formDataGroup.posTypeShortName = data.posTypeShortName;
formDataGroup.posTypeRank = data.posTypeRank;
}
function onClickDetail(id: string) { function onClickDetail(id: string) {
router.push(`/master-data/position-employee/level/${id}`); router.push(`/master-data/position-employee/level/${id}`);
} }
/**
* งกนป popup แกไขหรอเพมขอมลกลมงาน
*
* และกำหนดให ฟอรมขอมลกลมงาน เปนคาวาง
*/
function closeDialog() { function closeDialog() {
dialog.value = false; dialog.value = false;
clearFormData();
}
function clearFormData() {
formDataGroup.posTypeName = ""; formDataGroup.posTypeName = "";
formDataGroup.posTypeShortName = ""; formDataGroup.posTypeShortName = "";
formDataGroup.posTypeRank = null; formDataGroup.posTypeRank = null;
} }
onMounted(() => { /**
fetchData(); * hook ทำงานเม Components กเรยกใชงาน
*/
onMounted(async () => {
await fetchData();
}); });
</script> </script>
@ -268,17 +250,6 @@ onMounted(() => {
> >
<q-tooltip>แกไขขอม</q-tooltip> <q-tooltip>แกไขขอม</q-tooltip>
</q-btn> </q-btn>
<!-- <q-btn
color="red"
flat
dense
round
icon="mdi-delete"
clickable
@click.stop="onClickDelete(props.row.id)"
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn> -->
</q-td> </q-td>
<q-td v-for="col in props.cols" :key="col.id"> <q-td v-for="col in props.cols" :key="col.id">
{{ col.value ? col.value : "-" }} {{ col.value ? col.value : "-" }}
@ -289,7 +260,7 @@ onMounted(() => {
<q-dialog v-model="dialog" class="dialog" persistent> <q-dialog v-model="dialog" class="dialog" persistent>
<q-card style="width: 350px"> <q-card style="width: 350px">
<form @submit.prevent="onClickSubmit"> <q-form greedy @submit.prevent @validation-success="onSubmit">
<q-card-section class="flex justify-between" style="padding: 0"> <q-card-section class="flex justify-between" style="padding: 0">
<dialog-header <dialog-header
:tittle=" :tittle="
@ -313,7 +284,7 @@ onMounted(() => {
lazy-rules lazy-rules
borderless borderless
bg-color="white" bg-color="white"
:rules="[(val) => val.length > 0 || 'กรุณากรอกชื่อกลุ่มงาน']" :rules="[(val:string) => val.length > 0 || 'กรุณากรอกชื่อกลุ่มงาน']"
hide-bottom-space hide-bottom-space
class="inputgreen" class="inputgreen"
/> />
@ -329,7 +300,7 @@ onMounted(() => {
label="อักษรย่อกลุ่มงาน" label="อักษรย่อกลุ่มงาน"
lazy-rules lazy-rules
hide-bottom-space hide-bottom-space
:rules="[(val) => !!val || `${'กรุณากรอกอักษรย่อกลุ่มงาน'}`]" :rules="[(val:string) => !!val || `${'กรุณากรอกอักษรย่อกลุ่มงาน'}`]"
class="inputgreen" class="inputgreen"
/> />
</div> </div>
@ -345,7 +316,7 @@ onMounted(() => {
borderless borderless
min="1" min="1"
bg-color="white" bg-color="white"
:rules="[(val) => val != undefined || 'กรุณากรอกระดับกลุ่มงาน']" :rules="[(val:string) => val != undefined || 'กรุณากรอกระดับกลุ่มงาน']"
hide-bottom-space hide-bottom-space
mask="############" mask="############"
class="inputgreen" class="inputgreen"
@ -354,19 +325,11 @@ onMounted(() => {
</q-card-section> </q-card-section>
<q-separator /> <q-separator />
<q-card-actions align="right"> <q-card-actions align="right">
<q-btn <q-btn id="onSubmit" type="submit" label="บันทึก" color="public">
id="onSubmit"
type="submit"
dense
unelevated
label="บันทึก"
color="public"
class="q-px-md"
>
<q-tooltip>นทกขอม</q-tooltip> <q-tooltip>นทกขอม</q-tooltip>
</q-btn> </q-btn>
</q-card-actions> </q-card-actions>
</form> </q-form>
</q-card> </q-card>
</q-dialog> </q-dialog>
</template> </template>

View file

@ -11,7 +11,7 @@ import type {
ResGroup, ResGroup,
ResLevel, ResLevel,
} from "@/modules/01_metadata/interface/response/positionEmployee/Main"; } from "@/modules/01_metadata/interface/response/positionEmployee/Main";
import type { ObjectLevelRef } from "@/modules/01_metadata/interface/index/positionEmployee"; import type { DataGroup } from "@/modules/01_metadata/interface/index/positionEmployee";
import type { FormDataLevel } from "@/modules/01_metadata/interface/request/positionEmployee"; import type { FormDataLevel } from "@/modules/01_metadata/interface/request/positionEmployee";
/** importComponts*/ /** importComponts*/
@ -23,21 +23,15 @@ import { useCounterMixin } from "@/stores/mixin";
/**use*/ /**use*/
const $q = useQuasar(); const $q = useQuasar();
const storeOption = useMainOptionDataStore();
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const posName = ref<string>(""); const { dialogConfirm, showLoader, hideLoader, messageError, success } =
const posTypeId = ref<string>(route.params.id.toString()); useCounterMixin();
const {
dialogRemove,
dialogConfirm,
showLoader,
hideLoader,
messageError,
success,
} = useCounterMixin();
const storeOption = useMainOptionDataStore();
// Table
const rows = ref<DataGroup[]>([]); //
const filter = ref<string>(""); //
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "no", name: "no",
@ -60,7 +54,7 @@ const columns = ref<QTableProps["columns"]>([
{ {
name: "posTypeName", name: "posTypeName",
align: "left", align: "left",
label: "กลุ่มงาน", label: "ระดับชั้นงาน",
sortable: true, sortable: true,
field: "posTypeName", field: "posTypeName",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
@ -77,42 +71,38 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px", style: "font-size: 14px",
}, },
]); ]);
const rows = ref<any>([]);
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
"no", "no",
"posLevelName", "posLevelName",
"posTypeName", "posTypeName",
"posLevelAuthority", "posLevelAuthority",
]); ]);
const filter = ref<string>("");
const levelId = ref<string>(""); const posTypeId = ref<string>(route.params.id.toString()); // id
const titleName = ref<string | null>(""); const titleName = ref<string | null>(""); //
const levelId = ref<string>(""); // id
const isStatusEdit = ref<boolean>(false); //
const modalDialog = ref<boolean>(false); // popup
//
const formDataLevel = reactive<FormDataLevel>({ const formDataLevel = reactive<FormDataLevel>({
posLevelName: null, posLevelName: null,
posTypeName: "", posTypeName: "",
posLevelAuthority: "", posLevelAuthority: "",
}); });
/** formRef*/ /**
const posLevelNameRef = ref<Object | null>(null); * งกนดงขอมลรายการระดบชนงาน API
const commanderRef = ref<Object | null>(null); *
const objectLevelRef: ObjectLevelRef = { * เกบขอมลรรายการระดบชนงานไวใน rows.value
posLevelName: posLevelNameRef, */
posLevelAuthority: commanderRef, async function fetchData() {
};
const id = ref<string>(route.params.id.toString());
function fetchData() {
showLoader(); showLoader();
http await http
.get(config.API.orgEmployeeTypeById(id.value)) .get(config.API.orgEmployeeTypeById(posTypeId.value))
.then((res) => { .then(async (res) => {
titleName.value = res.data.result.posTypeName ?? null; titleName.value = res.data.result.posTypeName ?? null;
formDataLevel.posTypeName = res.data.result.posTypeName; formDataLevel.posTypeName = res.data.result.posTypeName;
rows.value = res.data.result.posLevels.map((x: any) => ({ rows.value = await res.data.result.posLevels.map((x: ResLevel) => ({
...x, ...x,
posTypeName: res.data.result.posTypeName, posTypeName: res.data.result.posTypeName,
})); }));
@ -125,9 +115,17 @@ function fetchData() {
}); });
} }
const isStatusEdit = ref<boolean>(false); /**
const modalDialog = ref<boolean>(false); * งกนเป popup แกไขขอมลระดบชนงาน
function onClickOpenDialog(statusEdit: boolean = false, data: any = []) { * @param data อมลระดบชนงานทจะแกไข
*
* กำหนด isStatusEdit เป true และกำหนดให ฟอรมขอมลระดบชนงาน เป อมลทจะแกไข
*
*/
function onClickOpenDialog(
statusEdit: boolean = false,
data: DataGroup = {} as DataGroup
) {
isStatusEdit.value = statusEdit; isStatusEdit.value = statusEdit;
modalDialog.value = true; modalDialog.value = true;
@ -141,6 +139,11 @@ function onClickOpenDialog(statusEdit: boolean = false, data: any = []) {
} }
} }
/**
* งกนป popup แกไขหรอเพมขอมลระดบชนงาน
*
* และกำหนดให ฟอรมขอมลระดบชนงาน เปนคาวาง
*/
function onClickCloseDialog() { function onClickCloseDialog() {
modalDialog.value = false; modalDialog.value = false;
formDataLevel.posLevelName = null; formDataLevel.posLevelName = null;
@ -148,66 +151,57 @@ function onClickCloseDialog() {
formDataLevel.posLevelAuthority = ""; formDataLevel.posLevelAuthority = "";
} }
function onClickSubmit() { /**
const hasError = []; * นยนการบนทกขอมลรายการระดบชนงาน
for (const key in objectLevelRef) { *
if (Object.prototype.hasOwnProperty.call(objectLevelRef, key)) { * dialogStatus เป 'false' จะทำการเพมขอมลรายการระดบชนงาน าไมจะทำการแกไขขอม
const property = objectLevelRef[key]; * เมอบนทกขอมลเสรจจะเรยก function fetchData() เพอดงขอมลรายการระดบชนงานใหม
if (property.value && typeof property.value.validate === "function") { *
const isValid = property.value.validate(); */
hasError.push(isValid); function onSubmit() {
} dialogConfirm($q, async () => {
} showLoader();
} const body = {
if (hasError.every((result) => result === true)) { posLevelName: Number(formDataLevel.posLevelName),
dialogConfirm($q, () => { posTypeId: posTypeId.value,
submit(); posLevelRank: Number(formDataLevel.posLevelName),
}); posLevelAuthority: formDataLevel.posLevelAuthority,
} };
} // Phat APi
async function submit() {
const body = {
posLevelName: Number(formDataLevel.posLevelName),
posTypeId: posTypeId.value,
posLevelRank: Number(formDataLevel.posLevelName),
posLevelAuthority: formDataLevel.posLevelAuthority,
};
showLoader();
try {
const url = !isStatusEdit.value const url = !isStatusEdit.value
? config.API.orgEmployeelevel ? config.API.orgEmployeelevel
: config.API.orgEmployeelevelById(levelId.value); : config.API.orgEmployeelevelById(levelId.value);
await http[!isStatusEdit.value ? "post" : "put"](url, body);
success($q, "บันทีกข้อมูลสำเร็จ");
fetchData();
onClickCloseDialog();
} catch (err) {
messageError($q, err);
} finally {
hideLoader();
}
}
function onClickDelete(id: string) { await http[!isStatusEdit.value ? "post" : "put"](url, body)
dialogRemove($q, () => { .then(async () => {
http await fetchData();
.delete(config.API.orgEmployeelevelById(id)) success($q, "บันทีกข้อมูลสำเร็จ");
.then(() => { onClickCloseDialog();
success($q, "ลบข้อมูลสำเร็จ");
fetchData();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
})
.finally(() => {
hideLoader();
}); });
}); });
} }
/**
* งกนแปลงตำแหนงผอำนาจ
* @param val าของผอำนาจ
* @returns ตำแหนงผอำนาจ
*/
function convertPosLevelAuthority(val: string) { function convertPosLevelAuthority(val: string) {
const result = storeOption.posLevelAuthorityOption.find((e) => e.id === val); const result = storeOption.posLevelAuthorityOption.find((e) => e.id === val);
return result?.label; return result?.label;
} }
/**
* hook ทำงานเม Components กเรยกใชงาน
*
* าม posTypeId จะดงขอมลรายการระดบชนงาน
*/
onMounted(() => { onMounted(() => {
posTypeId.value && fetchData(); posTypeId.value && fetchData();
}); });
@ -295,16 +289,6 @@ onMounted(() => {
> >
<q-tooltip>แกไขขอม</q-tooltip> <q-tooltip>แกไขขอม</q-tooltip>
</q-btn> </q-btn>
<!-- <q-btn
color="red"
flat
dense
round
icon="mdi-delete"
@click="onClickDelete(props.row.id)"
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn> -->
</q-td> </q-td>
<q-td v-for="(col, index) in props.cols" :key="col.id"> <q-td v-for="(col, index) in props.cols" :key="col.id">
<div v-if="col.name == 'no'"> <div v-if="col.name == 'no'">
@ -325,7 +309,7 @@ onMounted(() => {
<q-dialog v-model="modalDialog" class="dialog" persistent> <q-dialog v-model="modalDialog" class="dialog" persistent>
<q-card style="width: 350px"> <q-card style="width: 350px">
<form @submit.prevent="onClickSubmit"> <q-form greedy @submit.prevent @validation-success="onSubmit">
<q-card-section class="flex justify-between" style="padding: 0"> <q-card-section class="flex justify-between" style="padding: 0">
<DialogHeader <DialogHeader
:tittle="isStatusEdit ? 'แก้ไขข้อมูล' : 'เพิ่มข้อมูล'" :tittle="isStatusEdit ? 'แก้ไขข้อมูล' : 'เพิ่มข้อมูล'"
@ -333,7 +317,7 @@ onMounted(() => {
/> />
</q-card-section> </q-card-section>
<q-separator color="grey-4" /> <q-separator />
<q-card-section class="row q-gutter-y-md"> <q-card-section class="row q-gutter-y-md">
<div class="col-12"> <div class="col-12">
<q-input <q-input
@ -346,8 +330,10 @@ onMounted(() => {
borderless borderless
bg-color="white" bg-color="white"
hide-bottom-space hide-bottom-space
mask="#######################################" mask="#"
:rules="[(val) => !!val || 'กรุณากรอกระดับชั้นงาน']" reverse-fill-mask
:rules="[(val:string) => !!val || 'กรุณากรอกระดับชั้นงาน']"
class="inputgreen"
/> />
</div> </div>
@ -366,7 +352,8 @@ onMounted(() => {
borderless borderless
bg-color="white" bg-color="white"
hide-bottom-space hide-bottom-space
:rules="[(val) => !!val || 'กรุณาเลือกผู้มีอำนาจสั่งบรรจุ']" :rules="[(val:string) => !!val || 'กรุณาเลือกผู้มีอำนาจสั่งบรรจุ']"
class="inputgreen"
/> />
</div> </div>
@ -374,7 +361,7 @@ onMounted(() => {
<q-select <q-select
ref="posTypeIdRef" ref="posTypeIdRef"
v-model="formDataLevel.posTypeName" v-model="formDataLevel.posTypeName"
label="กลุ่มงาน" label="ระดับชั้นงาน"
outlined outlined
dense dense
bg-color="white" bg-color="white"
@ -384,21 +371,13 @@ onMounted(() => {
/> />
</div> </div>
</q-card-section> </q-card-section>
<q-separator />
<q-card-actions align="right"> <q-card-actions align="right">
<q-btn <q-btn id="onSubmit" type="submit" label="บันทึก" color="public">
id="onSubmit"
type="submit"
dense
unelevated
label="บันทึก"
color="public"
class="q-px-md"
>
<q-tooltip>นทกขอม</q-tooltip> <q-tooltip>นทกขอม</q-tooltip>
</q-btn> </q-btn>
</q-card-actions> </q-card-actions>
</form> </q-form>
</q-card> </q-card>
</q-dialog> </q-dialog>
</template> </template>

View file

@ -35,7 +35,7 @@ const formExecutive = reactive<RowListForm>({
/** /**
* นยนการบนทกขอมลรายการตำแหนงทางการบรหาร * นยนการบนทกขอมลรายการตำแหนงทางการบรหาร
* *
* isEdit เป false จะทำการเพมขอมลรายการตำแหนงทางการบรหาร าไมจะทำการแกไขขอม * isEdit เป false จะทำการเพมขอมลรายการตำแหนงทางการบรหาร าไมจะทำการแกไขขอม
* เมอบนทกขอมลเสรจจะเรยก function props.getData() เพอดงขอมลรายการตำแหนงทางการบรหาร * เมอบนทกขอมลเสรจจะเรยก function props.getData() เพอดงขอมลรายการตำแหนงทางการบรหาร
* *
*/ */

View file

@ -25,4 +25,18 @@ interface FormQuery {
keyword: string; keyword: string;
} }
export type { ObjectGroupRef, ObjectLevelRef, ObjectPosRef, FormQuery }; interface DataGroup {
id: string;
posLevelAuthority: string;
posLevelName: number;
posLevelRank: number;
posTypeName: string;
}
export type {
ObjectGroupRef,
ObjectLevelRef,
ObjectPosRef,
FormQuery,
DataGroup,
};

View file

@ -21,6 +21,7 @@ interface ResPossition {
posLevelName: number; posLevelName: number;
posTypeId: string; posTypeId: string;
posTypeName: string; posTypeName: string;
posTypeShortName: string;
} }
export type { ResGroup, ResLevel, ResPossition }; export type { ResGroup, ResLevel, ResPossition };

View file

@ -16,7 +16,7 @@ const personalSubDistrict = () =>
const positionPage = () => const positionPage = () =>
import("@/modules/01_metadata/views/02_position.vue"); //ข้อมูลตำแหน่งข้าราชการ ฯ import("@/modules/01_metadata/views/02_position.vue"); //ข้อมูลตำแหน่งข้าราชการ ฯ
const positionLevelPage = () => const positionLevelPage = () =>
import("@/modules/01_metadata/components/position/ListLevel.vue"); //รายการระดับของประเภทตำแหน่งทั่วไป import("@/modules/01_metadata/components/position/TypeDetail.vue"); //รายการระดับของประเภทตำแหน่งทั่วไป
/** /**
* *
@ -24,7 +24,7 @@ const positionLevelPage = () =>
const positionEmployeePage = () => const positionEmployeePage = () =>
import("@/modules/01_metadata/views/03_positionEmployee.vue"); //ข้อมูลตำแหน่งลูกจ้างประจำ import("@/modules/01_metadata/views/03_positionEmployee.vue"); //ข้อมูลตำแหน่งลูกจ้างประจำ
const positionEmployeeLevelPage = () => const positionEmployeeLevelPage = () =>
import("@/modules/01_metadata/components/position-employee/03ListLevel.vue"); //รายการระดับชั้นงานบริการพื้นฐาน import("@/modules/01_metadata/components/position-employee/GroupDetail.vue"); //รายการระดับชั้นงานบริการพื้นฐาน
/** /**
* *

View file

@ -5,14 +5,14 @@ import { usePersonalDataStore } from "@/modules/01_metadata/stores/personalStore
import type { MainTabs } from "@/modules/01_metadata/interface/index/Main"; import type { MainTabs } from "@/modules/01_metadata/interface/index/Main";
import ListPrefix from "@/modules/01_metadata/components/personal/01ListPrefix.vue"; // import ListPrefix from "@/modules/01_metadata/components/personal/01_Prefix.vue"; //
import ListRank from "@/modules/01_metadata/components/personal/02ListRank.vue"; // import ListRank from "@/modules/01_metadata/components/personal/02_Rank.vue"; //
import ListGender from "@/modules/01_metadata/components/personal/03ListGender.vue"; // import ListGender from "@/modules/01_metadata/components/personal/03_Gender.vue"; //
import ListRelationship from "@/modules/01_metadata/components/personal/04ListRelationship.vue"; // import ListRelationship from "@/modules/01_metadata/components/personal/04_Relationship.vue"; //
import ListBloodGroup from "@/modules/01_metadata/components/personal/05ListBloodGroup.vue"; // import ListBloodGroup from "@/modules/01_metadata/components/personal/05_BloodGroup.vue"; //
import ListReligion from "@/modules/01_metadata/components/personal/06ListReligion.vue"; // import ListReligion from "@/modules/01_metadata/components/personal/06_Religion.vue"; //
import ListProvince from "@/modules/01_metadata/components/personal/07ListProvince.vue"; // import ListProvince from "@/modules/01_metadata/components/personal/07_Province.vue"; //
import ListEducation from "@/modules/01_metadata/components/personal/08ListEducationLevel.vue"; // import ListEducation from "@/modules/01_metadata/components/personal/08_EducationLevel.vue"; //
const store = usePersonalDataStore(); const store = usePersonalDataStore();

View file

@ -5,9 +5,9 @@ import { usePositionDataStore } from "../stores/positionListStore";
import type { MainTabs } from "@/modules/01_metadata/interface/index/Main"; import type { MainTabs } from "@/modules/01_metadata/interface/index/Main";
import ListPosition from "@/modules/01_metadata/components/position/01ListPosition.vue"; // import ListPosition from "@/modules/01_metadata/components/position/01_Position.vue"; //
import ListType from "@/modules/01_metadata/components/position/02ListType.vue"; // import ListType from "@/modules/01_metadata/components/position/02_Type.vue"; //
import ListExecutive from "@/modules/01_metadata/components/position/03ListExecutive.vue"; // import ListExecutive from "@/modules/01_metadata/components/position/03_Executive.vue"; //
const store = usePositionDataStore(); const store = usePositionDataStore();

View file

@ -1,13 +1,20 @@
div
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import ListPosition from "@/modules/01_metadata/components/position-employee/01ListPosition.vue";
import ListType from "@/modules/01_metadata/components/position-employee/02ListType.vue";
import { usePositionEmployeeDataStore } from "../stores/positionEmployeeStore"; import { usePositionEmployeeDataStore } from "../stores/positionEmployeeStore";
// const store.pathLocation = ref<string>("list_position");
const tabs = ref<Array<any>>([]); import type { MainTabs } from "@/modules/01_metadata/interface/index/Main";
import ListPosition from "@/modules/01_metadata/components/position-employee/01_PositionMain.vue"; //
import ListType from "@/modules/01_metadata/components/position-employee/02_GroupMain.vue"; //
const store = usePositionEmployeeDataStore(); const store = usePositionEmployeeDataStore();
const tabs = ref<Array<MainTabs>>([]); // Tab
/**
* hook ทำงานเม Components กเรยกใชงาน
*/
onMounted(() => { onMounted(() => {
const tabsPerson = [ const tabsPerson = [
{ label: "ตำแหน่ง", value: "list_position" }, { label: "ตำแหน่ง", value: "list_position" },
@ -51,10 +58,6 @@ onMounted(() => {
<q-tab-panel name="list_type"> <q-tab-panel name="list_type">
<ListType v-if="store.pathLocation == 'list_type'" /> <ListType v-if="store.pathLocation == 'list_type'" />
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="list_executive">
<ListExecutive v-if="store.pathLocation == 'list_executive'" />
</q-tab-panel>
</q-tab-panels> </q-tab-panels>
</q-card> </q-card>
</template> </template>