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 useUtilsStore, { dialog, notify } from 'stores/utils';
|
||||||
import useFlowStore from 'stores/flow';
|
import useFlowStore from 'stores/flow';
|
||||||
import { Status } from 'stores/types';
|
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 { Employee, EmployeeHistory } from 'stores/employee/types';
|
||||||
import {
|
import {
|
||||||
EditButton,
|
EditButton,
|
||||||
|
|
@ -70,6 +75,13 @@ const customerFormStore = useCustomerForm();
|
||||||
const employeeFormStore = useEmployeeForm();
|
const employeeFormStore = useEmployeeForm();
|
||||||
const optionStore = useOptionStore();
|
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 } =
|
const { state: customerFormState, currentFormData: customerFormData } =
|
||||||
storeToRefs(customerFormStore);
|
storeToRefs(customerFormStore);
|
||||||
const { state: employeeFormState, currentFromDataEmployee } =
|
const { state: employeeFormState, currentFromDataEmployee } =
|
||||||
|
|
@ -230,6 +242,21 @@ const fieldCustomer = [
|
||||||
const employeeHistoryDialog = ref(false);
|
const employeeHistoryDialog = ref(false);
|
||||||
const employeeHistory = ref<EmployeeHistory[]>();
|
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) {
|
function deleteCustomerById(id: string) {
|
||||||
dialog({
|
dialog({
|
||||||
color: 'negative',
|
color: 'negative',
|
||||||
|
|
@ -1799,26 +1826,54 @@ const emptyCreateDialog = ref(false);
|
||||||
if (!customerFormData.customerBranch) return;
|
if (!customerFormData.customerBranch) return;
|
||||||
if (!customerFormState.editCustomerId) return;
|
if (!customerFormState.editCustomerId) return;
|
||||||
|
|
||||||
if (!customerFormData.customerBranch[idx].id) {
|
if (customerFormData.customerType === 'CORP') {
|
||||||
await customerStore.createBranch({
|
filtdRequire.main = ['legalPersonNo', 'registerName'];
|
||||||
...customerFormData.customerBranch[idx],
|
}
|
||||||
customerId: customerFormState.editCustomerId,
|
if (customerFormData.customerType === 'PERS') {
|
||||||
id: undefined,
|
filtdRequire.main = ['citizenId'];
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await customerStore.editBranchById(
|
|
||||||
customerFormData.customerBranch[idx].id || '',
|
|
||||||
{
|
|
||||||
...customerFormData.customerBranch[idx],
|
|
||||||
id: undefined,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await customerFormStore.assignFormData(
|
let tapIsUndefined = validateFiltdRequire(
|
||||||
customerFormState.editCustomerId,
|
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