updated
This commit is contained in:
parent
764078488c
commit
c7ea4e0e5b
2 changed files with 72 additions and 55 deletions
|
|
@ -29,6 +29,7 @@ const props = defineProps({
|
||||||
fetchDataTree: {
|
fetchDataTree: {
|
||||||
type: Function,
|
type: Function,
|
||||||
require: true,
|
require: true,
|
||||||
|
default: () => "",
|
||||||
},
|
},
|
||||||
dataNode: {
|
dataNode: {
|
||||||
type: Object,
|
type: Object,
|
||||||
|
|
@ -106,7 +107,6 @@ function validateForm() {
|
||||||
|
|
||||||
/** ฟังชั่น บันทึก */
|
/** ฟังชั่น บันทึก */
|
||||||
function onSubmit() {
|
function onSubmit() {
|
||||||
console.log(level.value);
|
|
||||||
dialogConfirm($q, async () => {
|
dialogConfirm($q, async () => {
|
||||||
// showLoader();
|
// showLoader();
|
||||||
const type = store.checkLevel(level.value);
|
const type = store.checkLevel(level.value);
|
||||||
|
|
@ -142,15 +142,13 @@ function onSubmit() {
|
||||||
await http
|
await http
|
||||||
.post(config.API.createOrgLevel(type.toLocaleLowerCase()), body)
|
.post(config.API.createOrgLevel(type.toLocaleLowerCase()), body)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res);
|
|
||||||
success($q, "บันทึกข้อมูลสำเร็จ");
|
success($q, "บันทึกข้อมูลสำเร็จ");
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
|
||||||
messageError($q, err);
|
messageError($q, err);
|
||||||
})
|
})
|
||||||
.finally(async () => {
|
.finally(() => {
|
||||||
await props.fetchDataTree?.();
|
props.fetchDataTree();
|
||||||
closeClear();
|
closeClear();
|
||||||
hideLoader();
|
hideLoader();
|
||||||
});
|
});
|
||||||
|
|
@ -166,7 +164,12 @@ function onSubmit() {
|
||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
props.edit?.(props.dataNode?.orgTreeId, type, body, props.dataNode?.orgRootCode);
|
props.edit?.(
|
||||||
|
props.dataNode?.orgTreeId,
|
||||||
|
type,
|
||||||
|
body,
|
||||||
|
props.dataNode?.orgRootCode
|
||||||
|
);
|
||||||
success($q, "บันทึกข้อมูลสำเร็จ");
|
success($q, "บันทึกข้อมูลสำเร็จ");
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
@ -175,8 +178,8 @@ function onSubmit() {
|
||||||
})
|
})
|
||||||
.finally(async () => {
|
.finally(async () => {
|
||||||
// await props.fetchDataTree?.();
|
// await props.fetchDataTree?.();
|
||||||
closeClear();
|
closeClear();
|
||||||
hideLoader();
|
hideLoader();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -84,8 +84,8 @@ const listAdd = ref<ListMenu[]>([
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const nodeTEST = defineModel<OrgTree[]>("nodeTree", { default: [] });
|
const nodeTEST = defineModel<OrgTree[]>("nodeTree", { default: [] });
|
||||||
const nodeId = defineModel<string>("nodeId", { require: true });
|
const nodeId = defineModel<string>("nodeId", { required: true });
|
||||||
const isLoad = defineModel<boolean>("isLoad", { require: true });
|
const isLoad = defineModel<boolean>("isLoad", { required: true });
|
||||||
const filter = ref<string>("");
|
const filter = ref<string>("");
|
||||||
|
|
||||||
const nodes = ref<Array<OrgTree>>([]);
|
const nodes = ref<Array<OrgTree>>([]);
|
||||||
|
|
@ -109,39 +109,15 @@ const updateSelected = (id: string, level: number) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const breakLoop = ref<boolean>(false);
|
const breakLoop = ref<boolean>(false);
|
||||||
async function edit(id: string, type: string, data: any) {
|
async function edit(id: string, type: string, data: any, orgRootCode: string) {
|
||||||
const data2 = {
|
|
||||||
orgName: data[`org${type}Name`],
|
|
||||||
orgShortName: data[`org${type}ShortName`],
|
|
||||||
orgCode: data[`org${type}Code`],
|
|
||||||
orgPhoneEx: data[`org${type}PhoneEx`],
|
|
||||||
orgPhoneIn: data[`org${type}PhoneIn`],
|
|
||||||
orgFax: data[`org${type}Fax`],
|
|
||||||
orgLevel: data[`org${type}Rank`],
|
|
||||||
};
|
|
||||||
|
|
||||||
breakLoop.value = false;
|
breakLoop.value = false;
|
||||||
|
|
||||||
// Usage
|
|
||||||
const targetNodeId = id;
|
const targetNodeId = id;
|
||||||
const replacementNode = {
|
|
||||||
orgTreeName: data2.orgName,
|
|
||||||
orgTreeShortName: data2.orgShortName,
|
|
||||||
orgCode: data2.orgCode,
|
|
||||||
orgTreePhoneEx: data2.orgPhoneEx,
|
|
||||||
orgTreePhoneIn: data2.orgPhoneIn,
|
|
||||||
orgTreeFax: data2.orgFax,
|
|
||||||
orgTreeRank: data2.orgLevel,
|
|
||||||
};
|
|
||||||
|
|
||||||
for (let index = 0; index < nodes.value.length; index++) {
|
for (let index = 0; index < nodes.value.length; index++) {
|
||||||
const element = nodes.value[index];
|
const element = nodes.value[index];
|
||||||
if (type !== "edit") {
|
|
||||||
searchAndReplace(element, targetNodeId, replacementNode);
|
|
||||||
} else deleteNode(element, targetNodeId);
|
|
||||||
|
|
||||||
console.log("index===>", index);
|
searchAndReplace(element, targetNodeId, data, type, orgRootCode);
|
||||||
console.log("breakLoop===>", breakLoop.value);
|
|
||||||
if (breakLoop.value) break;
|
if (breakLoop.value) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -149,32 +125,63 @@ async function edit(id: string, type: string, data: any) {
|
||||||
function searchAndReplace(
|
function searchAndReplace(
|
||||||
treeNode: any,
|
treeNode: any,
|
||||||
organizationId: string,
|
organizationId: string,
|
||||||
replacementObject: any
|
data: any,
|
||||||
|
type: string,
|
||||||
|
orgRootCode: string
|
||||||
) {
|
) {
|
||||||
if (treeNode.orgTreeId === organizationId) {
|
if (treeNode.orgTreeId === organizationId) {
|
||||||
Object.assign(treeNode, replacementObject);
|
let newData = {
|
||||||
|
...treeNode,
|
||||||
|
orgTreeName: data[`org${type}Name`],
|
||||||
|
orgTreeShortName: data[`org${type}ShortName`],
|
||||||
|
orgCode:
|
||||||
|
data.orgRootRank == "DEPARTMENT"
|
||||||
|
? data[`org${type}Code`] + "00"
|
||||||
|
: orgRootCode + data[`org${type}Code`],
|
||||||
|
orgTreeCode: data[`org${type}Code`],
|
||||||
|
orgTreePhoneEx: data[`org${type}PhoneEx`],
|
||||||
|
orgTreePhoneIn: data[`org${type}PhoneIn`],
|
||||||
|
orgTreeFax: data[`org${type}Fax`],
|
||||||
|
orgTreeRank: data[`org${type}Rank`],
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(treeNode, newData);
|
||||||
breakLoop.value = true;
|
breakLoop.value = true;
|
||||||
} else if (treeNode.children) {
|
} else if (treeNode.children) {
|
||||||
for (const child of treeNode.children) {
|
for (const child of treeNode.children) {
|
||||||
searchAndReplace(child, organizationId, replacementObject);
|
searchAndReplace(child, organizationId, data, type, orgRootCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteNode(treeNode: any, organizationId: any): boolean {
|
async function deleteUpdate(rootId: string, treeId: string) {
|
||||||
// console.log("tttttttttttttt", treeNode.orgTreeId, organizationId);
|
breakLoop.value = false;
|
||||||
|
if (rootId) {
|
||||||
|
for (let index = 0; index < nodes.value.length; index++) {
|
||||||
|
const element = nodes.value[index];
|
||||||
|
deleteNode(element, rootId, treeId);
|
||||||
|
|
||||||
if (treeNode.orgTreeId === organizationId) {
|
if (breakLoop.value) break;
|
||||||
treeNode.children = [];
|
}
|
||||||
|
} else {
|
||||||
|
console.log("rootId===>", rootId);
|
||||||
|
console.log("treeId===>", treeId);
|
||||||
|
nodes.value = nodes.value.filter((x: any) => x.orgTreeId != treeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteNode(treeNode: any, rootId: string, treeId: string): boolean {
|
||||||
|
if (treeNode.orgTreeId === rootId) {
|
||||||
|
let newData = {
|
||||||
|
...treeNode,
|
||||||
|
children: [],
|
||||||
|
};
|
||||||
|
Object.assign(treeNode, newData);
|
||||||
|
|
||||||
breakLoop.value = true;
|
breakLoop.value = true;
|
||||||
} else if (treeNode.children) {
|
} else if (treeNode.children) {
|
||||||
for (let i = 0; i < treeNode.children.length; i++) {
|
for (const child of treeNode.children) {
|
||||||
const child = treeNode.children[i];
|
deleteNode(child, rootId, treeId);
|
||||||
if (deleteNode(child, organizationId)) {
|
|
||||||
treeNode.children.splice(i, 1);
|
|
||||||
i--; // ลดค่า i เพราะที่ลบข้อมูล
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,17 +217,16 @@ async function onClickEdit(node: OrgTree) {
|
||||||
dataNode.value = node;
|
dataNode.value = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onClickDel(type: number, id: string) {
|
async function onClickDel(type: number, id: string, rootId: string) {
|
||||||
const level = store.checkLevel(type);
|
const level = store.checkLevel(type);
|
||||||
|
|
||||||
dialogRemove($q, async () => {
|
dialogRemove($q, async () => {
|
||||||
// edit(id, "edit", {});
|
|
||||||
showLoader();
|
showLoader();
|
||||||
await http
|
await http
|
||||||
.delete(config.API.orgLevelByid(level.toLocaleLowerCase(), id))
|
.delete(config.API.orgLevelByid(level.toLocaleLowerCase(), id))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
success($q, "ลบข้อมูลสำเร็จ");
|
success($q, "ลบข้อมูลสำเร็จ");
|
||||||
// edit(id, "edit", {});
|
deleteUpdate(rootId, id);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
messageError($q, err);
|
messageError($q, err);
|
||||||
|
|
@ -390,7 +396,11 @@ onMounted(async () => {});
|
||||||
: item.type === 'DETAIL'
|
: item.type === 'DETAIL'
|
||||||
? onClickDetail(prop.node.orgTreeId, prop.node.orgLevel)
|
? onClickDetail(prop.node.orgTreeId, prop.node.orgLevel)
|
||||||
: item.type === 'DEL'
|
: item.type === 'DEL'
|
||||||
? onClickDel(prop.node.orgLevel, prop.node.orgTreeId)
|
? onClickDel(
|
||||||
|
prop.node.orgLevel,
|
||||||
|
prop.node.orgTreeId,
|
||||||
|
prop.node.orgRootId
|
||||||
|
)
|
||||||
: item.type === 'SORT'
|
: item.type === 'SORT'
|
||||||
? onClickSort(prop.node.orgRootId)
|
? onClickSort(prop.node.orgRootId)
|
||||||
: item.type === 'HISTORY'
|
: item.type === 'HISTORY'
|
||||||
|
|
@ -462,7 +472,11 @@ onMounted(async () => {});
|
||||||
: item.type === 'DETAIL'
|
: item.type === 'DETAIL'
|
||||||
? onClickDetail(prop.node.orgTreeId, prop.node.orgLevel)
|
? onClickDetail(prop.node.orgTreeId, prop.node.orgLevel)
|
||||||
: item.type === 'DEL'
|
: item.type === 'DEL'
|
||||||
? onClickDel(prop.node.orgLevel, prop.node.orgTreeId)
|
? onClickDel(
|
||||||
|
prop.node.orgLevel,
|
||||||
|
prop.node.orgTreeId,
|
||||||
|
prop.node.orgRootId
|
||||||
|
)
|
||||||
: null
|
: null
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue