ปรับ code Popup เลือกหน่วยงานที่รับบรรจุ

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-02-21 10:16:21 +07:00
parent 036820ca80
commit 4c0dd2af29
2 changed files with 45 additions and 40 deletions

View file

@ -36,7 +36,6 @@ const {
/**props*/
const modal = defineModel<boolean>("modal", { required: true });
const props = defineProps({
dataRow: {
type: Object,
@ -57,16 +56,13 @@ const nodes = ref<Array<TreeMain>>([]);
const lazy = ref(nodes);
const expanded = ref<string[]>([]);
/** Position*/
const positionNo = ref<DataPositionNo[]>();
const positionId = ref<string>("");
const seletcId = ref<string>("");
const selectedPos = ref<any[]>([]);
const datePos = ref<Date>(new Date());
function closePopup() {
modal.value = !modal.value;
}
/** function เรียกข้อมูลโครงสร้าง แบบปัจุบันและ แบบร่าง*/
async function fetchOrganizationActive() {
showLoader();
@ -113,7 +109,6 @@ async function fetchDataTree(id: string) {
* @param data อม Tree
*/
function updateSelected(data: TreeMain) {
// console.log(props?.dataRow?.nodeId === data.orgTreeId);
if (props?.dataRow?.nodeId === data.orgTreeId) {
positionId.value = props?.dataRow?.posmasterId;
seletcId.value = props?.dataRow?.positionId;
@ -150,8 +145,8 @@ async function fetchDataTable(id: string, level: number = 0) {
if (p.length !== 0) {
const a = p.find((el: Positions) => el.positionIsSelected === true);
const { id, ...rest } = a ? a : p[0];
const test = { ...e, ...rest };
dataMain.push(test);
const data = { ...e, ...rest };
dataMain.push(data);
}
});
positionNo.value = store.fetchPosNo(dataMain);
@ -166,6 +161,11 @@ async function fetchDataTable(id: string, level: number = 0) {
});
}
/**
* function fetch อม expanded tree
* @param level levelTree
* @param id treeId
*/
async function fetchPosFind(level: number, id: string) {
showLoader();
const body = {
@ -176,8 +176,6 @@ async function fetchPosFind(level: number, id: string) {
.post(config.API.orgPosFind, body)
.then((res) => {
const data = res.data.result;
console.log(data);
expanded.value = data;
nodeId.value = id;
positionId.value = props?.dataRow?.posmasterId;
@ -191,6 +189,7 @@ async function fetchPosFind(level: number, id: string) {
});
}
/** function บันทึกข้อมูลตำแหน่ง*/
function onClickSubmit() {
if (selectedPos.value.length === 0) {
dialogMessageNotify($q, "กรุณาเลือกตำแหน่ง");
@ -223,26 +222,29 @@ function onClickSubmit() {
}
}
/** function closePopup*/
function closePopup() {
modal.value = !modal.value;
clearData();
}
/** function clearData*/
function clearData() {
nodeId.value = "";
expanded.value = [];
}
/** callback function เมื่อมีการเปิด popup*/
watch(
() => modal.value,
async () => {
if (modal.value) {
showLoader();
await fetchOrganizationActive();
console.log(props.dataRow);
if (props?.dataRow?.node !== null && props?.dataRow?.nodeId !== null) {
await fetchPosFind(props?.dataRow?.node, props?.dataRow?.nodeId);
} else {
expanded.value = [];
}
} else {
clearData();
}
}
);