refactor: add upload file of employee
This commit is contained in:
parent
13b8b480c6
commit
30c78ef269
2 changed files with 162 additions and 112 deletions
|
|
@ -8,6 +8,7 @@ import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types';
|
|||
|
||||
// NOTE: Import stores
|
||||
import { useQuotationStore } from 'stores/quotations';
|
||||
import useEmployeeStore from 'stores/employee';
|
||||
|
||||
const DEFAULT_DATA: QuotationPayload = {
|
||||
productServiceList: [],
|
||||
|
|
@ -32,9 +33,30 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
|||
const { t } = useI18n();
|
||||
|
||||
const quotationStore = useQuotationStore();
|
||||
const employeeStore = useEmployeeStore();
|
||||
const newWorkerList = ref<
|
||||
(EmployeeWorker & {
|
||||
attachment?: {
|
||||
name?: string;
|
||||
group?: string;
|
||||
url?: string;
|
||||
file?: File;
|
||||
_meta?: Record<string, any>;
|
||||
}[];
|
||||
})[]
|
||||
>([]);
|
||||
|
||||
let resetFormData = structuredClone(DEFAULT_DATA);
|
||||
|
||||
const fileItemNewWorker = ref<
|
||||
{
|
||||
employeeIndex: number;
|
||||
name?: string;
|
||||
group: 'passport' | 'visa' | 'in-country-notice';
|
||||
url?: string;
|
||||
file?: File;
|
||||
_meta?: Record<string, any>;
|
||||
}[]
|
||||
>([]);
|
||||
const currentTreeData = ref();
|
||||
const currentFormData = ref<QuotationPayload & { id?: string }>(
|
||||
structuredClone(resetFormData),
|
||||
|
|
@ -56,7 +78,8 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
|||
if (clean) {
|
||||
currentFormData.value = structuredClone(DEFAULT_DATA);
|
||||
resetFormData = structuredClone(DEFAULT_DATA);
|
||||
|
||||
fileItemNewWorker.value = [];
|
||||
newWorkerList.value = [];
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +115,19 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
|||
|
||||
async function submitQuotation() {
|
||||
if (currentFormState.value.mode === 'create') {
|
||||
await quotationStore.createQuotation(currentFormData.value);
|
||||
const res = await quotationStore.createQuotation(currentFormData.value);
|
||||
|
||||
if (res !== null) {
|
||||
fileItemNewWorker.value.forEach(async (v) => {
|
||||
if (v.group === undefined) return;
|
||||
await employeeStore.postMeta({
|
||||
group: v.group,
|
||||
parentId: res.worker[v.employeeIndex].employeeId,
|
||||
meta: v._meta,
|
||||
file: v.file,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
if (currentFormState.value.mode === 'edit' && currentFormData.value.id) {
|
||||
await quotationStore.editQuotation({
|
||||
|
|
@ -104,20 +139,34 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
|||
currentFormState.value.mode = 'info';
|
||||
}
|
||||
|
||||
function injectNewEmployee(data: EmployeeWorker, callback?: () => void) {
|
||||
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,
|
||||
function injectNewEmployee(
|
||||
obj: {
|
||||
data: EmployeeWorker & {
|
||||
attachment?: {
|
||||
name?: string;
|
||||
group?: string;
|
||||
url?: string;
|
||||
file?: File;
|
||||
_meta?: Record<string, any>;
|
||||
}[];
|
||||
};
|
||||
},
|
||||
callback?: () => void,
|
||||
) {
|
||||
newWorkerList.value.push({
|
||||
// passportNo: obj.data.passportNo, wait api add
|
||||
//documentExpireDate: obj.data.documentExpireDate,
|
||||
lastNameEN: obj.data.lastNameEN,
|
||||
lastName: obj.data.lastName,
|
||||
middleNameEN: obj.data.middleNameEN,
|
||||
middleName: obj.data.middleName,
|
||||
firstNameEN: obj.data.firstNameEN,
|
||||
firstName: obj.data.firstName,
|
||||
namePrefix: obj.data.namePrefix,
|
||||
nationality: obj.data.nationality,
|
||||
gender: obj.data.gender,
|
||||
dateOfBirth: obj.data.dateOfBirth,
|
||||
attachment: obj.data.attachment,
|
||||
});
|
||||
|
||||
callback?.();
|
||||
|
|
@ -141,6 +190,8 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
|||
return {
|
||||
currentFormState,
|
||||
currentFormData,
|
||||
newWorkerList,
|
||||
fileItemNewWorker,
|
||||
|
||||
isFormDataDifferent,
|
||||
injectNewEmployee,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue