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

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

View file

@ -1,5 +1,77 @@
import { defineStore } from 'pinia'; 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', () => { 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,
};
}); });