filter ตำแหน่งว่าง

This commit is contained in:
Kittapath 2023-07-14 11:36:59 +07:00
parent 5bfdd3cc2a
commit 6fab70b99b
2 changed files with 37 additions and 4 deletions

View file

@ -40,6 +40,7 @@ const config = ref<any>({
API_URI_PROFILE_SERVICE: `${window.location.protocol}//${window.location.host}/api/v1`,
API_CANDIDATE_URI: `${window.location.protocol}//${window.location.host}/api/v1`,
API_REPORT_URI: `${window.location.protocol}//${window.location.host}/api/v1`,
API_PLACEMENT_URI: `${window.location.protocol}//${window.location.host}/api/v1`,
API_URI_ORG_TREE:
"https://s3cluster.frappet.com/bma-ehr-fpt/organization/strueture/tree_20230707_115124.json",
MEET_URI: "meet.frappet.com",

View file

@ -17,6 +17,7 @@ const noData = ref<string>("ไม่พบข้อมูลผังโคร
const checkValidate = ref<boolean>(false);
const myFormPosition = ref<any>();
const selected = ref<string>("");
const selectedFile = ref<string>("");
// Set form field
let dataForm = reactive({
@ -33,18 +34,37 @@ let dataForm = reactive({
positionSalaryAmount: null,
});
onMounted(() => {
loadTreeData();
fetchplacementPosition();
onMounted(async () => {
await fetchPublishFile();
await loadTreeData();
await fetchplacementPosition();
});
const fetchPublishFile = async () => {
await http
.get(config.API.getPublishFileHistory)
.then((res) => {
let data = res.data.result;
selectedFile.value = data[0].fileName;
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
hideLoader();
});
};
// json
const treeData = ref<Array<any>>([]);
const loadTreeData = async () => {
await http
.get(config.API.orgTree)
.get(`${config.s3ClusterUrl}${selectedFile.value}`)
.then((res: any) => {
treeData.value = res.data;
// Filter objects with "name" null
const filteredData = res.data.filter(filterByPersonIdNull);
treeData.value = filteredData;
})
.catch((e: any) => {
messageError($q, e);
@ -53,6 +73,18 @@ const loadTreeData = async () => {
hideLoader();
});
};
function filterByPersonIdNull(obj: any) {
if (obj.name === null) {
return true;
}
if (obj.children && obj.children.length > 0) {
obj.children = obj.children.filter(filterByPersonIdNull);
return obj.children.length > 0;
}
return false;
}
// position
const placementPosition = ref<any>([]);
const fetchplacementPosition = async () => {