refactor:add submitCustomer
This commit is contained in:
parent
34751b300e
commit
14bf438cba
2 changed files with 112 additions and 15 deletions
|
|
@ -4,7 +4,7 @@ import { onMounted, reactive, ref } from 'vue';
|
|||
import { useRouter } from 'vue-router';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
// at stores
|
||||
// NOTE at stores
|
||||
import useProductServiceStore from 'src/stores/product-service';
|
||||
import { useQuotationStore } from 'src/stores/quotations';
|
||||
import { baseUrl, waitAll } from 'src/stores/utils';
|
||||
|
|
@ -12,12 +12,13 @@ import useCustomerStore from 'stores/customer';
|
|||
import useEmployeeStore from 'stores/employee';
|
||||
import useFlowStore from 'src/stores/flow';
|
||||
import useOcrStore from 'stores/ocr';
|
||||
import useMyBranch from 'stores/my-branch';
|
||||
|
||||
// at type
|
||||
// NOTE at type
|
||||
import { CustomerBranchCreate } from 'stores/customer/types';
|
||||
import { Employee } from 'src/stores/employee/types';
|
||||
|
||||
// at component
|
||||
// NOTE at component
|
||||
import BasicInformation from 'components/03_customer-management/employee/BasicInformation.vue';
|
||||
import FormReferDocument from 'src/components/05_quotation/FormReferDocument.vue';
|
||||
import { UploadFileGroup, noticeJobEmployment } from 'components/upload-file';
|
||||
|
|
@ -81,17 +82,19 @@ type Node = {
|
|||
children?: Node[];
|
||||
};
|
||||
|
||||
const employeeStore = useEmployeeStore();
|
||||
const ocrStore = useOcrStore();
|
||||
const customerFormStore = useCustomerForm();
|
||||
const employeeFormStore = useEmployeeForm();
|
||||
const employeeStore = useEmployeeStore();
|
||||
const customerStore = useCustomerStore();
|
||||
const flowStore = useFlowStore();
|
||||
const userBranch = useMyBranch();
|
||||
const ocrStore = useOcrStore();
|
||||
|
||||
const { state: customerFormState, currentFormData: customerFormData } =
|
||||
storeToRefs(customerFormStore);
|
||||
const { state: employeeFormState, currentFromDataEmployee } =
|
||||
storeToRefs(employeeFormStore);
|
||||
const { currentMyBranch } = storeToRefs(userBranch);
|
||||
|
||||
const currentCustomerId = ref<string | undefined>();
|
||||
const refreshImageState = ref(false);
|
||||
|
|
@ -299,7 +302,13 @@ const formDataEmployee = ref<EmployeeWorker>({
|
|||
dateOfBirth: new Date(),
|
||||
});
|
||||
|
||||
const formDataCustomerBranch = ref<CustomerBranchCreate>({
|
||||
const formDataCustomerBranch = ref<
|
||||
CustomerBranchCreate & {
|
||||
id?: string;
|
||||
branchCode?: string;
|
||||
codeCustomer?: string;
|
||||
}
|
||||
>({
|
||||
customerCode: '',
|
||||
customerId: '',
|
||||
legalPersonNo: '',
|
||||
|
|
@ -311,7 +320,7 @@ const formDataCustomerBranch = ref<CustomerBranchCreate>({
|
|||
lastNameEN: '',
|
||||
telephoneNo: '',
|
||||
gender: '',
|
||||
birthDate: '',
|
||||
birthDate: new Date().toString(),
|
||||
businessType: '',
|
||||
jobPosition: '',
|
||||
jobDescription: '',
|
||||
|
|
@ -363,7 +372,7 @@ function setDefaultCustomerd() {
|
|||
lastNameEN: '',
|
||||
telephoneNo: '',
|
||||
gender: '',
|
||||
birthDate: '',
|
||||
birthDate: new Date().toString(),
|
||||
businessType: '',
|
||||
jobPosition: '',
|
||||
jobDescription: '',
|
||||
|
|
@ -403,6 +412,19 @@ function setDefaultCustomerd() {
|
|||
];
|
||||
}
|
||||
|
||||
function submitCustomer() {
|
||||
if (currentMyBranch.value === undefined) return;
|
||||
|
||||
const { code, customerCode, birthDate, ...payload } =
|
||||
formDataCustomerBranch.value;
|
||||
|
||||
customerFormData.value.customerBranch = [{ ...payload }];
|
||||
customerFormData.value.registeredBranchId = currentMyBranch.value.id;
|
||||
customerFormStore.submitFormCustomer();
|
||||
customerFormState.value.dialogType = 'info';
|
||||
customerFormState.value.editCustomerId = '218554';
|
||||
}
|
||||
|
||||
function triggerCreateEmployee() {
|
||||
employeeFormStore.resetFormDataEmployee(true);
|
||||
employeeFormState.value.dialogType = 'create';
|
||||
|
|
@ -1038,7 +1060,6 @@ watch(() => pageState.currentTab, fetchQuotationList);
|
|||
@click="
|
||||
() => {
|
||||
triggerCreateEmployee();
|
||||
console.log('asdassdasd');
|
||||
}
|
||||
"
|
||||
/>
|
||||
|
|
@ -1114,7 +1135,11 @@ watch(() => pageState.currentTab, fetchQuotationList);
|
|||
})
|
||||
: `${$t('customer.employer')} `
|
||||
"
|
||||
:submit="() => {}"
|
||||
:submit="
|
||||
() => {
|
||||
submitCustomer();
|
||||
}
|
||||
"
|
||||
:close="
|
||||
() => {
|
||||
customerFormState.dialogModal = false;
|
||||
|
|
@ -1190,7 +1215,7 @@ watch(() => pageState.currentTab, fetchQuotationList);
|
|||
<UndoButton
|
||||
v-if="
|
||||
customerFormState.dialogType === 'edit' &&
|
||||
currentCustomerId !== undefined
|
||||
customerFormState.editCustomerId !== undefined
|
||||
"
|
||||
icon-only
|
||||
@click="() => {}"
|
||||
|
|
@ -1209,7 +1234,7 @@ watch(() => pageState.currentTab, fetchQuotationList);
|
|||
<EditButton
|
||||
v-if="
|
||||
customerFormState.dialogType !== 'edit' &&
|
||||
currentCustomerId !== undefined
|
||||
customerFormState.editCustomerId !== undefined
|
||||
"
|
||||
id="btn-info-basic-edit"
|
||||
icon-only
|
||||
|
|
@ -1220,7 +1245,7 @@ watch(() => pageState.currentTab, fetchQuotationList);
|
|||
<DeleteButton
|
||||
v-if="
|
||||
customerFormState.dialogType !== 'edit' &&
|
||||
currentCustomerId !== undefined
|
||||
customerFormState.editCustomerId !== undefined
|
||||
"
|
||||
id="btn-info-basic-delete"
|
||||
icon-only
|
||||
|
|
@ -1291,6 +1316,7 @@ watch(() => pageState.currentTab, fetchQuotationList);
|
|||
v-model:authorized-capital="
|
||||
formDataCustomerBranch.authorizedCapital
|
||||
"
|
||||
v-model:telephone-no="formDataCustomerBranch.telephoneNo"
|
||||
/>
|
||||
|
||||
<EmployerFormBusiness
|
||||
|
|
@ -1307,7 +1333,6 @@ watch(() => pageState.currentTab, fetchQuotationList);
|
|||
v-model:wage-rate="formDataCustomerBranch.wageRate"
|
||||
v-model:wage-rate-text="formDataCustomerBranch.wageRateText"
|
||||
/>
|
||||
|
||||
<AddressForm
|
||||
id="form-address"
|
||||
prefix-id="employer"
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue