refactor:add submitCustomer

This commit is contained in:
Thanaphon Frappet 2024-10-02 14:05:36 +07:00
parent 34751b300e
commit 14bf438cba
2 changed files with 112 additions and 15 deletions

View file

@ -1,5 +1,77 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
// NOTE at type
import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types';
export const useQuotationForm = defineStore('form-quotation', () => {
return {};
const defaultFormData: QuotationPayload = {
service: [
{
work: [
{
product: [
{
vat: 0,
discount: 1,
amount: 0,
id: '',
},
],
excluded: false,
id: '',
},
],
id: '',
},
],
urgent: false,
customerBranchId: '',
worker: [],
workerCount: 0,
payBillDate: new Date(),
paySplit: [],
paySplitCount: 0,
payCondition: 'Full',
dueDate: new Date(),
documentReceivePoint: '',
contactTel: '',
contactName: '',
workName: '',
actorName: '',
status: 'CREATED',
};
let resetFormData = structuredClone(defaultFormData);
const currentFormData = ref<QuotationPayload>(structuredClone(resetFormData));
function isFormDataDifferent() {
const { ...resetData } = resetFormData;
const { ...currData } = currentFormData.value;
return JSON.stringify(resetData) !== JSON.stringify(currData);
}
function submitEmployee(data: EmployeeWorker) {
currentFormData.value.worker.push({
alienReferencNumber: data.alienReferencNumber,
documentExpireDate: data.documentExpireDate,
lastNameEN: data.lastNameEN,
lastName: data.lastName,
middleNameEN: data.middleNameEN,
middleName: data.middleName,
firstNameEN: data.firstNameEN,
firstName: data.firstName,
namePrefix: data.namePrefix,
nationality: data.nationality,
gender: data.gender,
dateOfBirth: data.dateOfBirth,
});
}
return {
currentFormData,
submitEmployee,
};
});