diff --git a/src/modules/02_organization/components/DialogFormPosition.vue b/src/modules/02_organization/components/DialogFormPosition.vue index 091e22d13..bb82d762d 100644 --- a/src/modules/02_organization/components/DialogFormPosition.vue +++ b/src/modules/02_organization/components/DialogFormPosition.vue @@ -44,6 +44,10 @@ const { * props */ const reqMaster = defineModel("reqMaster", { required: true }); // qurey +const isPositionHolder = defineModel("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(false); // อ่านได้อย่างเดียว @@ -104,9 +109,19 @@ const formPositionSelect = reactive({ }); //Table +const selectedPos = ref([]); const rows = ref([]); //ข้อมูลรายการอัตรากำลัง const rowsPositionSelect = ref([]); //ข้อมูลรายากรตำแหน่ง const columns = ref([ + { + 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" >