diff --git a/src/components/03_customer-management/DrawerEmployee.vue b/src/components/03_customer-management/DrawerEmployee.vue new file mode 100644 index 00000000..c7155931 --- /dev/null +++ b/src/components/03_customer-management/DrawerEmployee.vue @@ -0,0 +1,1670 @@ + + + + + + + { + employeeFormState.isImageEdit = false; + employeeFormStore.resetFormDataEmployee(); + employeeFormState.isEmployeeEdit = false; + employeeFormState.dialogType = 'info'; + employeeFormState.currentIndexPassport = -1; + } + " + @view=" + () => { + employeeFormState.imageDialog = true; + employeeFormState.isImageEdit = false; + } + " + @edit=" + employeeFormState.imageDialog = employeeFormState.isImageEdit = true + " + @update:toggle-status=" + (v) => { + if (currentFromDataEmployee.id !== undefined) + $emit('changeStatus', v); + } + " + :active="currentFromDataEmployee.status !== 'INACTIVE'" + use-toggle + color="white" + icon="mdi-account-outline" + :bg-color=" + employeeFormState.profileUrl + ? 'white' + : 'linear-gradient(135deg, rgba(43,137,223,1) 0%, rgba(230,51,81,1) 100%)' + " + v-model:current-tab="employeeFormState.currentTab" + v-model:toggle-status="currentFromDataEmployee.status" + fallback-cover="/images/employee-banner.png" + :title=" + employeeFormState.currentEmployee + ? setPrefixName( + { + namePrefix: employeeFormState.currentEmployee.namePrefix, + firstName: + employeeFormState.currentEmployee.firstName || + employeeFormState.currentEmployee.firstNameEN, + lastName: employeeFormState.currentEmployee.lastName, + firstNameEN: employeeFormState.currentEmployee.firstNameEN, + lastNameEN: employeeFormState.currentEmployee.lastNameEN, + }, + { locale }, + ) + : '-' + " + :caption="currentFromDataEmployee.code" + :img=" + `${baseUrl}/employee/${currentFromDataEmployee.id}/image/${currentFromDataEmployee.selectedImage}`.concat( + refreshImageState ? `?ts=${Date.now()}` : '', + ) || null + " + :fallbackImg="`/images/employee-avatar-${currentFromDataEmployee.gender === 'male' ? 'male' : 'female'}.png`" + :tabs-list="[ + { + name: 'personalInfo', + label: $t('customerEmployee.form.group.personalInfo'), + }, + { + name: 'passport', + label: $t('customerEmployee.fileType.passport'), + }, + { + name: 'visa', + label: $t('customerEmployee.form.group.visa'), + }, + { + name: 'healthCheck', + label: $t('customerEmployee.form.group.healthCheck'), + }, + { + name: 'workHistory', + label: $t('customerEmployee.form.group.workHistory'), + }, + { name: 'other', label: $t('customerEmployee.form.group.other') }, + ]" + :toggle-title="$t('status.title')" + /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + 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) { + 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" + /> + { + 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" + /> + { + 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; + notify('create', $t('general.success')); + } + " + @edit=" + (index) => { + if ( + currentFromDataEmployee.employeeCheckup?.[index] + .statusSave + ) { + employeeFormState.currentIndexCheckup = index; + currentFromDataEmployee.employeeCheckup[ + index + ].statusSave = false; + } + } + " + @undo=" + (index) => { + if ( + currentFromDataEmployee.employeeCheckup?.[index] + .statusSave === false + ) { + employeeFormState.currentIndexCheckup = -1; + currentFromDataEmployee.employeeCheckup[ + index + ].statusSave = true; + employeeFormStore.resetFormDataEmployee(); + } + } + " + @delete=" + (index) => { + 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, + }, + ), + }); + } + " + /> + + + + + + + + {{ $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 + ) { + employeeFormState.currentIndexWorkHistory = -1; + currentFromDataEmployee.employeeWork[ + index + ].statusSave = true; + } + } + " + @edit=" + (index) => { + if ( + currentFromDataEmployee.employeeWork?.[index] + .statusSave + ) { + employeeFormState.currentIndexWorkHistory = index; + currentFromDataEmployee.employeeWork[ + index + ].statusSave = false; + } + } + " + /> + + + + + { + if ( + currentFromDataEmployee.employeeOtherInfo?.statusSave === + false + ) { + currentFromDataEmployee.employeeOtherInfo.statusSave = true; + } + } + " + @edit=" + () => { + if (currentFromDataEmployee.employeeOtherInfo?.statusSave) { + currentFromDataEmployee.employeeOtherInfo.statusSave = false; + } + } + " + /> + + + + + + + diff --git a/src/pages/03_customer-management/MainPage.vue b/src/pages/03_customer-management/MainPage.vue index 6152ad1b..7ed8d550 100644 --- a/src/pages/03_customer-management/MainPage.vue +++ b/src/pages/03_customer-management/MainPage.vue @@ -3,21 +3,11 @@ import { ref, watch, onMounted, computed } from 'vue'; import { useI18n } from 'vue-i18n'; import { useQuasar } from 'quasar'; import { useRoute, useRouter } from 'vue-router'; -import { getUserId, getRole } from 'src/services/keycloak'; -import { baseUrl, setPrefixName, waitAll } from 'src/stores/utils'; -import { dateFormat } from 'src/utils/datetime'; -import { dialogCheckData, canAccess } from 'stores/utils'; +import { canAccess } from 'stores/utils'; -import useOcrStore from 'stores/ocr'; import useCustomerStore from 'stores/customer'; import useEmployeeStore from 'stores/employee'; -import useMyBranchStore from 'stores/my-branch'; -import { - dialog, - notify, - resetScrollBar, - capitalizeFirstLetter, -} from 'stores/utils'; +import { dialog } from 'stores/utils'; import { useNavigator } from 'src/stores/navigator'; import useFlowStore from 'stores/flow'; import { Status } from 'stores/types'; @@ -25,68 +15,21 @@ import { CustomerStats, Customer, CustomerBranch, - CustomerBranchCreate, CustomerType, } from 'stores/customer/types'; import { Employee, EmployeeHistory } from 'stores/employee/types'; -import { - EditButton, - DeleteButton, - SaveButton, - UndoButton, -} from 'components/button'; +import { SaveButton } from 'components/button'; import TabCustomer from './TabCustomer.vue'; -import ExpirationDate from 'components/03_customer-management/ExpirationDate.vue'; -import { AddressForm } from 'components/form'; -import BranchCard from 'src/components/01_branch-management/BranchCard.vue'; -import ItemCard from 'src/components/ItemCard.vue'; -import DrawerInfo from 'components/DrawerInfo.vue'; import FloatingActionButton from 'components/FloatingActionButton.vue'; import StatCardComponent from 'components/StatCardComponent.vue'; -import TooltipComponent from 'components/TooltipComponent.vue'; -import EmptyAddButton from 'components/AddButton.vue'; -import NoData from 'components/NoData.vue'; -import PaginationComponent from 'components/PaginationComponent.vue'; -import BasicInformation from 'components/03_customer-management/employee/BasicInformation.vue'; -import FormPerson from 'components/02_personnel-management/FormPerson.vue'; -import { EmployerFormBasicInfo, EmployerFormBranch } from './components'; import BranchPage from './BranchPage.vue'; -import FormEmployeePassport from 'components/03_customer-management/FormEmployeePassport.vue'; -import DialogForm from 'components/DialogForm.vue'; -import SideMenu from 'components/SideMenu.vue'; -import TableEmpoloyee from 'src/components/03_customer-management/TableEmpoloyee.vue'; -import HistoryEditComponent from 'src/components/03_customer-management/HistoryEditComponent.vue'; -import { calculateAge, toISOStringWithTimezone } from 'src/utils/datetime'; -import { runOcr, parseResultMRZ } from 'src/utils/ocr'; -import { formatAddress } from 'src/utils/address'; -import { - UploadFileGroup, - FormTm6, - NoticeJobEmployment, -} from 'components/upload-file'; -import { - columnsCustomer, - columnsEmployee, - uploadFileListEmployee, - columnsAttachment, - dialogCreateCustomerItem, -} from './constant'; +import { columnsCustomer, columnsEmployee } from './constant'; import { useCustomerForm, useEmployeeForm } from './form'; import { storeToRefs } from 'pinia'; -import ProfileBanner from 'components/ProfileBanner.vue'; -import ImageUploadDialog from 'components/ImageUploadDialog.vue'; -import FormEmployeeHealthCheck from 'components/03_customer-management/FormEmployeeHealthCheck.vue'; -import FormEmployeeWorkHistory from 'components/03_customer-management/FormEmployeeWorkHistory.vue'; -import FormEmployeeOther from 'components/03_customer-management/FormEmployeeOther.vue'; -import useOptionStore from 'stores/options'; -import { DialogContainer, DialogHeader } from 'components/dialog'; -import KebabAction from 'src/components/shared/KebabAction.vue'; + import { nextTick } from 'vue'; -import FormEmployeeVisa from 'components/03_customer-management/FormEmployeeVisa.vue'; -import PaginationPageSize from 'src/components/PaginationPageSize.vue'; -import { AddButton } from 'components/button'; import AdvanceSearch from 'src/components/shared/AdvanceSearch.vue'; import TabEmployee from './TabEmployee.vue'; @@ -97,48 +40,20 @@ const router = useRouter(); const flowStore = useFlowStore(); const navigatorStore = useNavigator(); const customerStore = useCustomerStore(); -const userBranchStore = useMyBranchStore(); const employeeStore = useEmployeeStore(); const customerFormStore = useCustomerForm(); const employeeFormStore = useEmployeeForm(); -const optionStore = useOptionStore(); -const ocrStore = useOcrStore(); -const mrz = ref>>(); - -const { - fetchListOfOptionBranch, - customerFormUndo, - customerConfirmUnsave, - deleteCustomerById, - validateTabField, - deleteCustomerBranchById, -} = customerFormStore; - -const { employeeFormUndo, employeeConfirmUnsave, deleteEmployeeById } = - employeeFormStore; - -const { - state: customerFormState, - currentFormData: customerFormData, - registerAbleBranchOption, - tabFieldRequired, -} = storeToRefs(customerFormStore); -const { - state: employeeFormState, - currentFromDataEmployee, - onCreateImageList, - statusEmployeeCreate, - refreshImageState, -} = storeToRefs(employeeFormStore); +const { state: customerFormState, currentFormData: customerFormData } = + storeToRefs(customerFormStore); +const { state: employeeFormState, statusEmployeeCreate } = + storeToRefs(employeeFormStore); const refTabCustomer = ref>(); const refTabEmployee = ref>(); // NOTE: Page Data const currentCustomer = ref(); -// const listCustomer = ref<(Customer & { branch: CustomerBranch[] })[]>([]); -// const listEmployee = ref([]); const hideStats = ref(false); const statsCustomerType = ref({ CORP: 0, @@ -158,27 +73,8 @@ const customerTypeSelected = ref<{ value: 'all', }); -// const customerNameInfo = computed(() => { -// if (customerFormData.value.customerBranch === undefined) return; - -// const name = -// locale.value === 'eng' -// ? `${customerFormData.value.customerBranch[0]?.firstNameEN} ${customerFormData.value.customerBranch[0]?.lastNameEN}` -// : `${customerFormData.value.customerBranch[0]?.firstName} ${customerFormData.value.customerBranch[0]?.lastName}`; -// return name || '-'; -// }); -// const currentBtnOpen = ref([]); const employeeStats = ref(0); const gridView = ref(false); -// const splitPercent = computed(() => ($q.screen.lt.md ? 0 : 15)); - -// const currentPageCustomer = ref(1); -// const maxPageCustomer = ref(1); -// const currentPageEmployee = ref(1); -// const maxPageEmployee = ref(1); -// const pageSize = ref(30); -// const dialogCustomerImageUpload = ref>(); -// const dialogEmployeeImageUpload = ref>(); // image const imageList = ref<{ selectedImage: string; list: string[] }>(); @@ -354,27 +250,6 @@ async function init() { watch(() => route.name, init); -// watch( -// [currentTab, currentStatus, inputSearch, searchDate], -// async ([tabName], [oldTabName]) => { -// if (tabName !== oldTabName) searchDate.value = []; -// if (tabName === 'employer') { -// currentPageCustomer.value = 1; -// currentBtnOpen.value = []; -// listCustomer.value = []; -// await fetchListCustomer(true); -// } -// if (tabName === 'employee') { -// currentPageEmployee.value = 1; -// listEmployee.value = []; -// await fetchListEmployee({ fetchStats: true }); -// } - -// customerFormState.value.currentCustomerId = undefined; -// flowStore.rotate(); -// }, -// ); - watch(locale, () => { customerTypeSelected.value = { label: `${customerTypeSelected.value.label}`, @@ -388,304 +263,6 @@ watch( ); onMounted(async () => await init()); -// const employeeHistoryDialog = ref(false); -// const employeeHistory = ref(); - -// async function fetchListCustomer(fetchStats = false, mobileFetch?: boolean) { -// const total = statsCustomerType.value.PERS + statsCustomerType.value.CORP; - -// const resultList = await customerStore.fetchList({ -// includeBranch: true, -// page: mobileFetch ? 1 : currentPageCustomer.value, -// pageSize: mobileFetch -// ? listCustomer.value.length + -// (total === listCustomer.value.length ? 1 : 0) -// : pageSize.value, -// status: -// currentStatus.value === 'All' -// ? undefined -// : currentStatus.value === 'ACTIVE' -// ? 'ACTIVE' -// : 'INACTIVE', -// query: inputSearch.value, -// startDate: searchDate.value[0], -// endDate: searchDate.value[1], -// customerType: ( -// { -// all: undefined, -// customerLegalEntity: CustomerType.Corporate, -// customerNaturalPerson: CustomerType.Person, -// } as const -// )[customerTypeSelected.value.value], -// }); - -// if (resultList) { -// maxPageCustomer.value = Math.ceil(resultList.total / pageSize.value); -// $q.screen.xs && !mobileFetch -// ? listCustomer.value.push(...resultList.result) -// : (listCustomer.value = resultList.result); -// } - -// if (fetchStats) { -// statsCustomerType.value = await customerStore -// .getStatsCustomer() -// .then((value) => (value ? value : { CORP: 0, PERS: 0 })); -// } -// } - -// async function fetchListEmployee(opt?: { -// fetchStats?: boolean; -// page?: number; -// pageSize?: number; -// customerId?: string; -// mobileFetch?: boolean; -// }) { -// const resultListEmployee = await employeeStore.fetchList({ -// customerId: opt?.customerId, -// page: opt -// ? opt.mobileFetch -// ? 1 -// : opt.page || currentPageEmployee.value -// : currentPageEmployee.value, -// pageSize: opt -// ? opt.mobileFetch -// ? listEmployee.value.length + -// (employeeStats.value === listEmployee.value.length ? 1 : 0) -// : opt.pageSize || pageSize.value -// : pageSize.value, -// status: -// currentStatus.value === 'All' -// ? undefined -// : currentStatus.value === 'ACTIVE' -// ? 'ACTIVE' -// : 'INACTIVE', -// query: inputSearch.value, -// passport: true, -// visa: true, -// startDate: searchDate.value[0], -// endDate: searchDate.value[1], -// }); -// if (resultListEmployee) { -// maxPageEmployee.value = Math.ceil( -// resultListEmployee.total / pageSize.value, -// ); -// $q.screen.xs && !(opt && opt.mobileFetch) -// ? listEmployee.value.push(...resultListEmployee.result) -// : (listEmployee.value = resultListEmployee.result); -// } - -// if (opt && opt.fetchStats) -// employeeStats.value = await employeeStore.getStatsEmployee(); -// } - -// async function toggleStatusEmployee( -// id: string, -// status: boolean, -// employeeName: string, -// ) { -// const res = await employeeStore.editById(id, { -// status: !status ? 'ACTIVE' : 'INACTIVE', -// firstNameEN: employeeName, -// }); -// if (res && employeeFormState.value.drawerModal) -// currentFromDataEmployee.value.status = res.status; - -// await fetchListEmployee({ mobileFetch: $q.screen.xs }); -// flowStore.rotate(); -// } - -// async function toggleStatusCustomer(id: string, status: boolean) { -// const res = await customerStore.editById(id, { -// status: !status ? 'ACTIVE' : 'INACTIVE', -// }); -// if (res && customerFormState.value.drawerModal) -// customerFormData.value.status = res.status; - -// await fetchListCustomer(false, $q.screen.xs); -// flowStore.rotate(); -// } -// async function openHistory(id: string) { -// const res = await employeeStore.getEditHistory(id); -// employeeHistory.value = res.reverse(); -// employeeHistoryDialog.value = true; -// } - -// async function editCustomerForm(id: string) { -// await customerFormStore.assignFormData(id); -// await fetchListOfOptionBranch(); -// await fetchImageList( -// id, -// customerFormData.value.selectedImage || '', -// 'customer', -// ); -// customerFormState.value.branchIndex = -1; -// customerFormState.value.dialogType = 'edit'; -// customerFormState.value.drawerModal = true; -// customerFormState.value.editCustomerId = id; -// } - -// async function editEmployeeFormPersonal(id: string) { -// await employeeFormStore.assignFormDataEmployee(id); -// await fetchImageList( -// id, -// currentFromDataEmployee.value.selectedImage || '', -// 'employee', -// ); - -// employeeFormState.value.isEmployeeEdit = true; -// employeeFormState.value.dialogType = 'edit'; -// employeeFormState.value.drawerModal = true; -// } - -// async function openSpecificCustomer(id: string) { -// await customerFormStore.assignFormData(id); -// await fetchImageList( -// id, -// customerFormData.value.selectedImage || '', -// 'customer', -// ); -// customerFormState.value.branchIndex = -1; -// customerFormState.value.drawerModal = true; -// customerFormState.value.editCustomerId = id; -// customerFormState.value.dialogType = 'info'; -// } - -// async function openSpecificEmployee(id: string) { -// await employeeFormStore.assignFormDataEmployee(id); -// await fetchImageList( -// id, -// currentFromDataEmployee.value.selectedImage || '', -// 'employee', -// ); -// employeeFormState.value.dialogType = 'info'; -// employeeFormState.value.drawerModal = true; -// } - -// TODO: When in employee form, if select address same as customer then auto fill - -// watch( -// () => employeeFormState.value.currentCustomerBranch, -// (e) => { -// if (!e) return; -// if (employeeFormState.value.formDataEmployeeSameAddr) { -// currentFromDataEmployee.value.address = e.address; -// currentFromDataEmployee.value.addressEN = e.addressEN; -// currentFromDataEmployee.value.provinceId = e.provinceId; -// currentFromDataEmployee.value.districtId = e.districtId; -// currentFromDataEmployee.value.subDistrictId = e.subDistrictId; -// } -// currentFromDataEmployee.value.customerBranchId = e.id; -// }, -// ); - -// watch( -// () => employeeFormState.value.formDataEmployeeSameAddr, -// (isSame) => { -// if (!employeeFormState.value.currentCustomerBranch) return; -// if (isSame) { -// currentFromDataEmployee.value.address = -// employeeFormState.value.currentCustomerBranch.address; -// currentFromDataEmployee.value.addressEN = -// employeeFormState.value.currentCustomerBranch.addressEN; -// currentFromDataEmployee.value.provinceId = -// employeeFormState.value.currentCustomerBranch.provinceId; -// currentFromDataEmployee.value.districtId = -// employeeFormState.value.currentCustomerBranch.districtId; -// currentFromDataEmployee.value.subDistrictId = -// employeeFormState.value.currentCustomerBranch.subDistrictId; -// } -// currentFromDataEmployee.value.customerBranchId = -// employeeFormState.value.currentCustomerBranch.id; -// }, -// ); - -// watch( -// () => employeeFormState.value.currentTab, -// () => { -// employeeFormState.value.isEmployeeEdit = false; -// }, -// ); - -// watch( -// () => currentFromDataEmployee.value.dateOfBirth, -// (v) => { -// const isEdit = -// employeeFormState.value.drawerModal && -// employeeFormState.value.isEmployeeEdit; -// let currentFormDate = v && toISOStringWithTimezone(new Date(v)); -// let currentDate: string = ''; - -// if (isEdit && employeeFormState.value.currentEmployee) { -// currentDate = toISOStringWithTimezone( -// new Date(employeeFormState.value.currentEmployee.dateOfBirth), -// ); -// } - -// if ( -// employeeFormState.value.dialogModal || -// (isEdit && currentFormDate !== currentDate) -// ) { -// const age = calculateAge( -// currentFromDataEmployee.value.dateOfBirth, -// 'year', -// ); -// if (currentFromDataEmployee.value.dateOfBirth && Number(age) < 15) { -// dialog({ -// color: 'warning', -// icon: 'mdi-alert', -// title: t('dialog.title.youngWorker15'), -// cancelText: t('general.edit'), -// persistent: true, -// message: t('dialog.message.youngWorker15'), - -// cancel: async () => { -// currentFromDataEmployee.value.dateOfBirth = null; -// return; -// }, -// }); -// } - -// if ( -// currentFromDataEmployee.value.dateOfBirth && -// Number(age) > 15 && -// Number(age) <= 18 -// ) { -// dialog({ -// color: 'warning', -// icon: 'mdi-alert', -// title: t('dialog.title.youngWorker18'), -// cancelText: t('general.cancel'), -// actionText: t('general.confirm'), -// persistent: true, -// message: t('dialog.message.youngWorker18'), -// action: () => {}, -// cancel: async () => { -// currentFromDataEmployee.value.dateOfBirth = null; -// return; -// }, -// }); -// } -// } -// }, -// ); - -// watch( -// () => customerFormData.value.image, -// () => { -// if (customerFormData.value.image !== null) -// customerFormState.value.isImageEdit = true; -// }, -// ); - -// watch( -// () => currentFromDataEmployee.value.image, -// () => { -// if (currentFromDataEmployee.value.image !== null) -// employeeFormState.value.isImageEdit = true; -// }, -// ); - -// const emptyCreateDialog = ref(false); diff --git a/src/pages/03_customer-management/TabCustomer.vue b/src/pages/03_customer-management/TabCustomer.vue index 1a0f85a2..85e80a03 100644 --- a/src/pages/03_customer-management/TabCustomer.vue +++ b/src/pages/03_customer-management/TabCustomer.vue @@ -8,6 +8,7 @@ import { useRoute, useRouter } from 'vue-router'; import BranchCard from 'src/components/01_branch-management/BranchCard.vue'; import KebabAction from 'src/components/shared/KebabAction.vue'; import TableEmpoloyee from 'src/components/03_customer-management/TableEmpoloyee.vue'; +import DrawerEmployee from 'src/components/03_customer-management/DrawerEmployee.vue'; import { DialogContainer, DialogHeader } from 'components/dialog'; import { EmployerFormBasicInfo, EmployerFormBranch } from './components'; import EmptyAddButton from 'components/AddButton.vue'; @@ -262,9 +263,16 @@ async function toggleStatusCustomer(id: string, status: boolean) { flowStore.rotate(); } -async function fetchListEmployee(customerId: string) { +async function fetchListEmployee(opt?: { + fetchStats?: boolean; + page?: number; + pageSize?: number; + customerId?: string; + mobileFetch?: boolean; +}) { + // ลูกจ้างภายในนายจ้าง const resultListEmployee = await employeeStore.fetchList({ - customerId: customerId, + customerId: opt.customerId, page: 1, pageSize: 9999, passport: true, @@ -662,7 +670,9 @@ onMounted(async () => { props.row.id; // TODO: - await fetchListEmployee(props.row.id); + await fetchListEmployee({ + customerId: props.row.id, + }); currentBtnOpen.map((v, i) => { if (i !== props.rowIndex) { @@ -1940,6 +1950,11 @@ onMounted(async () => { + +