fix bug แก้ไขอัตรากำลัง

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-08-15 13:10:36 +07:00
parent ecb8366e4d
commit da1bd5d937
2 changed files with 123 additions and 52 deletions

View file

@ -54,6 +54,7 @@ const props = defineProps({
fetchDataTable: Function,
getSummary: Function,
shortName: { type: String, required: true },
orgShortName: { type: String, required: true },
dataTree: { type: Object, default: () => [] },
});
@ -61,6 +62,8 @@ const isReadonly = ref<boolean>(false); // อ่านได้อย่าง
const isEdit = ref<boolean>(false); //
const modalAdd = ref<boolean>(false); //
const isPosition = ref<boolean>(false); //
const orgLevel = ref<number>(0);
const orgId = ref<string>(""); //Id
const dataCopy = ref<RowDetailPositions>(); //
const search = ref<string>(""); //
@ -78,7 +81,7 @@ const optionFilter = ref<DataOption[]>([
//
const formData = reactive<FormDataPosition>({
shortName: props.shortName,
shortName: "",
prefixNo: "",
positionNo: "",
suffixNo: "",
@ -224,6 +227,8 @@ async function fetchPosition(id: string) {
formData.suffixNo = data.posMasterNoSuffix;
formData.reason = data.reason;
formData.isDirector = data.isDirector;
orgLevel.value = data.orgLevel;
orgId.value = data.orgId; // Id
// formData.isStaff = data.isStaff;
formData.positionSign = data.positionSign;
rows.value = data.positions;
@ -260,6 +265,7 @@ function onSubmit() {
isSpecial: e.isSpecial,
positionIsSelected: e.positionIsSelected,
}));
const body = {
posMasterNoPrefix: formData.prefixNo, //*Prefix Optional (/)
posMasterNo: Number(formData.positionNo), //*
@ -269,56 +275,109 @@ function onSubmit() {
// isStaff: formData.isStaff ? formData.isStaff : false,
isStaff: false,
positionSign: formData.positionSign,
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,
orgRootId: getOrgIdByLevel(0), // Id
orgChild1Id: getOrgIdByLevel(1),
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,
};
showLoader();
props.actionType === "ADD" || props.actionType === "COPY"
? await http
.post(config.API.orgPosMaster, body)
.then(async () => {
await props.fetchDataTable?.(
reqMaster.value.id,
reqMaster.value.type,
false
);
await props.getSummary?.();
await success($q, "เพิ่มข้อมูลสำเร็จ");
close();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
})
: props.rowId &&
(await http
.put(config.API.orgPosMasterById(props.rowId), body)
.then(async () => {
await props.fetchDataTable?.(
reqMaster.value.id,
reqMaster.value.type,
false
);
await success($q, "แก้ไขข้อมูลสำเร็จ");
close();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
}));
try {
const isAddOrCopy =
props.actionType === "ADD" || props.actionType === "COPY";
if (isAddOrCopy) {
await http.post(config.API.orgPosMaster, body);
await Promise.all([
props.fetchDataTable?.(
reqMaster.value.id,
reqMaster.value.type,
false
),
props.getSummary?.(),
]);
await success($q, "เพิ่มข้อมูลสำเร็จ");
} else if (props.rowId) {
await http.put(config.API.orgPosMasterById(props.rowId), body);
await props.fetchDataTable?.(
reqMaster.value.id,
reqMaster.value.type,
false
);
await success($q, "แก้ไขข้อมูลสำเร็จ");
}
close();
} catch (error) {
messageError($q, error);
} finally {
hideLoader();
}
});
}
}
/**
* งกนสราง organization ID สำหรบแตละ level
* @param level ระดบของ organization (0-4)
* @returns ID เหมาะสมสำหร level
*/
function getOrgIdByLevel(level: number): string | null {
const isAdd = props.actionType === "ADD";
if (isAdd) {
return props.orgLevel === level ? props.treeId ?? null : null;
} else {
return orgLevel.value === level
? level === 0
? props.treeId ?? null
: orgId.value
: null;
}
}
/**
* งกนตนหาตำแหนงทองการเพ
*/
@ -441,7 +500,6 @@ async function clearFormPositionSelect() {
/**
* งก popup
*
* และกำหนดตวแปรทงหมดใหเปนค Default
*/
function close() {
@ -472,14 +530,15 @@ function inputEdit(val: boolean) {
}
/**
* การเปลยยนแปลง props.modal
*
* การเปลยนแปลง props.modal
* เม props.modal เป true
*/
watch(
() => props.modal,
async () => {
if (props.modal === true) {
formData.shortName =
props.actionType === "ADD" ? props.shortName : props.orgShortName;
if (props.actionType !== "ADD" && props.rowId) {
fetchPosition(props.rowId);
}
@ -491,9 +550,8 @@ watch(
() => formData.isDirector,
(newData, oldData) => {
if (newData === true) {
formData.positionSign = !formData.positionSign
? ''
? ""
: formData.positionSign;
} else {
formData.positionSign = "";

View file

@ -71,6 +71,8 @@ const personalId = ref<string>(""); //ตัวแปร id ข้อมูล
const modalSelectPerson = ref<boolean>(false); //
const rowId = ref<string>(""); //id
const actionType = ref<string>(""); //
const orgShortName = ref<string>(""); //
const orgRootIdMain = ref<string>(""); //Id
/** ListMenu Table*/
const listMenu = ref<ListMenu[]>([
{
@ -285,7 +287,12 @@ const dialogPosition = ref<boolean>(false); //ตำแหน่ง
* @param type ประเภท
* @param id id
*/
function onClickPosition(type: string, id: string) {
function onClickPosition(
type: string,
id: string,
data: PosMaster2 = {} as PosMaster2
) {
orgShortName.value = type === "EDIT" ? data?.orgShortname : "";
rowId.value = id ? id : "";
actionType.value = type;
dialogPosition.value = !dialogPosition.value;
@ -296,7 +303,12 @@ function onClickPosition(type: string, id: string) {
* @param type ประเภทการกระทำ
* @param id id องการกระทำ
*/
function onClickCopyPosition(type: string, id: string) {
function onClickCopyPosition(
type: string,
id: string,
data: PosMaster2 = {} as PosMaster2
) {
orgShortName.value = data?.orgShortname;
rowId.value = id ? id : "";
actionType.value = type;
dialogPosition.value = !dialogPosition.value;
@ -723,7 +735,7 @@ watch(
v-close-popup
@click="
item.type === 'EDIT'
? onClickPosition('EDIT', props.row.id)
? onClickPosition('EDIT', props.row.id, props.row)
: item.type === 'DEL'
? onClickDelete(props.row.id)
: item.type === 'MOVE'
@ -733,7 +745,7 @@ watch(
: item.type === 'INHERIT'
? onClickInherit(props.row.id)
: item.type === 'COPY'
? onClickCopyPosition('COPY', props.row.id)
? onClickCopyPosition('COPY', props.row.id, props.row)
: item.type === 'CONDITION'
? onClickCodition(props.row)
: null
@ -962,6 +974,7 @@ watch(
:modal="dialogPosition"
:data-tree="mainTree"
:shortName="shortName"
:orgShortName="orgShortName"
:close="onClickPosition"
:orgLevel="orgLevel"
:treeId="treeId"