refactor: header data on submit
This commit is contained in:
parent
358ef363bd
commit
c1def79b11
1 changed files with 73 additions and 18 deletions
|
|
@ -11,7 +11,12 @@ import useMyBranchStore from 'stores/my-branch';
|
|||
import useUtilsStore, { dialog, notify } from 'stores/utils';
|
||||
import useFlowStore from 'stores/flow';
|
||||
import { Status } from 'stores/types';
|
||||
import { CustomerStats, Customer, CustomerBranch } from 'stores/customer/types';
|
||||
import {
|
||||
CustomerStats,
|
||||
Customer,
|
||||
CustomerBranch,
|
||||
CustomerBranchCreate,
|
||||
} from 'stores/customer/types';
|
||||
import { Employee, EmployeeHistory } from 'stores/employee/types';
|
||||
import {
|
||||
EditButton,
|
||||
|
|
@ -70,6 +75,13 @@ const customerFormStore = useCustomerForm();
|
|||
const employeeFormStore = useEmployeeForm();
|
||||
const optionStore = useOptionStore();
|
||||
|
||||
const filtdRequire = ref<{ [key: string]: (keyof CustomerBranchCreate)[] }>({
|
||||
main: ['citizenId', 'legalPersonNo', 'registerName'],
|
||||
address: ['address', 'addressEN', 'provinceId', 'districtId'],
|
||||
business: [],
|
||||
contact: ['contactName', 'telephoneNo'],
|
||||
});
|
||||
|
||||
const { state: customerFormState, currentFormData: customerFormData } =
|
||||
storeToRefs(customerFormStore);
|
||||
const { state: employeeFormState, currentFromDataEmployee } =
|
||||
|
|
@ -230,6 +242,21 @@ const fieldCustomer = [
|
|||
const employeeHistoryDialog = ref(false);
|
||||
const employeeHistory = ref<EmployeeHistory[]>();
|
||||
|
||||
function validateFiltdRequire<T = CustomerBranchCreate>(
|
||||
value: T,
|
||||
fieldRequired: { [key: string]: (keyof T)[] },
|
||||
) {
|
||||
const list: string[] = [];
|
||||
|
||||
for (const tab in fieldRequired) {
|
||||
for (const field of fieldRequired[tab]) {
|
||||
if (!value[field] && !list.includes(tab)) list.push(tab);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
function deleteCustomerById(id: string) {
|
||||
dialog({
|
||||
color: 'negative',
|
||||
|
|
@ -1799,26 +1826,54 @@ const emptyCreateDialog = ref(false);
|
|||
if (!customerFormData.customerBranch) return;
|
||||
if (!customerFormState.editCustomerId) return;
|
||||
|
||||
if (!customerFormData.customerBranch[idx].id) {
|
||||
await customerStore.createBranch({
|
||||
...customerFormData.customerBranch[idx],
|
||||
customerId: customerFormState.editCustomerId,
|
||||
id: undefined,
|
||||
});
|
||||
} else {
|
||||
await customerStore.editBranchById(
|
||||
customerFormData.customerBranch[idx].id || '',
|
||||
{
|
||||
...customerFormData.customerBranch[idx],
|
||||
id: undefined,
|
||||
},
|
||||
);
|
||||
if (customerFormData.customerType === 'CORP') {
|
||||
filtdRequire.main = ['legalPersonNo', 'registerName'];
|
||||
}
|
||||
if (customerFormData.customerType === 'PERS') {
|
||||
filtdRequire.main = ['citizenId'];
|
||||
}
|
||||
|
||||
await customerFormStore.assignFormData(
|
||||
customerFormState.editCustomerId,
|
||||
let tapIsUndefined = validateFiltdRequire(
|
||||
customerFormData.customerBranch?.[idx],
|
||||
filtdRequire,
|
||||
);
|
||||
customerFormStore.resetForm();
|
||||
|
||||
if (!!tapIsUndefined) {
|
||||
dialog({
|
||||
color: 'warning',
|
||||
icon: 'mdi-alert',
|
||||
title: t('dialog.title.incompleteDataEntry'),
|
||||
actionText: t('ok'),
|
||||
persistent: true,
|
||||
message: t('dialog.message.incompleteDataEntry', {
|
||||
tap: `${tapIsUndefined.map((v: string) => t(`customerBranch.tab.${v}`)).join(', ')}`,
|
||||
}),
|
||||
action: async () => {
|
||||
return;
|
||||
},
|
||||
});
|
||||
} else {
|
||||
if (!customerFormData.customerBranch[idx].id) {
|
||||
await customerStore.createBranch({
|
||||
...customerFormData.customerBranch[idx],
|
||||
customerId: customerFormState.editCustomerId,
|
||||
id: undefined,
|
||||
});
|
||||
} else {
|
||||
await customerStore.editBranchById(
|
||||
customerFormData.customerBranch[idx].id || '',
|
||||
{
|
||||
...customerFormData.customerBranch[idx],
|
||||
id: undefined,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
await customerFormStore.assignFormData(
|
||||
customerFormState.editCustomerId,
|
||||
);
|
||||
customerFormStore.resetForm();
|
||||
}
|
||||
}
|
||||
"
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue