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

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, watch, computed } from "vue";
import { ref, watch, computed, reactive } from "vue";
import { useQuasar } from "quasar";
import config from "@/app.config";
@ -72,6 +72,15 @@ const modalSelectPerson = ref<boolean>(false); //เลือกคนครอ
const rowId = ref<string>(""); //id
const actionType = ref<string>(""); //
const orgShortName = ref<string>(""); //
const isPositionHolder = ref<boolean>(false);
const positionHolderInfo = reactive({
posMaster: "",
position: "",
profileId: " ",
isSit: false,
});
/** ListMenu Table*/
const listMenu = ref<ListMenu[]>([
{
@ -323,10 +332,22 @@ function onClickPosition(
id: string,
data: PosMaster2 = {} as PosMaster2
) {
actionType.value = type;
orgShortName.value = type === "EDIT" ? data?.orgShortname : "";
rowId.value = id ? id : "";
actionType.value = type;
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"
:fetchDataTable="props.fetchDataTable"
:getSummary="getSummary"
:is-position-holder="isPositionHolder"
:position-holder-info="positionHolderInfo"
/>
<!-- ดลำด -->

View file

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

View file

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