feat: incomplete form warning (employee)

This commit is contained in:
puriphatt 2024-06-13 03:50:14 +00:00
parent 34cb58fbfd
commit e284a7bd4c

View file

@ -390,6 +390,19 @@ async function openDialogInputForm(
if (selectorLabel.value === 'EMPLOYEE') {
if (!id) return;
await assignFormDataEmployee(id);
const code = currentEmployee.value?.code.split('-')[0];
const result = await fetchListBranch({
includeCustomer: true,
query: code,
pageSize: 30,
});
if (result) {
employeeStore.ownerOption = result.result.map((i) => ({
label: i.code,
value: i.id,
}));
}
dialogEmployee.value = true;
}
}
@ -587,17 +600,20 @@ async function onSubmit() {
}
if (selectorLabel.value === 'EMPLOYEE') {
await employeeStore.create({
...formDataEmployee.value,
image: profileSubmit.value ? profileFile.value ?? null : null,
});
const resultList = await employeeStore.fetchList();
if (resultList) listEmployee.value = resultList.result;
const isOk = await checkEmployeeForm();
if (isOk) {
await employeeStore.create({
...formDataEmployee.value,
image: profileSubmit.value ? profileFile.value ?? null : null,
});
const resultList = await employeeStore.fetchList();
if (resultList) listEmployee.value = resultList.result;
const resultStatsEmployee = await employeeStore.getStatsEmployee();
if (resultStatsEmployee) statsEmployee.value = resultStatsEmployee;
const resultStatsEmployee = await employeeStore.getStatsEmployee();
if (resultStatsEmployee) statsEmployee.value = resultStatsEmployee;
clearFormEmployee();
clearFormEmployee();
}
}
}
@ -670,17 +686,20 @@ async function onSubmitEdit(id: string) {
}
if (selectorLabel.value === 'EMPLOYEE') {
if (!formDataEmployee.value) return;
const isOk = await checkEmployeeForm();
if (isOk) {
if (!formDataEmployee.value) return;
await employeeStore.editById(id, {
...formDataEmployee.value,
image: profileSubmit.value ? profileFile.value ?? null : null,
});
await employeeStore.editById(id, {
...formDataEmployee.value,
image: profileSubmit.value ? profileFile.value ?? null : null,
});
const resultList = await employeeStore.fetchList();
if (resultList) listEmployee.value = resultList.result;
const resultList = await employeeStore.fetchList();
if (resultList) listEmployee.value = resultList.result;
clearFormEmployee();
clearFormEmployee();
}
}
}
@ -893,6 +912,39 @@ async function assignFormDataEmployee(id: string) {
}
}
async function checkEmployeeForm() {
const formData = formDataEmployee.value;
let forget = false;
for (const [key, val] of Object.entries(formData)) {
if (key === 'workerStatus') continue;
if (key === 'image') continue;
if (val === '' || val === null) {
forget = true;
}
}
if (forget) {
return await new Promise((resolve) => {
dialog({
color: 'warning',
icon: 'mdi-alert',
title: t('warning'),
actionText: t('ok'),
persistent: true,
message: t('warningForgetInput'),
action: () => {
resolve(true);
},
cancel: () => {
resolve(false);
},
});
});
} else return true;
}
onMounted(async () => {
const resultStats = await getStatsCustomer();