refactor: handle edit

This commit is contained in:
Net 2024-08-13 13:31:29 +07:00
parent f337760644
commit d21506f4d6
3 changed files with 20 additions and 4 deletions

View file

@ -31,6 +31,7 @@ const addrOptions = reactive<{
subDistrictOps: [], subDistrictOps: [],
}); });
const currentIndex = defineModel<number>('currentIndex');
const employeeCheckup = defineModel<EmployeeCheckupCreate[]>('employeeCheckup'); const employeeCheckup = defineModel<EmployeeCheckupCreate[]>('employeeCheckup');
const checkupTypeOption = defineModel<{ label: string; value: string }[]>( const checkupTypeOption = defineModel<{ label: string; value: string }[]>(
'checkupTypeOption', 'checkupTypeOption',
@ -164,6 +165,7 @@ const insuranceCompanyFilter = selectFilterOptionRefMod(
class="q-ml-sm" class="q-ml-sm"
type="button" type="button"
@click="addCheckup" @click="addCheckup"
:disabled="!(currentIndex === -1)"
/> />
</div> </div>
@ -188,12 +190,14 @@ const insuranceCompanyFilter = selectFilterOptionRefMod(
icon-only icon-only
@click="$emit('undo', index)" @click="$emit('undo', index)"
type="button" type="button"
:disabled="!(currentIndex === -1) && !(currentIndex === index)"
/> />
<SaveButton <SaveButton
icon-only icon-only
id="btn-info-health-save" id="btn-info-health-save"
v-if="!readonly && !checkup.statusSave" v-if="!readonly && !checkup.statusSave"
@click="$emit('save', index)" @click="$emit('save', index)"
:disabled="!(currentIndex === -1) && !(currentIndex === index)"
/> />
<EditButton <EditButton
icon-only icon-only
@ -201,6 +205,7 @@ const insuranceCompanyFilter = selectFilterOptionRefMod(
v-if="!readonly && checkup.statusSave" v-if="!readonly && checkup.statusSave"
@click="$emit('edit', index)" @click="$emit('edit', index)"
type="button" type="button"
:disabled="!(currentIndex === -1) && !(currentIndex === index)"
/> />
<DeleteButton <DeleteButton
icon-only icon-only
@ -208,6 +213,7 @@ const insuranceCompanyFilter = selectFilterOptionRefMod(
v-if="!readonly && !!checkup.id && checkup.statusSave" v-if="!readonly && !!checkup.id && checkup.statusSave"
@click="$emit('delete', index)" @click="$emit('delete', index)"
type="button" type="button"
:disabled="!(currentIndex === -1) && !(currentIndex === index)"
/> />
</div> </div>
</span> </span>

View file

@ -2527,6 +2527,7 @@ watch(
await fetchListEmployee(); await fetchListEmployee();
employeeFormState.isEmployeeEdit = false; employeeFormState.isEmployeeEdit = false;
employeeFormState.currentIndex = -1;
} }
" "
:show=" :show="
@ -2734,9 +2735,12 @@ watch(
prefix-id="form-employee" prefix-id="form-employee"
dense dense
outlined outlined
v-model:employeeCheckup="currentFromDataEmployee.employeeCheckup" v-model:current-index="employeeFormState.currentIndex"
v-model:checkupTypeOption="optionStore.globalOption.insurancePlace" v-model:employee-checkup="currentFromDataEmployee.employeeCheckup"
v-model:medicalBenefitOption=" v-model:checkup-type-option="
optionStore.globalOption.insurancePlace
"
v-model:medical-benefit-option="
optionStore.globalOption.typeInsurance optionStore.globalOption.typeInsurance
" "
v-model:insuranceCompanyOption=" v-model:insuranceCompanyOption="
@ -2753,6 +2757,7 @@ watch(
if ( if (
currentFromDataEmployee.employeeCheckup?.[index].statusSave currentFromDataEmployee.employeeCheckup?.[index].statusSave
) { ) {
employeeFormState.currentIndex = index;
currentFromDataEmployee.employeeCheckup[index].statusSave = currentFromDataEmployee.employeeCheckup[index].statusSave =
false; false;
} }
@ -2764,6 +2769,7 @@ watch(
currentFromDataEmployee.employeeCheckup?.[index] currentFromDataEmployee.employeeCheckup?.[index]
.statusSave === false .statusSave === false
) { ) {
employeeFormState.currentIndex = -1;
currentFromDataEmployee.employeeCheckup[index].statusSave = currentFromDataEmployee.employeeCheckup[index].statusSave =
true; true;
employeeFormStore.resetFormDataEmployee(); employeeFormStore.resetFormDataEmployee();
@ -2783,6 +2789,7 @@ watch(
prefix-id="form-employee" prefix-id="form-employee"
dense dense
outlined outlined
v-model:current-index="employeeFormState.currentIndex"
v-model:employee-work="currentFromDataEmployee.employeeWork" v-model:employee-work="currentFromDataEmployee.employeeWork"
v-model:position-name-option="optionStore.globalOption.position" v-model:position-name-option="optionStore.globalOption.position"
v-model:job-type-option="optionStore.globalOption.businessType" v-model:job-type-option="optionStore.globalOption.businessType"
@ -2804,6 +2811,7 @@ watch(
currentFromDataEmployee.employeeWork?.[index].statusSave === currentFromDataEmployee.employeeWork?.[index].statusSave ===
false false
) { ) {
employeeFormState.currentIndex = -1;
currentFromDataEmployee.employeeWork[index].statusSave = true; currentFromDataEmployee.employeeWork[index].statusSave = true;
} }
} }
@ -2811,6 +2819,7 @@ watch(
@edit=" @edit="
(index) => { (index) => {
if (currentFromDataEmployee.employeeWork?.[index].statusSave) { if (currentFromDataEmployee.employeeWork?.[index].statusSave) {
employeeFormState.currentIndex = index;
currentFromDataEmployee.employeeWork[index].statusSave = currentFromDataEmployee.employeeWork[index].statusSave =
false; false;
} }

View file

@ -392,6 +392,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
currentTab: string; currentTab: string;
dialogModal: boolean; dialogModal: boolean;
drawerModal: boolean; drawerModal: boolean;
currentEmployeeCode: string; currentEmployeeCode: string;
currentEmployee: Employee | null; currentEmployee: Employee | null;
currentIndex: number; currentIndex: number;
@ -422,7 +423,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
} }
| undefined; | undefined;
}>({ }>({
currentIndex: 0, currentIndex: -1,
statusSavePersonal: false, statusSavePersonal: false,
drawerModal: false, drawerModal: false,
imageDialog: false, imageDialog: false,