diff --git a/src/components/03_customer-management/DialogEmployee.vue b/src/components/03_customer-management/DialogEmployee.vue new file mode 100644 index 00000000..cfd4088a --- /dev/null +++ b/src/components/03_customer-management/DialogEmployee.vue @@ -0,0 +1,1646 @@ + + + + + { + employeeFormState.imageDialog = true; + employeeFormState.isImageEdit = false; + } + " + @edit=" + employeeFormState.imageDialog = employeeFormState.isImageEdit = true + " + @update:toggle-status=" + () => { + currentFromDataEmployee.status = + currentFromDataEmployee.status === 'CREATED' + ? 'INACTIVE' + : 'CREATED'; + } + " + /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + employeeFormStore.resetFormDataEmployee(); + employeeFormState.isEmployeeEdit = false; + employeeFormState.dialogType = 'info'; + } + " + type="button" + /> + + { + employeeFormState.isEmployeeEdit = true; + employeeFormState.dialogType = 'edit'; + } + " + type="button" + /> + + deleteEmployeeById({ + id: currentFromDataEmployee.id, + fetch: async () => + await fetchListEmployee( + currentTab === 'employer' + ? { + page: 1, + pageSize: 999, + customerId: + customerFormState.currentCustomerId, + } + : { + fetchStats: true, + mobileFetch: $q.screen.xs, + }, + ), + }) + " + type="button" + /> + + + + + + + + + + + {{ $t(`general.uploadFile`) }} + + + { + if (allMeta === undefined) return; + + if (group === 'passport') { + const fullName = allMeta['full_name'].split(' '); + let tempValue: { + oldData: { nameField: string; value: string }[]; + newData: { nameField: string; value: string }[]; + } = { oldData: [], newData: [] }; + + if ( + currentFromDataEmployee.gender !== '' && + currentFromDataEmployee.gender !== allMeta['sex'] + ) { + tempValue.oldData.push({ + nameField: $t('form.gender'), + value: $t( + `general.${currentFromDataEmployee.gender}`, + ), + }); + tempValue.newData.push({ + nameField: $t('form.gender'), + value: $t(`general.${allMeta['sex']}`), + }); + } + + if (currentFromDataEmployee.firstName !== '') { + tempValue.oldData.push({ + nameField: $t('personnel.form.firstName'), + value: currentFromDataEmployee.firstName, + }); + tempValue.newData.push({ + nameField: $t('personnel.form.firstName'), + value: fullName[0], + }); + } + + if (currentFromDataEmployee.lastName !== '') { + tempValue.oldData.push({ + nameField: $t('personnel.form.lastName'), + value: currentFromDataEmployee.lastName, + }); + tempValue.newData.push({ + nameField: $t('personnel.form.lastName'), + value: fullName[1], + }); + } + + if (currentFromDataEmployee.nationality !== '') { + tempValue.oldData.push({ + nameField: $t('general.nationality'), + value: currentFromDataEmployee.nationality || '', + }); + tempValue.newData.push({ + nameField: $t('general.nationality'), + value: allMeta['nationality'], + }); + } + + dialogCheckData({ + action: async () => { + currentFromDataEmployee.gender = allMeta['sex']; + currentFromDataEmployee.firstName = fullName[0]; + currentFromDataEmployee.lastName = fullName[1]; + currentFromDataEmployee.nationality = + allMeta['nationality']; + }, + checkData: () => { + return tempValue; + }, + cancel: () => { + if (!currentFromDataEmployee.gender) { + currentFromDataEmployee.gender = allMeta['gender']; + } + if (!currentFromDataEmployee.firstName) { + currentFromDataEmployee.firstName = fullName[0]; + } + if (!currentFromDataEmployee.firstName) { + currentFromDataEmployee.firstName = fullName[0]; + } + if (!currentFromDataEmployee.lastName) { + currentFromDataEmployee.lastName = fullName[1]; + } + + if (!currentFromDataEmployee.nationality) { + currentFromDataEmployee.nationality = + allMeta['nationality']; + } + }, + }); + } + } + " + :ocr=" + async (group, file) => { + if (group === 'passport') { + mrz = await runOcr(file, parseResultMRZ); + + if (mrz !== null) { + const mapMrz = Object.entries(mrz.result || {}).map( + ([key, value]) => ({ + name: key, + value: String(value), + }), + ); + const tempValue = { + status: true, + group, + meta: mapMrz, + }; + + return tempValue; + } + } + if (group === 'visa') { + const res = await ocrStore.sendOcr({ + file: file, + category: group, + }); + + if (res) { + const tempValue = { + status: true, + group, + meta: res.fields, + }; + + return tempValue; + } + } + + return { status: true, group, meta: [] }; + } + " + :auto-save="currentFromDataEmployee.id !== ''" + :download=" + (obj) => { + if (obj.group !== 'attachment') { + employeeStore.getFile({ + parentId: currentFromDataEmployee.id || '', + group: obj.group, + fileId: obj._meta.id, + download: true, + }); + } else { + employeeStore.getAttachment({ + parentId: currentFromDataEmployee.id || '', + name: obj._meta.name, + download: true, + }); + } + } + " + :delete-item=" + async (obj) => { + let status: boolean = false; + const res = await employeeStore.delMeta({ + parentId: currentFromDataEmployee.id || '', + group: obj.group, + metaId: obj._meta.id, + }); + + if (res) { + status = true; + } + + await employeeFormStore.assignFormDataEmployee( + currentFromDataEmployee.id, + ); + + return status; + } + " + :save=" + async ( + group: 'passport' | 'visa' | 'attachment', + _meta: any, + file: File | undefined, + ) => { + let status: boolean = false; + if (group === 'passport' || group === 'visa') { + if (file !== undefined && currentFromDataEmployee.id) { + const res = await employeeStore.postMeta({ + parentId: currentFromDataEmployee.id || '', + group, + meta: _meta, + file, + }); + + if (res) { + status = true; + } + } else { + const { + id, + employeeId, + createdAt, + updatedAt, + ...payload + } = _meta; + + const res = await employeeStore.putMeta({ + parentId: currentFromDataEmployee.id || '', + group, + metaId: _meta.id, + meta: payload, + file, + }); + if (res) { + status = true; + } + } + } else { + if (file !== undefined) { + await employeeStore.uploadAttachment( + currentFromDataEmployee.id || '', + file, + file.name, + ); + status = true; + } + } + await employeeFormStore.assignFormDataEmployee( + currentFromDataEmployee.id, + ); + return status; + } + " + :get-file-list=" + async (group: 'passport' | 'visa' | 'attachment') => { + if ( + !!currentFromDataEmployee.id && + group !== 'attachment' + ) { + const resMeta = await employeeStore.getMetaList({ + parentId: currentFromDataEmployee.id, + group, + }); + + const tempValue = resMeta.map(async (i: any) => { + return { + _meta: { ...i }, + name: `${group}-${dateFormat(i.expireDate)}` || '', + group: group, + url: await employeeStore.getFile({ + parentId: currentFromDataEmployee.id || '', + group, + fileId: i.id, + }), + file: undefined, + }; + }); + + return await waitAll(tempValue); + } else { + const res = await employeeStore.listAttachment({ + parentId: currentFromDataEmployee.id || '', + }); + + const tempValue = (res as string[]).map( + async (i: any) => { + return { + _meta: { id: i, name: i }, + name: i || '', + group: group, + url: await employeeStore.getAttachment({ + parentId: currentFromDataEmployee.id || '', + name: i, + }), + file: undefined, + }; + }, + ); + + return await waitAll(tempValue); + } + } + " + > + + + + + + + + + + + + + + + {{ $t('customerEmployee.form.group.passport') }} + + + + + + {{ $t('general.expirationDate') }} : + {{ dateFormat(value.expireDate) }} + + + + + + { + employeeFormStore.resetFormDataEmployee(); + employeeFormState.isEmployeeEdit = false; + employeeFormState.dialogType = 'info'; + employeeFormState.currentIndexPassport = -1; + } + " + type="button" + /> + { + employeeFormState.currentIndexPassport = index; + } + " + type="submit" + /> + + { + employeeFormState.currentIndexPassport = index; + employeeFormState.isEmployeeEdit = true; + employeeFormState.dialogType = 'edit'; + } + " + type="button" + /> + { + employeeFormState.currentIndexPassport = index; + deleteEmployeeById({ + type: 'passport', + index, + fetch: async () => + await fetchListEmployee( + currentTab === 'employer' + ? { + page: 1, + pageSize: 999, + customerId: + customerFormState.currentCustomerId, + } + : { + fetchStats: true, + mobileFetch: $q.screen.xs, + }, + ), + }); + } + " + type="button" + :disabled=" + !(employeeFormState.currentIndexPassport === -1) && + !(employeeFormState.currentIndexPassport === index) + " + /> + + + + + + + + + + + {{ $t('customerEmployee.form.group.visa') }} + + + + + + {{ $t('general.expirationDate') }} : + {{ dateFormat(value.expireDate) }} + + + + + + { + employeeFormStore.resetFormDataEmployee(); + employeeFormState.isEmployeeEdit = false; + employeeFormState.dialogType = 'info'; + employeeFormState.currentIndexVisa = -1; + } + " + type="button" + /> + { + employeeFormState.currentIndexVisa = index; + } + " + type="submit" + /> + + { + employeeFormState.currentIndexVisa = index; + employeeFormState.isEmployeeEdit = true; + employeeFormState.dialogType = 'edit'; + } + " + type="button" + /> + { + employeeFormState.currentIndexVisa = index; + deleteEmployeeById({ + type: 'visa', + index, + fetch: async () => + await fetchListEmployee( + currentTab === 'employer' + ? { + page: 1, + pageSize: 999, + customerId: + customerFormState.currentCustomerId, + } + : { + fetchStats: true, + mobileFetch: $q.screen.xs, + }, + ), + }); + } + " + type="button" + :disabled=" + !(employeeFormState.currentIndexVisa === -1) && + !(employeeFormState.currentIndexVisa === index) + " + /> + + + + + + + + + + + + {{ $t(`customerEmployee.formHealthCheck.title`) }} + + + { + employeeFormState.currentIndexCheckup = index; + deleteEmployeeById({ + type: 'healthCheck', + index, + fetch: async () => + await fetchListEmployee( + currentTab === 'employer' + ? { + page: 1, + pageSize: 999, + customerId: customerFormState.currentCustomerId, + } + : { + fetchStats: true, + mobileFetch: $q.screen.xs, + }, + ), + }); + } + " + @save=" + (index) => { + employeeFormState.currentIndexCheckup = index; + notify('create', $t('general.success')); + } + " + @undo=" + (index) => { + if ( + currentFromDataEmployee.employeeCheckup?.[index] + .statusSave === false + ) { + currentFromDataEmployee.employeeCheckup[ + index + ].statusSave = true; + } + } + " + @edit=" + (index) => { + if ( + currentFromDataEmployee.employeeCheckup?.[index] + .statusSave + ) { + currentFromDataEmployee.employeeCheckup[ + index + ].statusSave = false; + } + } + " + /> + + + + + + + + {{ $t(`customerEmployee.form.group.workHistory`) }} + + + { + employeeFormState.currentIndexWorkHistory = index; + deleteEmployeeById({ + type: 'work', + index, + fetch: async () => + await fetchListEmployee( + currentTab === 'employer' + ? { + page: 1, + pageSize: 999, + customerId: customerFormState.currentCustomerId, + } + : { + fetchStats: true, + mobileFetch: $q.screen.xs, + }, + ), + }); + } + " + @save=" + (index) => { + employeeFormState.currentIndexWorkHistory = index; + } + " + @undo=" + (index) => { + if ( + currentFromDataEmployee.employeeWork?.[index] + .statusSave === false + ) { + currentFromDataEmployee.employeeWork[index].statusSave = + true; + } + } + " + @edit=" + (index) => { + if ( + currentFromDataEmployee.employeeWork?.[index].statusSave + ) { + currentFromDataEmployee.employeeWork[index].statusSave = + false; + } + } + " + /> + + + + + { + if ( + currentFromDataEmployee.employeeOtherInfo?.statusSave === + false + ) { + currentFromDataEmployee.employeeOtherInfo.statusSave = true; + } + } + " + @edit=" + () => { + if (currentFromDataEmployee.employeeOtherInfo?.statusSave) { + currentFromDataEmployee.employeeOtherInfo.statusSave = false; + } + } + " + /> + + + + + + + { + if (!v) return; + if (!currentFromDataEmployee.id) return; + await employeeStore.addImageList( + v, + currentFromDataEmployee.id, + Date.now().toString(), + ); + await fetchImageList( + currentFromDataEmployee.id, + currentFromDataEmployee.selectedImage || '', + 'employee', + ); + } + " + @remove-image=" + async (v) => { + if (!v) return; + if (!currentFromDataEmployee.id) return; + const name = v.split('/').pop() || ''; + await employeeStore.deleteImageByName(currentFromDataEmployee.id, name); + await fetchImageList( + currentFromDataEmployee.id, + currentFromDataEmployee.selectedImage || '', + 'employee', + ); + } + " + @submit=" + async (v) => { + if (employeeFormState.dialogModal && !currentFromDataEmployee.id) { + employeeFormState.profileUrl = v; + employeeFormState.imageDialog = false; + } else { + refreshImageState = true; + employeeFormState.dialogType = 'edit'; + currentFromDataEmployee.selectedImage = v; + employeeFormState.imageList + ? (employeeFormState.imageList.selectedImage = v) + : ''; + employeeFormState.profileUrl = `${baseUrl}/employee/${currentFromDataEmployee.id && currentFromDataEmployee.id}/image/${v}`; + employeeFormStore.resetFormDataEmployee(); + await employeeFormStore.submitPersonal(onCreateImageList); + employeeFormState.imageDialog = false; + refreshImageState = false; + employeeFormState.isEmployeeEdit = false; + employeeFormState.dialogType = 'info'; + await fetchListEmployee(); + } + } + " + > + + + {{ $t('general.image') }} + {{ + $i18n.locale === 'eng' + ? `${currentFromDataEmployee.firstNameEN || currentFromDataEmployee.firstName} ${currentFromDataEmployee.lastNameEN || currentFromDataEmployee.lastName}` + : `${currentFromDataEmployee.firstName} ${currentFromDataEmployee.lastName}` + }} + + + + + + + + + + + diff --git a/src/components/03_customer-management/DrawerEmployee.vue b/src/components/03_customer-management/DrawerEmployee.vue index 5cbdde66..c5e94e79 100644 --- a/src/components/03_customer-management/DrawerEmployee.vue +++ b/src/components/03_customer-management/DrawerEmployee.vue @@ -22,6 +22,7 @@ import FormEmployeePassport from './FormEmployeePassport.vue'; import FormEmployeeVisa from './FormEmployeeVisa.vue'; import FormEmployeeWorkHistory from './FormEmployeeWorkHistory.vue'; import ExpirationDate from 'components/03_customer-management/ExpirationDate.vue'; +import ImageUploadDialog from '../ImageUploadDialog.vue'; import useOcrStore from 'stores/ocr'; import useOptionStore from 'src/stores/options'; @@ -58,6 +59,7 @@ const { state: employeeFormState, currentFromDataEmployee, refreshImageState, + onCreateImageList, } = storeToRefs(employeeFormStore); const { state: customerFormState, currentFormData: customerFormData } = storeToRefs(customerFormStore); @@ -71,7 +73,13 @@ const props = defineProps<{ customerId?: string; mobileFetch?: boolean; }) => Promise; + fetchImageList: ( + id: string, + selectedName: string, + type: 'customer' | 'employee', + ) => Promise; }>(); + const mrz = defineModel>>('mrz'); defineEmits<{ @@ -1668,4 +1676,95 @@ defineEmits<{ + + { + if (!v) return; + if (!currentFromDataEmployee.id) return; + await employeeStore.addImageList( + v, + currentFromDataEmployee.id, + Date.now().toString(), + ); + await fetchImageList( + currentFromDataEmployee.id, + currentFromDataEmployee.selectedImage || '', + 'employee', + ); + } + " + @remove-image=" + async (v) => { + if (!v) return; + if (!currentFromDataEmployee.id) return; + const name = v.split('/').pop() || ''; + await employeeStore.deleteImageByName(currentFromDataEmployee.id, name); + await fetchImageList( + currentFromDataEmployee.id, + currentFromDataEmployee.selectedImage || '', + 'employee', + ); + } + " + @submit=" + async (v) => { + if (employeeFormState.dialogModal && !currentFromDataEmployee.id) { + employeeFormState.profileUrl = v; + employeeFormState.imageDialog = false; + } else { + refreshImageState = true; + employeeFormState.dialogType = 'edit'; + currentFromDataEmployee.selectedImage = v; + employeeFormState.imageList + ? (employeeFormState.imageList.selectedImage = v) + : ''; + employeeFormState.profileUrl = `${baseUrl}/employee/${currentFromDataEmployee.id && currentFromDataEmployee.id}/image/${v}`; + employeeFormStore.resetFormDataEmployee(); + await employeeFormStore.submitPersonal(onCreateImageList); + employeeFormState.imageDialog = false; + refreshImageState = false; + employeeFormState.isEmployeeEdit = false; + employeeFormState.dialogType = 'info'; + await fetchListEmployee(); + } + } + " + > + + + {{ $t('general.image') }} + {{ + $i18n.locale === 'eng' + ? `${currentFromDataEmployee.firstNameEN || currentFromDataEmployee.firstName} ${currentFromDataEmployee.lastNameEN || currentFromDataEmployee.lastName}` + : `${currentFromDataEmployee.firstName} ${currentFromDataEmployee.lastName}` + }} + + + + + + + + + + diff --git a/src/pages/03_customer-management/BranchPage.vue b/src/pages/03_customer-management/BranchPage.vue index ef8ab8f5..dd8c4737 100644 --- a/src/pages/03_customer-management/BranchPage.vue +++ b/src/pages/03_customer-management/BranchPage.vue @@ -18,6 +18,8 @@ import { CustomerBranch, CustomerType } from 'stores/customer/types'; import { columnsEmployee } from './constant'; import { useCustomerBranchForm, useEmployeeForm } from './form'; +import DialogEmployee from 'src/components/03_customer-management/DialogEmployee.vue'; +import DrawerEmployee from 'src/components/03_customer-management/DrawerEmployee.vue'; import EmployerFormAuthorized from './components/employer/EmployerFormAuthorized.vue'; import FloatingActionButton from 'components/FloatingActionButton.vue'; import SideMenu from 'components/SideMenu.vue'; @@ -89,6 +91,11 @@ const prop = withDefaults( currentCitizenId?: string; gender: string; selectedImage: string; + fetchImageList: ( + id: string, + selectedName: string, + type: 'customer' | 'employee', + ) => Promise; }>(), { color: 'green', @@ -96,7 +103,6 @@ const prop = withDefaults( ); const currentBranchEmployee = ref(''); const listEmployee = ref([]); - const customerId = defineModel('customerId', { required: true }); defineEmits<{ @@ -106,16 +112,6 @@ defineEmits<{ (e: 'dialog'): void; }>(); -onMounted(async () => { - customerBranchFormState.value.currentCustomerId = route.params - .customerId as string; - await fetchList(); - - branch.value?.forEach((v) => { - currentBtnOpen.value.push(false); - }); -}); - const columns = [ { name: 'branchName', @@ -257,10 +253,6 @@ async function fetchEmployee(opts: { branchId: string; pageSize?: number }) { } } -onMounted(async () => { - await fetchList(); -}); - watch([customerId, inputSearch, currentStatus, pageSizeBranch], async () => { await fetchList(); }); @@ -280,6 +272,16 @@ watch( } }, ); + +onMounted(async () => { + customerBranchFormState.value.currentCustomerId = route.params + .customerId as string; + await fetchList(); + + branch.value?.forEach((v) => { + currentBtnOpen.value.push(false); + }); +}); @@ -641,10 +643,15 @@ watch( " @history="(item) => {}" @view=" - (item) => { + async (item) => { employeeFormState.drawerModal = true; //employeeFormState.isEmployeeEdit = true; employeeFormStore.assignFormDataEmployee(item.id); + await fetchImageList( + item.id, + item.selectedImage || '', + 'employee', + ); } " /> @@ -1004,6 +1011,18 @@ watch( /> + + + +