feat: add employee under employer (#35)

* refactor: btn add in table

* refactor: Emits addEmployee

* fix: visa can is null

* refactor: update data

* fix: number not update

---------

Co-authored-by: Thanaphon Frappet <thanaphon@frappet.com>
This commit is contained in:
Methapon Metanipat 2024-10-31 17:43:56 +07:00 committed by GitHub
parent a9c9467643
commit 05c1c07384
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 61 additions and 20 deletions

View file

@ -70,6 +70,8 @@ const currentPageBranch = ref<number>(1);
const maxPageBranch = ref<number>(1);
const pageSizeBranch = ref<number>(30);
const statusEmployeeCreate = defineModel<boolean>('statusEmployeeCreate');
const prop = withDefaults(
defineProps<{
index?: string | number;
@ -84,12 +86,13 @@ const prop = withDefaults(
color: 'green',
},
);
const currentBranchEmployee = ref<string>('');
const listEmployee = ref<Employee[]>([]);
const customerId = defineModel<string>('customerId', { required: true });
defineEmits<{
(e: 'addEmployee', currentBranch: CustomerBranch): void;
(e: 'back'): void;
(e: 'viewDetail', branch: CustomerBranch, index: number): void;
(e: 'dialog'): void;
@ -210,6 +213,14 @@ function openEmployerBranchForm(formType: 'create' | 'edit' | 'info') {
customerBranchFormState.value.dialogModal = true;
}
async function fetchEmployee(branchId: string) {
const res = await fetchBranchEmployee(branchId);
if (res) {
listEmployee.value = res.data.result;
}
}
onMounted(async () => {
await fetchList();
});
@ -217,6 +228,19 @@ onMounted(async () => {
watch([customerId, inputSearch, currentStatus], async () => {
await fetchList();
});
watch(
() => statusEmployeeCreate.value,
async () => {
if (statusEmployeeCreate.value) {
await fetchEmployee(currentBranchEmployee.value);
const br = branch.value?.find(
(v) => v.id === currentBranchEmployee.value,
);
if (br) br._count.employee += 1;
}
},
);
</script>
<template>
@ -487,20 +511,17 @@ watch([customerId, inputSearch, currentStatus], async () => {
flat
@click.stop="
async () => {
const res = await fetchBranchEmployee(props.row.id);
currentBranchEmployee = props.row.id;
await fetchEmployee(currentBranchEmployee);
if (res) {
listEmployee = res.data.result;
currentBtnOpen.map((v, i) => {
if (i !== props.rowIndex) {
currentBtnOpen[i] = false;
}
});
currentBtnOpen.map((v, i) => {
if (i !== props.rowIndex) {
currentBtnOpen[i] = false;
}
});
currentBtnOpen[props.rowIndex] =
!currentBtnOpen[props.rowIndex];
}
currentBtnOpen[props.rowIndex] =
!currentBtnOpen[props.rowIndex];
}
"
>
@ -537,6 +558,7 @@ watch([customerId, inputSearch, currentStatus], async () => {
<q-td colspan="100%" style="padding: 16px">
<div class="text-center">
<TableEmpoloyee
add-button
in-table
:list-employee="listEmployee"
:columns-employee="columnsEmployee"
@ -550,6 +572,12 @@ watch([customerId, inputSearch, currentStatus], async () => {
'formDialogEmployeeNRCNo',
'action',
]"
@add="
() => {
statusEmployeeCreate = false;
$emit('addEmployee', props.row);
}
"
@history="(item) => {}"
@view="
(item) => {
@ -627,7 +655,6 @@ watch([customerId, inputSearch, currentStatus], async () => {
"
@submit="
async () => {
console.log('asasd');
const res = await customerBranchFormStore.submitForm();
if (res) {