[fix] แก้ไขกรณีแก้ไขตำแหน่ง/แก้ไขอัตรากำลังแล้วมีคนครองอยู่

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-08-22 13:11:27 +07:00
parent 762acf46bd
commit 0be2f0d037
4 changed files with 103 additions and 58 deletions

View file

@ -44,6 +44,10 @@ const {
* props * props
*/ */
const reqMaster = defineModel<FilterMaster>("reqMaster", { required: true }); // qurey const reqMaster = defineModel<FilterMaster>("reqMaster", { required: true }); // qurey
const isPositionHolder = defineModel<boolean>("isPositionHolder", {
default: false,
});
const props = defineProps({ const props = defineProps({
modal: Boolean, modal: Boolean,
close: Function, close: Function,
@ -56,6 +60,7 @@ const props = defineProps({
shortName: { type: String, required: true }, shortName: { type: String, required: true },
orgShortName: { type: String, required: true }, orgShortName: { type: String, required: true },
dataTree: { type: Object, default: () => [] }, dataTree: { type: Object, default: () => [] },
positionHolderInfo: { type: Object, default: () => ({}) },
}); });
const isReadonly = ref<boolean>(false); // const isReadonly = ref<boolean>(false); //
@ -104,9 +109,19 @@ const formPositionSelect = reactive<FormPositionSelect>({
}); });
//Table //Table
const selectedPos = ref<RowDetailPositions[]>([]);
const rows = ref<RowDetailPositions[]>([]); // const rows = ref<RowDetailPositions[]>([]); //
const rowsPositionSelect = ref<RowDetailPositions[]>([]); // const rowsPositionSelect = ref<RowDetailPositions[]>([]); //
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{
name: "checkbox",
align: "center",
label: "ครองในตำแหน่ง",
sortable: false,
field: "checkbox",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{ {
name: "no", name: "no",
align: "left", align: "left",
@ -232,6 +247,15 @@ async function fetchPosition(id: string) {
// formData.isStaff = data.isStaff; // formData.isStaff = data.isStaff;
formData.positionSign = data.positionSign; formData.positionSign = data.positionSign;
rows.value = data.positions; rows.value = data.positions;
const positionIsSelected = data.positions.find(
(item: any) => item.id === props.positionHolderInfo.position
);
if (positionIsSelected) {
selectedPos.value.push(positionIsSelected);
} else {
selectedPos.value = [];
}
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -251,20 +275,29 @@ function onSubmit() {
// //
if (rows.value.length == 0) { if (rows.value.length == 0) {
dialogMessageNotify($q, "กรุณาเลือกตำแหน่งอย่างน้อย 1 ตำแหน่ง"); dialogMessageNotify($q, "กรุณาเลือกตำแหน่งอย่างน้อย 1 ตำแหน่ง");
} else if (selectedPos.value.length == 0 && isPositionHolder.value) {
dialogMessageNotify($q, "กรุณาเลือกครองในตำแหน่ง");
} else { } else {
// dialog // dialog
dialogConfirm($q, async () => { dialogConfirm($q, async () => {
const positionsData = rows.value.map((e: RowDetailPositions) => ({ const positionsData = rows.value.map(
posDictName: e.positionName, // () (e: RowDetailPositions, index: number) => ({
posDictField: e.positionField, // id: e.id, //id
posTypeId: e.posTypeId, //* posDictName: e.positionName, // ()
posLevelId: e.posLevelId, //* posDictField: e.positionField, //
posExecutiveId: e.posExecutiveId ? e.posExecutiveId : "", // posTypeId: e.posTypeId, //*
posDictExecutiveField: e.positionExecutiveField, // posLevelId: e.posLevelId, //*
posDictArea: e.positionArea, /// posExecutiveId: e.posExecutiveId ? e.posExecutiveId : "", //
isSpecial: e.isSpecial, posDictExecutiveField: e.positionExecutiveField, //
positionIsSelected: e.positionIsSelected, posDictArea: e.positionArea, ///
})); isSpecial: e.isSpecial,
positionIsSelected:
isPositionHolder.value && selectedPos.value[0]?.id === e.id
? true
: false,
orderNo: index,
})
);
const body = { const body = {
posMasterNoPrefix: formData.prefixNo, //*Prefix Optional (/) posMasterNoPrefix: formData.prefixNo, //*Prefix Optional (/)
@ -280,46 +313,6 @@ function onSubmit() {
orgChild2Id: getOrgIdByLevel(2), orgChild2Id: getOrgIdByLevel(2),
orgChild3Id: getOrgIdByLevel(3), orgChild3Id: getOrgIdByLevel(3),
orgChild4Id: getOrgIdByLevel(4), orgChild4Id: getOrgIdByLevel(4),
// orgRootId:
// props.actionType === "ADD"
// ? props.orgLevel === 0
// ? props.treeId
// : null
// : orgLevel.value === 0
// ? props.treeId
// : null, //Id
// orgChild1Id:
// props.actionType === "ADD"
// ? props.orgLevel === 1
// ? props.treeId
// : null
// : orgLevel.value === 1
// ? orgId.value
// : null,
// orgChild2Id:
// props.actionType === "ADD"
// ? props.orgLevel === 2
// ? props.treeId
// : null
// : orgLevel.value === 2
// ? orgId.value
// : null,
// orgChild3Id:
// props.actionType === "ADD"
// ? props.orgLevel === 3
// ? props.treeId
// : null
// : orgLevel.value === 3
// ? orgId.value
// : null,
// orgChild4Id:
// props.actionType === "ADD"
// ? props.orgLevel === 4
// ? props.treeId
// : null
// : orgLevel.value === 4
// ? orgId.value
// : null,
positions: positionsData, positions: positionsData,
}; };
@ -433,7 +426,7 @@ async function addPosition(data: RowDetailPositions) {
item.positionName == data.positionName && item.positionName == data.positionName &&
item.isSpecial == data.isSpecial item.isSpecial == data.isSpecial
); );
data.id = null; // Reset id to ensure a new entry
if (!isIdExist) { if (!isIdExist) {
rows.value = [...rows.value, data]; rows.value = [...rows.value, data];
} }
@ -496,6 +489,7 @@ async function clearFormPositionSelect() {
isPosition.value = false; isPosition.value = false;
// formData.isStaff = false; // formData.isStaff = false;
formData.positionSign = ""; formData.positionSign = "";
selectedPos.value = [];
} }
/** /**
@ -542,6 +536,18 @@ watch(
if (props.actionType !== "ADD" && props.rowId) { if (props.actionType !== "ADD" && props.rowId) {
fetchPosition(props.rowId); fetchPosition(props.rowId);
} }
visibleColumns.value = [
...(isPositionHolder.value ? ["checkbox"] : []),
"no",
"positionName",
"positionField",
"posTypeName",
"posLevelName",
"posExecutiveName",
"positionExecutiveField",
"positionArea",
];
} }
} }
); );
@ -651,13 +657,15 @@ watch(
ref="table" ref="table"
:columns="columns" :columns="columns"
:rows="rows" :rows="rows"
row-key="idcard" row-key="id"
flat flat
bordered bordered
:paging="true" :paging="true"
dense dense
class="custom-header-table" class="custom-header-table"
:visible-columns="visibleColumns" :visible-columns="visibleColumns"
selection="single"
v-model:selected="selectedPos"
> >
<template v-slot:header="props"> <template v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">
@ -687,12 +695,21 @@ watch(
<q-tooltip>ลบขอม</q-tooltip> <q-tooltip>ลบขอม</q-tooltip>
</q-btn> </q-btn>
</q-td> </q-td>
<q-td <q-td
v-for="col in props.cols" v-for="col in props.cols"
:key="col.name" :key="col.name"
:props="props" :props="props"
> >
<div v-if="col.name == 'no'"> <div v-if="col.name === 'checkbox'">
<q-checkbox
keep-color
color="primary"
dense
v-model="props.selected"
/>
</div>
<div v-else-if="col.name == 'no'">
{{ props.rowIndex + 1 }} {{ props.rowIndex + 1 }}
</div> </div>
<div v-else-if="col.name === 'posExecutiveName'"> <div v-else-if="col.name === 'posExecutiveName'">
@ -853,7 +870,9 @@ watch(
:paging="true" :paging="true"
dense dense
class="custom-header-table" class="custom-header-table"
:visible-columns="visibleColumns" :visible-columns="
visibleColumns.filter((col) => col !== 'checkbox')
"
> >
<template v-slot:header="props"> <template v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch, computed } from "vue"; import { ref, watch, computed, reactive } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import config from "@/app.config"; import config from "@/app.config";
@ -72,6 +72,15 @@ const modalSelectPerson = ref<boolean>(false); //เลือกคนครอ
const rowId = ref<string>(""); //id const rowId = ref<string>(""); //id
const actionType = ref<string>(""); // const actionType = ref<string>(""); //
const orgShortName = ref<string>(""); // const orgShortName = ref<string>(""); //
const isPositionHolder = ref<boolean>(false);
const positionHolderInfo = reactive({
posMaster: "",
position: "",
profileId: " ",
isSit: false,
});
/** ListMenu Table*/ /** ListMenu Table*/
const listMenu = ref<ListMenu[]>([ const listMenu = ref<ListMenu[]>([
{ {
@ -323,10 +332,22 @@ function onClickPosition(
id: string, id: string,
data: PosMaster2 = {} as PosMaster2 data: PosMaster2 = {} as PosMaster2
) { ) {
actionType.value = type;
orgShortName.value = type === "EDIT" ? data?.orgShortname : ""; orgShortName.value = type === "EDIT" ? data?.orgShortname : "";
rowId.value = id ? id : ""; rowId.value = id ? id : "";
actionType.value = type;
dialogPosition.value = !dialogPosition.value; dialogPosition.value = !dialogPosition.value;
if (type === "EDIT") {
isPositionHolder.value = data.positionIsSelected !== "ว่าง";
positionHolderInfo.posMaster = data.id || "";
positionHolderInfo.position =
data.positions.find((e) => e.positionIsSelected === true)?.id || "";
positionHolderInfo.profileId =
store.typeOrganizational === "current"
? data.current_holderId || ""
: data.next_holderId || "";
positionHolderInfo.isSit = data.isSit || false;
}
} }
/** /**
@ -1019,6 +1040,8 @@ watch(
v-model:reqMaster="reqMaster" v-model:reqMaster="reqMaster"
:fetchDataTable="props.fetchDataTable" :fetchDataTable="props.fetchDataTable"
:getSummary="getSummary" :getSummary="getSummary"
:is-position-holder="isPositionHolder"
:position-holder-info="positionHolderInfo"
/> />
<!-- ดลำด --> <!-- ดลำด -->

View file

@ -131,7 +131,7 @@ interface FormPositionSelectRef {
} }
interface RowDetailPositions { interface RowDetailPositions {
id: string; id: string | null;
positionId: string; positionId: string;
positionName: string; positionName: string;
positionField: string; positionField: string;

View file

@ -159,6 +159,9 @@ interface PosMaster2 {
profilePoslevel: string; profilePoslevel: string;
profilePostype: string; profilePostype: string;
isDirector?: boolean; isDirector?: boolean;
current_holderId?: string;
next_holderId?: string;
isSit?: boolean;
} }
interface HistoryPos { interface HistoryPos {