2050 lines
75 KiB
Vue
2050 lines
75 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, ref, watch } from 'vue';
|
|
import { useQuasar } from 'quasar';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { storeToRefs } from 'pinia';
|
|
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';
|
|
import {
|
|
PaginationComponent,
|
|
PaginationPageSize,
|
|
ImageUploadDialog,
|
|
TooltipComponent,
|
|
ProfileBanner,
|
|
DialogForm,
|
|
DrawerInfo,
|
|
ItemCard,
|
|
SideMenu,
|
|
NoData,
|
|
} from 'src/components';
|
|
|
|
import useCustomerStore from 'src/stores/customer';
|
|
import useOptionStore from 'src/stores/options';
|
|
import { formatAddress } from 'src/utils/address';
|
|
import { Status } from 'src/stores/types';
|
|
import { useCustomerForm, useEmployeeForm } from './form';
|
|
import {
|
|
baseUrl,
|
|
setPrefixName,
|
|
waitAll,
|
|
dialog,
|
|
notify,
|
|
resetScrollBar,
|
|
capitalizeFirstLetter,
|
|
dialogCheckData,
|
|
canAccess,
|
|
} from 'src/stores/utils';
|
|
import {
|
|
CustomerStats,
|
|
Customer,
|
|
CustomerBranch,
|
|
CustomerBranchCreate,
|
|
CustomerType,
|
|
} from 'stores/customer/types';
|
|
import {
|
|
columnsCustomer,
|
|
columnsEmployee,
|
|
uploadFileListEmployee,
|
|
columnsAttachment,
|
|
dialogCreateCustomerItem,
|
|
} from './constant';
|
|
import { Employee } from 'src/stores/employee/types';
|
|
import { useNavigator } from 'src/stores/navigator';
|
|
import useFlowStore from 'src/stores/flow';
|
|
import useEmployeeStore from 'src/stores/employee';
|
|
|
|
const $q = useQuasar();
|
|
const route = useRoute();
|
|
const router = useRouter();
|
|
const flowStore = useFlowStore();
|
|
const navigatorStore = useNavigator();
|
|
const optionStore = useOptionStore();
|
|
const customerFormStore = useCustomerForm();
|
|
const customerStore = useCustomerStore();
|
|
const employeeStore = useEmployeeStore();
|
|
const employeeFormStore = useEmployeeForm();
|
|
const { t, locale } = useI18n();
|
|
const {
|
|
fetchListOfOptionBranch,
|
|
customerFormUndo,
|
|
customerConfirmUnsave,
|
|
deleteCustomerById,
|
|
validateTabField,
|
|
deleteCustomerBranchById,
|
|
} = customerFormStore;
|
|
const {
|
|
state: customerFormState,
|
|
currentFormData: customerFormData,
|
|
registerAbleBranchOption,
|
|
tabFieldRequired,
|
|
onCreateImageList,
|
|
} = storeToRefs(customerFormStore);
|
|
const {
|
|
state: employeeFormState,
|
|
currentFromDataEmployee,
|
|
statusEmployeeCreate,
|
|
refreshImageState,
|
|
} = storeToRefs(employeeFormStore);
|
|
|
|
const statsCustomerType = defineModel<CustomerStats>('statsCustomerType', {
|
|
default: {
|
|
CORP: 0,
|
|
PERS: 0,
|
|
},
|
|
});
|
|
|
|
const props = defineProps<{
|
|
currentTab: 'employee' | 'employer';
|
|
currentStatus: Status | 'All';
|
|
gridView: boolean;
|
|
inputSearch: string;
|
|
searchDate: string[];
|
|
fieldSelected: string[];
|
|
filterBusinessType: string;
|
|
filterAddress: {
|
|
provinceId: string;
|
|
districtId: string;
|
|
subDistrictId: string;
|
|
};
|
|
fetchImageList: (
|
|
id: string,
|
|
selectedName: string,
|
|
type: 'customer' | 'employee',
|
|
) => Promise<void>;
|
|
triggerChangeStatus: (
|
|
id: string,
|
|
status: string,
|
|
employeeName?: string,
|
|
) => void;
|
|
}>();
|
|
|
|
defineExpose({
|
|
openSpecificCustomer,
|
|
fetchListCustomer,
|
|
toggleStatusCustomer,
|
|
});
|
|
|
|
const emptyCreateDialog = ref(false);
|
|
const currentPageCustomer = ref<number>(1);
|
|
const maxPageCustomer = ref<number>(1);
|
|
const pageSize = ref<number>(30);
|
|
const currentBtnOpen = ref<boolean[]>([]);
|
|
const currentCustomer = ref<Customer>();
|
|
const listEmployee = ref<Employee[]>([]);
|
|
const listCustomer = ref<(Customer & { branch: CustomerBranch[] })[]>([]);
|
|
const dialogCustomerImageUpload = ref<InstanceType<typeof ImageUploadDialog>>();
|
|
|
|
const fieldCustomer = [
|
|
'all',
|
|
'customerLegalEntity',
|
|
'customerNaturalPerson',
|
|
] as const;
|
|
const customerTypeSelected = defineModel<{
|
|
label: string;
|
|
value: 'all' | 'customerLegalEntity' | 'customerNaturalPerson';
|
|
}>('customerTypeSelected');
|
|
const splitPercent = computed(() => ($q.screen.lt.md ? 0 : 15));
|
|
|
|
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 || '-';
|
|
});
|
|
|
|
async function createCustomerForm(customerType: 'CORP' | 'PERS') {
|
|
customerFormState.value.dialogModal = true;
|
|
customerFormState.value.dialogType = 'create';
|
|
customerFormData.value.customerType =
|
|
customerType === 'CORP' ? CustomerType.Corporate : CustomerType.Person;
|
|
}
|
|
|
|
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:
|
|
props.currentStatus === 'All'
|
|
? undefined
|
|
: props.currentStatus === 'ACTIVE'
|
|
? 'ACTIVE'
|
|
: 'INACTIVE',
|
|
query: props.inputSearch,
|
|
businessType: props.filterBusinessType,
|
|
province: props.filterAddress.provinceId || undefined,
|
|
district: props.filterAddress.districtId || undefined,
|
|
subDistrict: props.filterAddress.subDistrictId || undefined,
|
|
startDate: props.searchDate[0],
|
|
endDate: props.searchDate[1],
|
|
customerType: (
|
|
{
|
|
all: undefined,
|
|
customerLegalEntity: CustomerType.Corporate,
|
|
customerNaturalPerson: CustomerType.Person,
|
|
} as const
|
|
)[customerTypeSelected.value.value],
|
|
});
|
|
|
|
if (resultList) {
|
|
// currentPageCustomer.value = resultList.page;
|
|
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 editCustomerForm(id: string) {
|
|
await customerFormStore.assignFormData(id);
|
|
await fetchListOfOptionBranch();
|
|
await props.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 props.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 props.fetchImageList(
|
|
id,
|
|
customerFormData.value.selectedImage || '',
|
|
'customer',
|
|
);
|
|
customerFormState.value.branchIndex = -1;
|
|
customerFormState.value.drawerModal = true;
|
|
customerFormState.value.editCustomerId = id;
|
|
customerFormState.value.dialogType = 'info';
|
|
}
|
|
|
|
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 fetchListEmployee(opt?: {
|
|
fetchStats?: boolean;
|
|
page?: number;
|
|
pageSize?: number;
|
|
customerId?: string;
|
|
mobileFetch?: boolean;
|
|
}) {
|
|
// ลูกจ้างภายในนายจ้าง
|
|
const resultListEmployee = await employeeStore.fetchList({
|
|
customerId: opt.customerId,
|
|
page: 1,
|
|
pageSize: 9999,
|
|
passport: true,
|
|
visa: true,
|
|
});
|
|
if (resultListEmployee) {
|
|
listEmployee.value = resultListEmployee.result;
|
|
}
|
|
}
|
|
|
|
watch(
|
|
() => [
|
|
props.inputSearch,
|
|
props.searchDate,
|
|
props.currentStatus,
|
|
props.filterBusinessType,
|
|
props.filterAddress,
|
|
customerTypeSelected.value,
|
|
pageSize.value,
|
|
],
|
|
async () => {
|
|
if (props.currentTab === 'employer') {
|
|
currentPageCustomer.value = 1;
|
|
currentBtnOpen.value = [];
|
|
listCustomer.value = [];
|
|
await fetchListCustomer(true);
|
|
}
|
|
|
|
customerFormState.value.currentCustomerId = undefined;
|
|
flowStore.rotate();
|
|
},
|
|
{ deep: true },
|
|
);
|
|
|
|
watch(
|
|
() => customerFormData.value.image,
|
|
() => {
|
|
if (customerFormData.value.image !== null)
|
|
customerFormState.value.isImageEdit = true;
|
|
},
|
|
);
|
|
|
|
onMounted(async () => {
|
|
currentPageCustomer.value = 1;
|
|
currentBtnOpen.value = [];
|
|
listCustomer.value = [];
|
|
await fetchListCustomer(true);
|
|
});
|
|
</script>
|
|
<template>
|
|
<q-splitter
|
|
v-model="splitPercent"
|
|
:limits="[0, 100]"
|
|
class="col full-width"
|
|
before-class="overflow-hidden"
|
|
after-class="overflow-hidden"
|
|
:disable="$q.screen.lt.sm"
|
|
>
|
|
<template v-slot:before>
|
|
<div
|
|
class="column q-pa-md surface-1 full-height full-width"
|
|
style="gap: var(--size-1)"
|
|
>
|
|
<q-item
|
|
v-for="v in fieldCustomer"
|
|
v-close-popup
|
|
clickable
|
|
:key="v"
|
|
dense
|
|
class="no-padding items-center rounded full-width"
|
|
active-class="employer-active"
|
|
:active="customerTypeSelected.value === v"
|
|
@click="customerTypeSelected = { label: v, value: v }"
|
|
:id="`btn-${v}`"
|
|
>
|
|
<span class="q-px-md ellipsis">
|
|
{{
|
|
$t(
|
|
{
|
|
all: 'general.all',
|
|
customerLegalEntity: 'customer.employerLegalEntity',
|
|
customerNaturalPerson: 'customer.employerNaturalPerson',
|
|
}[v],
|
|
)
|
|
}}
|
|
</span>
|
|
</q-item>
|
|
</div>
|
|
</template>
|
|
|
|
<template v-slot:after>
|
|
<div class="column full-height no-wrap">
|
|
<!-- ไม่มีข้อมูล -->
|
|
<template
|
|
v-if="
|
|
statsCustomerType.CORP + statsCustomerType.PERS === 0 &&
|
|
currentTab === 'employer'
|
|
"
|
|
>
|
|
<TooltipComponent
|
|
v-if="canAccess('customer', 'edit')"
|
|
class="self-end q-ma-md"
|
|
:title="'general.noData'"
|
|
:caption="'general.clickToCreate'"
|
|
imgSrc="personnel-table-"
|
|
/>
|
|
|
|
<div class="row items-center justify-center" style="flex-grow: 1">
|
|
<EmptyAddButton
|
|
v-if="canAccess('customer', 'edit')"
|
|
:label="'general.add'"
|
|
:i18n-args="{
|
|
text: $t(`customer.${currentTab}`),
|
|
}"
|
|
@trigger="
|
|
() => {
|
|
if (currentTab === 'employer') emptyCreateDialog = true;
|
|
}
|
|
"
|
|
/>
|
|
<NoData v-else />
|
|
</div>
|
|
</template>
|
|
|
|
<!-- มีข้อมูล -->
|
|
<template
|
|
v-if="
|
|
listCustomer &&
|
|
statsCustomerType.PERS + statsCustomerType.CORP > 0 &&
|
|
currentTab === 'employer'
|
|
"
|
|
>
|
|
<div
|
|
v-if="listCustomer.length === 0"
|
|
class="row col full-width items-center justify-center"
|
|
style="min-height: 250px"
|
|
>
|
|
<NoData :not-found="!!inputSearch" />
|
|
</div>
|
|
|
|
<div
|
|
v-if="listCustomer.length !== 0"
|
|
class="column scroll q-pa-md col"
|
|
>
|
|
<q-infinite-scroll
|
|
:offset="10"
|
|
@load="
|
|
(_, done) => {
|
|
if (
|
|
$q.screen.gt.xs ||
|
|
currentPageCustomer === maxPageCustomer
|
|
)
|
|
return;
|
|
currentPageCustomer = currentPageCustomer + 1;
|
|
fetchListCustomer().then(() =>
|
|
done(currentPageCustomer >= maxPageCustomer),
|
|
);
|
|
}
|
|
"
|
|
>
|
|
<q-table
|
|
flat
|
|
bordered
|
|
:grid="gridView"
|
|
:rows="listCustomer"
|
|
:columns="columnsCustomer"
|
|
card-container-class="q-col-gutter-md"
|
|
row-key="name"
|
|
:rows-per-page-options="[0]"
|
|
hide-pagination
|
|
:visible-columns="fieldSelected"
|
|
>
|
|
<template v-slot:header="props">
|
|
<q-tr
|
|
style="background-color: hsla(var(--info-bg) / 0.07)"
|
|
:props="props"
|
|
>
|
|
<q-th
|
|
v-for="col in props.cols"
|
|
:key="col.name"
|
|
:props="props"
|
|
>
|
|
{{ $t(col.label) }}
|
|
</q-th>
|
|
<q-th auto-width />
|
|
</q-tr>
|
|
</template>
|
|
|
|
<template v-slot:body="props">
|
|
<q-tr
|
|
class="cursor-pointer"
|
|
:class="{
|
|
'app-text-muted': props.row.status === 'INACTIVE',
|
|
'status-active': props.row.status !== 'INACTIVE',
|
|
'status-inactive': props.row.status === 'INACTIVE',
|
|
}"
|
|
:id="`row-table-${props.row.id}`"
|
|
:props="props"
|
|
@click="
|
|
$router.push(
|
|
`/customer-management/${props.row.id}/branch`,
|
|
)
|
|
"
|
|
:style="
|
|
props.rowIndex % 2 !== 0
|
|
? $q.dark.isActive
|
|
? 'background: hsl(var(--gray-11-hsl)/0.2)'
|
|
: `background: #f9fafc`
|
|
: ''
|
|
"
|
|
>
|
|
<q-td
|
|
class="text-center"
|
|
v-if="fieldSelected.includes('orderNumber')"
|
|
>
|
|
{{
|
|
$q.screen.xs
|
|
? props.rowIndex + 1
|
|
: (currentPageCustomer - 1) * pageSize +
|
|
props.rowIndex +
|
|
1
|
|
}}
|
|
</q-td>
|
|
|
|
<q-td
|
|
v-if="fieldSelected.includes('titleName')"
|
|
class="ellipsis"
|
|
>
|
|
<div class="row items-center no-wrap">
|
|
<div
|
|
class="q-mr-sm"
|
|
style="display: flex; margin-bottom: var(--size-2)"
|
|
>
|
|
<div
|
|
:style="`
|
|
border-radius: 50%;
|
|
border-style: solid;
|
|
border-width: 2px;
|
|
border-color: hsl(var(${props.row.customerType === 'CORP' ? '--violet-11-hsl' : '--teal-10-hsl'}));
|
|
`"
|
|
>
|
|
<div class="branch-card__icon">
|
|
<q-avatar size="md">
|
|
<q-img
|
|
:src="
|
|
props.row.selectedImage
|
|
? `${baseUrl}/customer/${props.row.id}/image/${props.row.selectedImage}`
|
|
: `/images/customer-${props.row.customerType}-avartar-${props.row.customerType === 'PERS' ? props.row.branch[0].gender : 'male'}.png`
|
|
"
|
|
class="full-height full-width"
|
|
>
|
|
<template #error>
|
|
<q-img
|
|
:src="`/images/customer-${props.row.customerType}-avartar-${props.row.customerType === 'PERS' ? props.row.branch[0].gender : 'male'}.png`"
|
|
/>
|
|
</template>
|
|
</q-img>
|
|
</q-avatar>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col">
|
|
<div class="col">
|
|
{{
|
|
props.row.customerType === 'CORP'
|
|
? props.row.branch[0]?.registerName || '-'
|
|
: optionStore.mapOption(
|
|
props.row.branch[0].namePrefix,
|
|
) +
|
|
' ' +
|
|
props.row.branch[0]?.firstName +
|
|
' ' +
|
|
props.row.branch[0]?.lastName || '-'
|
|
}}
|
|
</div>
|
|
<div class="col app-text-muted">
|
|
{{
|
|
props.row.customerType === 'CORP'
|
|
? props.row.branch[0]?.registerNameEN || '-'
|
|
: capitalizeFirstLetter(
|
|
props.row.branch[0].namePrefix,
|
|
) +
|
|
' ' +
|
|
props.row.branch[0]?.firstNameEN +
|
|
' ' +
|
|
props.row.branch[0]?.lastNameEN || '-'
|
|
}}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</q-td>
|
|
|
|
<q-td
|
|
v-if="fieldSelected.includes('businessTypePure')"
|
|
style="max-width: 150px"
|
|
class="ellipsis"
|
|
>
|
|
{{
|
|
props.row.branch[0].businessType
|
|
? props.row.branch[0].businessType[
|
|
$i18n.locale === 'eng' ? 'nameEN' : 'name'
|
|
]
|
|
: '-'
|
|
}}
|
|
<q-tooltip>
|
|
{{
|
|
props.row.branch[0].businessType
|
|
? props.row.branch[0].businessType[
|
|
$i18n.locale === 'eng' ? 'nameEN' : 'name'
|
|
]
|
|
: '-'
|
|
}}
|
|
</q-tooltip>
|
|
</q-td>
|
|
|
|
<q-td
|
|
v-if="fieldSelected.includes('jobPosition')"
|
|
style="max-width: 150px"
|
|
class="ellipsis"
|
|
>
|
|
{{
|
|
props.row.branch.length !== 0
|
|
? props.row.branch[0].jobPosition !== null
|
|
? optionStore.mapOption(
|
|
props.row.branch[0].jobPosition,
|
|
)
|
|
: ''
|
|
: '-'
|
|
}}
|
|
|
|
<q-tooltip>
|
|
{{
|
|
props.row.branch.length !== 0
|
|
? props.row.branch[0].jobPosition !== null
|
|
? optionStore.mapOption(
|
|
props.row.branch[0].jobPosition,
|
|
)
|
|
: ''
|
|
: '-'
|
|
}}
|
|
</q-tooltip>
|
|
</q-td>
|
|
|
|
<q-td v-if="fieldSelected.includes('address')">
|
|
{{
|
|
formatAddress({
|
|
address: props.row.branch[0].address,
|
|
addressEN: props.row.branch[0].addressEN,
|
|
moo: props.row.branch[0].moo,
|
|
mooEN: props.row.branch[0].mooEN,
|
|
soi: props.row.branch[0].soi,
|
|
soiEN: props.row.branch[0].soiEN,
|
|
street: props.row.branch[0].street,
|
|
streetEN: props.row.branch[0].streetEN,
|
|
province: props.row.branch[0].province,
|
|
district: props.row.branch[0].district,
|
|
subDistrict: props.row.branch[0].subDistrict,
|
|
en: $i18n.locale === 'eng',
|
|
})
|
|
}}
|
|
<q-tooltip>
|
|
{{
|
|
formatAddress({
|
|
address: props.row.branch[0].address,
|
|
addressEN: props.row.branch[0].addressEN,
|
|
moo: props.row.branch[0].moo,
|
|
mooEN: props.row.branch[0].mooEN,
|
|
soi: props.row.branch[0].soi,
|
|
soiEN: props.row.branch[0].soiEN,
|
|
street: props.row.branch[0].street,
|
|
streetEN: props.row.branch[0].streetEN,
|
|
province: props.row.branch[0].province,
|
|
district: props.row.branch[0].district,
|
|
subDistrict: props.row.branch[0].subDistrict,
|
|
en: $i18n.locale === 'eng',
|
|
})
|
|
}}
|
|
</q-tooltip>
|
|
</q-td>
|
|
|
|
<q-td v-if="fieldSelected.includes('contactName')">
|
|
{{ props.row.branch[0]?.contactName || '-' }}
|
|
</q-td>
|
|
|
|
<q-td v-if="fieldSelected.includes('officeTel')">
|
|
{{ props.row.branch[0]?.officeTel || '-' }}
|
|
</q-td>
|
|
|
|
<q-td>
|
|
<q-btn
|
|
:id="`btn-eye-${props.row.branch[0].customerName || props.row.branch[0].firstName}`"
|
|
dense
|
|
flat
|
|
@click.stop="
|
|
async () => {
|
|
if (!currentBtnOpen[props.rowIndex]) {
|
|
customerFormState.currentCustomerId =
|
|
props.row.id;
|
|
|
|
// TODO:
|
|
await fetchListEmployee({
|
|
customerId: props.row.id,
|
|
});
|
|
|
|
currentBtnOpen.map((v, i) => {
|
|
if (i !== props.rowIndex) {
|
|
currentBtnOpen[i] = false;
|
|
}
|
|
});
|
|
}
|
|
currentBtnOpen[props.rowIndex] =
|
|
!currentBtnOpen[props.rowIndex];
|
|
}
|
|
"
|
|
>
|
|
<div class="row items-center">
|
|
<q-icon name="mdi-account-group-outline" />
|
|
<q-icon
|
|
class="btn-arrow-right"
|
|
:class="{
|
|
active: currentBtnOpen[props.rowIndex],
|
|
}"
|
|
size="xs"
|
|
name="mdi-chevron-right"
|
|
/>
|
|
</div>
|
|
</q-btn>
|
|
<q-btn
|
|
icon="mdi-eye-outline"
|
|
:id="`btn-eye-${props.row.branch[0].customerName || props.row.branch[0].firstName}`"
|
|
size="sm"
|
|
dense
|
|
round
|
|
flat
|
|
@click.stop="editCustomerForm(props.row.id)"
|
|
/>
|
|
|
|
<KebabAction
|
|
:hide-delete="!canAccess('customer', 'edit')"
|
|
:id-name="
|
|
props.row.branch[0].customerName ||
|
|
props.row.branch[0].firstName
|
|
"
|
|
:status="props.row.status"
|
|
@view="
|
|
() => {
|
|
const { branch, ...payload } = props.row;
|
|
currentCustomer = payload;
|
|
editCustomerForm(props.row.id);
|
|
}
|
|
"
|
|
@edit="
|
|
async () => {
|
|
await editCustomerForm(props.row.id);
|
|
customerFormState.branchIndex = 0;
|
|
}
|
|
"
|
|
@delete="
|
|
deleteCustomerById(
|
|
props.row.id,
|
|
async () =>
|
|
await fetchListCustomer(true, $q.screen.xs),
|
|
)
|
|
"
|
|
@change-status="
|
|
triggerChangeStatus(props.row.id, props.row.status)
|
|
"
|
|
/>
|
|
</q-td>
|
|
</q-tr>
|
|
|
|
<q-tr v-show="currentBtnOpen[props.rowIndex]" :props="props">
|
|
<q-td colspan="100%" style="padding: 16px">
|
|
<div class="text-center">
|
|
<TableEmpoloyee
|
|
in-table
|
|
:list-employee="listEmployee"
|
|
:columns-employee="columnsEmployee"
|
|
@view="
|
|
async (item: any) => {
|
|
employeeFormState.drawerModal = true;
|
|
employeeFormState.isEmployeeEdit = false;
|
|
employeeFormStore.assignFormDataEmployee(item.id);
|
|
await fetchImageList(
|
|
item.id,
|
|
item.selectedImage || '',
|
|
'employee',
|
|
);
|
|
}
|
|
"
|
|
/>
|
|
</div>
|
|
</q-td>
|
|
</q-tr>
|
|
</template>
|
|
|
|
<template v-slot:item="props">
|
|
<div class="col-12 col-md-6 column">
|
|
<BranchCard
|
|
i18n-key="customer.table"
|
|
class="surface-1 col"
|
|
:virtual-branch="false"
|
|
:id="`branch-card-${props.row.name}`"
|
|
:class="{
|
|
'cursor-pointer': props.row._count.branch !== 0,
|
|
}"
|
|
@click="
|
|
$router.push(
|
|
`/customer-management/${props.row.id}/branch`,
|
|
)
|
|
"
|
|
:metadata="props.row"
|
|
:color="
|
|
props.row.customerType === 'CORP' ? 'hq' : 'br-virtual'
|
|
"
|
|
:key="props.row.id"
|
|
:data="{
|
|
branchLabelName:
|
|
props.row.customerType === 'CORP'
|
|
? $i18n.locale === 'eng'
|
|
? props.row.branch[0]?.registerNameEN || '-'
|
|
: props.row.branch[0]?.registerName || '-'
|
|
: $i18n.locale === 'eng'
|
|
? props.row.branch[0]?.firstNameEN +
|
|
' ' +
|
|
props.row.branch[0]?.lastNameEN || '-'
|
|
: props.row.branch[0]?.firstName +
|
|
' ' +
|
|
props.row.branch[0]?.lastName || '-',
|
|
}"
|
|
:inactive="props.row.status === 'INACTIVE'"
|
|
:field-selected="
|
|
fieldSelected.filter((v) => {
|
|
return columnsCustomer.some((c) => c.name === v);
|
|
})
|
|
"
|
|
>
|
|
<template #image>
|
|
<q-avatar size="3rem">
|
|
<q-img
|
|
:src="
|
|
props.row.selectedImage
|
|
? `${baseUrl}/customer/${props.row.id}/image/${props.row.selectedImage}`
|
|
: `/images/customer-${props.row.customerType}-avartar-${props.row.customerType === 'PERS' ? props.row.branch[0].gender : 'male'}.png`
|
|
"
|
|
class="full-height full-width"
|
|
>
|
|
<template #error>
|
|
<q-img
|
|
:src="`/images/customer-${props.row.customerType}-avartar-${props.row.customerType === 'PERS' ? props.row.branch[0].gender : 'male'}.png`"
|
|
/>
|
|
</template>
|
|
</q-img>
|
|
<q-badge
|
|
class="absolute-bottom-right no-padding"
|
|
style="
|
|
border-radius: 50%;
|
|
min-width: 10px;
|
|
min-height: 10px;
|
|
"
|
|
:style="{
|
|
background: `var(--${props.row.status === 'INACTIVE' ? 'stone-5' : 'green-6'})`,
|
|
}"
|
|
></q-badge>
|
|
</q-avatar>
|
|
</template>
|
|
<template #data>
|
|
<div
|
|
class="row"
|
|
style="display: flex; padding-block: var(--size-2)"
|
|
>
|
|
<div class="col-12 q-py-sm row">
|
|
<span class="col-4 app-text-muted">
|
|
{{
|
|
props.row.customerType === 'CORP'
|
|
? $t('customer.form.legalPersonCode')
|
|
: $t('customer.form.cardNumber')
|
|
}}
|
|
</span>
|
|
<span class="col">
|
|
{{
|
|
props.row.customerType === 'CORP'
|
|
? props.row.branch[0]?.legalPersonNo
|
|
: props.row.branch[0]?.citizenId
|
|
}}
|
|
</span>
|
|
</div>
|
|
<div
|
|
class="col-12 q-py-sm row"
|
|
v-for="key in fieldSelected
|
|
.filter((v) => {
|
|
return (
|
|
v !== 'orderNumber' &&
|
|
v !== 'titleName' &&
|
|
v !== 'address' &&
|
|
v !== 'contactName' &&
|
|
columnsCustomer.some((c) => c.name === v)
|
|
);
|
|
})
|
|
.sort((lhs, rhs) => {
|
|
const fields = [
|
|
...columnsEmployee,
|
|
...columnsCustomer,
|
|
];
|
|
return (
|
|
fields.findIndex((i) => i.name === lhs) -
|
|
fields.findIndex((i) => i.name === rhs)
|
|
);
|
|
})"
|
|
:key="key"
|
|
>
|
|
<span class="col-4 app-text-muted">
|
|
{{ $t(`customer.table.${key}`) }}
|
|
</span>
|
|
<span class="col">
|
|
{{
|
|
key === 'businessTypePure'
|
|
? ($i18n.locale === 'eng'
|
|
? props.row.branch[0]?.businessType
|
|
?.nameEN
|
|
: props.row.branch[0]?.businessType
|
|
?.name) || '-'
|
|
: key === 'jobPosition'
|
|
? optionStore.mapOption(
|
|
props.row.branch[0]?.jobPosition,
|
|
)
|
|
: key === 'officeTel'
|
|
? props.row.branch[0]?.officeTel || '-'
|
|
: ''
|
|
}}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
<template v-slot:action>
|
|
<q-btn
|
|
icon="mdi-eye-outline"
|
|
:id="`btn-eye-${props.row.branch[0].customerName || props.row.branch[0].firstName}`"
|
|
size="sm"
|
|
dense
|
|
round
|
|
flat
|
|
@click.stop="editCustomerForm(props.row.id)"
|
|
/>
|
|
<KebabAction
|
|
:hide-delete="!canAccess('customer', 'edit')"
|
|
:status="props.row.status"
|
|
:id-name="props.row.name"
|
|
@view="
|
|
() => {
|
|
const { branch, ...payload } = props.row;
|
|
currentCustomer = payload;
|
|
editCustomerForm(props.row.id);
|
|
}
|
|
"
|
|
@edit="
|
|
async () => {
|
|
await editCustomerForm(props.row.id);
|
|
customerFormState.branchIndex = 0;
|
|
}
|
|
"
|
|
@delete="
|
|
deleteCustomerById(
|
|
props.row.id,
|
|
async () =>
|
|
await fetchListCustomer(true, $q.screen.xs),
|
|
)
|
|
"
|
|
@change-status="
|
|
triggerChangeStatus(props.row.id, props.row.status)
|
|
"
|
|
/>
|
|
</template>
|
|
</BranchCard>
|
|
</div>
|
|
</template>
|
|
</q-table>
|
|
<template v-slot:loading>
|
|
<div
|
|
v-if="
|
|
$q.screen.lt.sm && currentPageCustomer !== maxPageCustomer
|
|
"
|
|
class="row justify-center"
|
|
>
|
|
<q-spinner-dots color="primary" size="40px" />
|
|
</div>
|
|
</template>
|
|
</q-infinite-scroll>
|
|
</div>
|
|
|
|
<footer
|
|
v-if="listCustomer.length !== 0 && $q.screen.gt.xs"
|
|
class="row justify-between items-center q-px-md q-py-sm"
|
|
>
|
|
<div class="row col-4 items-center">
|
|
<div
|
|
class="app-text-muted"
|
|
style="width: 80px"
|
|
v-if="$q.screen.gt.sm"
|
|
>
|
|
{{ $t('general.recordPerPage') }}
|
|
</div>
|
|
|
|
<div><PaginationPageSize v-model="pageSize" /></div>
|
|
</div>
|
|
|
|
<div class="col-4 flex justify-center app-text-muted">
|
|
{{
|
|
$q.screen.gt.sm
|
|
? $t('general.recordsPage', {
|
|
resultcurrentPage: listCustomer.length,
|
|
total: statsCustomerType.PERS + statsCustomerType.CORP,
|
|
})
|
|
: $t('general.ofPage', {
|
|
current: listCustomer.length,
|
|
total: statsCustomerType.PERS + statsCustomerType.CORP,
|
|
})
|
|
}}
|
|
</div>
|
|
|
|
<div class="col-4 flex justify-end">
|
|
<PaginationComponent
|
|
v-model:current-page="currentPageCustomer"
|
|
v-model:max-page="maxPageCustomer"
|
|
:fetch-data="
|
|
async () => {
|
|
await fetchListCustomer();
|
|
flowStore.rotate();
|
|
}
|
|
"
|
|
/>
|
|
</div>
|
|
</footer>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
</q-splitter>
|
|
|
|
<!-- select type to add customer -->
|
|
<DialogForm
|
|
v-model:modal="emptyCreateDialog"
|
|
:title="$t('customer.employerType')"
|
|
hide-footer
|
|
no-app-box
|
|
width="40vw"
|
|
height="250px"
|
|
:close="
|
|
() => {
|
|
emptyCreateDialog = false;
|
|
onCreateImageList = { selectedImage: '', list: [] };
|
|
}
|
|
"
|
|
>
|
|
<div class="full-height row q-pa-md">
|
|
<ItemCard
|
|
class="col q-mx-sm full-height"
|
|
v-for="value in dialogCreateCustomerItem"
|
|
:key="value.text"
|
|
:icon="value.icon"
|
|
:text="value.text"
|
|
:icon-color="value.iconColor"
|
|
:bg-color="value.color"
|
|
@trigger="
|
|
() => {
|
|
createCustomerForm(
|
|
value.text === 'customer.employerLegalEntity' ? 'CORP' : 'PERS',
|
|
);
|
|
emptyCreateDialog = false;
|
|
}
|
|
"
|
|
/>
|
|
</div>
|
|
</DialogForm>
|
|
|
|
<!-- add customer -->
|
|
<DialogContainer
|
|
:model-value="customerFormState.dialogModal"
|
|
:on-open="
|
|
async () => {
|
|
customerFormStore.resetForm(customerFormState.dialogType === 'create');
|
|
onCreateImageList = { selectedImage: '', list: [] };
|
|
customerFormState.customerImageUrl = '';
|
|
await fetchListOfOptionBranch();
|
|
await customerFormStore.addCurrentCustomerBranch();
|
|
}
|
|
"
|
|
:on-close="
|
|
() => {
|
|
customerFormState.dialogModal = false;
|
|
onCreateImageList = { selectedImage: '', list: [] };
|
|
}
|
|
"
|
|
>
|
|
<template #header>
|
|
<DialogHeader
|
|
:title="
|
|
customerFormState.dialogType === 'create'
|
|
? $t(`general.add`, {
|
|
text: `${$t('customer.employer')} `,
|
|
})
|
|
: `${$t('customer.employer')} `
|
|
"
|
|
>
|
|
<template #title-after>
|
|
<span
|
|
:style="`color: hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/1)`"
|
|
>
|
|
:
|
|
{{
|
|
customerFormData.customerType === 'CORP'
|
|
? $t('customer.employerLegalEntity')
|
|
: $t('customer.employerNaturalPerson')
|
|
}}
|
|
</span>
|
|
</template>
|
|
</DialogHeader>
|
|
</template>
|
|
|
|
<div
|
|
:class="{
|
|
'q-mx-lg q-my-md': $q.screen.gt.sm,
|
|
'q-mx-md q-my-sm': !$q.screen.gt.sm,
|
|
}"
|
|
>
|
|
<ProfileBanner
|
|
v-if="customerFormData.customerBranch !== undefined"
|
|
active
|
|
hide-fade
|
|
prefix="dialog"
|
|
:fallback-cover="`/images/customer-${customerFormData.customerType}-banner-bg.jpg`"
|
|
:img="
|
|
customerFormState.customerImageUrl ||
|
|
`/images/customer-${customerFormData.customerType}-avartar-${customerFormData.customerType === 'PERS' ? customerFormData.customerBranch[0]?.gender : 'male'}.png`
|
|
"
|
|
:fallbackImg="`/images/customer-${customerFormData.customerType}-avartar-${customerFormData.customerType === 'PERS' ? customerFormData.customerBranch[0]?.gender : 'male'}.png`"
|
|
:color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/1)`"
|
|
:bg-color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/0.1)`"
|
|
:icon="
|
|
customerFormData.customerType === 'PERS'
|
|
? 'mdi-account-plus-outline'
|
|
: 'mdi-office-building-outline'
|
|
"
|
|
:title="
|
|
customerFormData.customerType === 'PERS'
|
|
? setPrefixName(
|
|
{
|
|
namePrefix: customerFormData.customerBranch[0]?.namePrefix,
|
|
firstName: customerFormData.customerBranch[0]?.firstName,
|
|
lastName: customerFormData.customerBranch[0]?.lastName,
|
|
firstNameEN: customerFormData.customerBranch[0]?.firstNameEN,
|
|
lastNameEN: customerFormData.customerBranch[0]?.lastNameEN,
|
|
},
|
|
{ locale },
|
|
)
|
|
: customerFormData.customerBranch[0]?.registerName
|
|
"
|
|
:caption="
|
|
customerFormData.customerType === 'PERS'
|
|
? `${customerFormData.customerBranch[0]?.firstNameEN} ${customerFormData.customerBranch[0]?.lastNameEN}`
|
|
: customerFormData.customerBranch[0]?.registerNameEN
|
|
"
|
|
@view="
|
|
() => {
|
|
customerFormState.imageDialog = true;
|
|
customerFormState.isImageEdit = false;
|
|
}
|
|
"
|
|
@edit="
|
|
() => {
|
|
if (customerFormState.editCustomerId) {
|
|
fetchImageList(
|
|
customerFormState.editCustomerId,
|
|
customerFormData.selectedImage,
|
|
'customer',
|
|
);
|
|
}
|
|
customerFormState.imageDialog =
|
|
customerFormState.isImageEdit = true;
|
|
}
|
|
"
|
|
/>
|
|
</div>
|
|
<div
|
|
style="flex: 1; width: 100%; overflow-y: auto"
|
|
id="customer-form"
|
|
:class="{
|
|
'q-px-lg q-pb-lg': $q.screen.gt.sm,
|
|
'q-px-md q-pb-sm': !$q.screen.gt.sm,
|
|
}"
|
|
>
|
|
<div class="col surface-1 full-height rounded bordered scroll row">
|
|
<div
|
|
class="col"
|
|
style="height: 100%; max-height: 100; overflow-y: auto"
|
|
v-if="$q.screen.gt.sm"
|
|
>
|
|
<div class="q-py-md q-pl-md q-pr-sm">
|
|
<SideMenu
|
|
:menu="[
|
|
{
|
|
name: $t('form.field.basicInformation'),
|
|
anchor: 'form-basic-info-customer',
|
|
},
|
|
{
|
|
name: $t('customer.form.group.branch'),
|
|
anchor: 'form-branch-customer-branch',
|
|
useBtn: true,
|
|
},
|
|
...(customerFormData.customerBranch?.map((v, i) => ({
|
|
name:
|
|
i === 0
|
|
? $t('customer.form.headQuarters.title')
|
|
: $t('customer.form.branch.title', {
|
|
name: i,
|
|
}),
|
|
anchor: `form-branch-customer-no-${i}`,
|
|
sub: true,
|
|
})) || []),
|
|
]"
|
|
background="transparent"
|
|
:active="{
|
|
background: 'hsla(var(--blue-6-hsl) / .2)',
|
|
foreground: 'var(--blue-6)',
|
|
}"
|
|
scroll-element="#customer-form-content"
|
|
>
|
|
<template v-slot:btn-form-branch-customer-branch>
|
|
<q-btn
|
|
dense
|
|
flat
|
|
icon="mdi-plus"
|
|
size="sm"
|
|
rounded
|
|
padding="0px 0px"
|
|
style="color: var(--stone-9)"
|
|
@click.stop="customerFormStore.addCurrentCustomerBranch()"
|
|
v-if="
|
|
customerFormState.branchIndex === -1 &&
|
|
!!customerFormState.editCustomerId &&
|
|
customerFormState.dialogType !== 'create'
|
|
"
|
|
:disabled="!customerFormState.readonly"
|
|
/>
|
|
</template>
|
|
</SideMenu>
|
|
</div>
|
|
</div>
|
|
<div
|
|
class="col-12 col-md-10"
|
|
:class="{
|
|
'q-py-md q-pr-md ': $q.screen.gt.sm,
|
|
'q-pa-sm': !$q.screen.gt.sm,
|
|
}"
|
|
id="customer-form-content"
|
|
style="height: 100%; max-height: 100%; overflow-y: auto"
|
|
>
|
|
<EmployerFormBasicInfo
|
|
prefixId="form"
|
|
v-if="
|
|
customerFormData.customerBranch !== undefined &&
|
|
customerFormData.customerBranch.length > 0
|
|
"
|
|
class="q-mb-xl"
|
|
:readonly="
|
|
(customerFormState.dialogType === 'edit' &&
|
|
customerFormState.readonly === true) ||
|
|
customerFormState.dialogType === 'info'
|
|
"
|
|
:action-disabled="customerFormState.branchIndex !== -1"
|
|
id="form-basic-info-customer"
|
|
:onCreate="customerFormState.dialogType === 'create'"
|
|
@edit="
|
|
((customerFormState.dialogType = 'edit'),
|
|
(customerFormState.readonly = false))
|
|
"
|
|
@cancel="() => customerFormUndo(false)"
|
|
@delete="
|
|
customerFormState.editCustomerId &&
|
|
deleteCustomerById(
|
|
customerFormState.editCustomerId,
|
|
async () => await fetchListCustomer(true, $q.screen.xs),
|
|
)
|
|
"
|
|
:customer-type="customerFormData.customerType"
|
|
v-model:registered-branch-id="customerFormData.registeredBranchId"
|
|
v-model:customer-name="customerNameInfo"
|
|
v-model:register-name="
|
|
customerFormData.customerBranch[0].registerName
|
|
"
|
|
v-model:citizen-id="customerFormData.customerBranch[0].citizenId"
|
|
v-model:legal-person-no="
|
|
customerFormData.customerBranch[0].legalPersonNo
|
|
"
|
|
v-model:business-type="
|
|
customerFormData.customerBranch[0].businessTypeId
|
|
"
|
|
v-model:job-position="
|
|
customerFormData.customerBranch[0].jobPosition
|
|
"
|
|
v-model:telephone-no="
|
|
customerFormData.customerBranch[0].telephoneNo
|
|
"
|
|
v-model:branch-options="registerAbleBranchOption"
|
|
/>
|
|
<div class="row q-col-gutter-sm" id="form-branch-customer-branch">
|
|
<div class="col-12 text-weight-bold text-body1 row items-center">
|
|
<q-icon
|
|
flat
|
|
size="xs"
|
|
class="q-pa-sm rounded q-mr-xs"
|
|
color="info"
|
|
name="mdi-briefcase-outline"
|
|
style="background-color: var(--surface-3)"
|
|
/>
|
|
<span>{{ $t('customer.form.group.branch') }}</span>
|
|
</div>
|
|
|
|
<template
|
|
v-for="(_, idx) in customerFormData.customerBranch"
|
|
:key="idx"
|
|
>
|
|
<q-form
|
|
class="full-width"
|
|
greedy
|
|
@submit.prevent="
|
|
async () => {
|
|
if (!customerFormData.customerBranch) return;
|
|
|
|
if (customerFormData.customerType === 'PERS') {
|
|
tabFieldRequired.main = [
|
|
'citizenId',
|
|
'namePrefix',
|
|
'firstName',
|
|
'firstNameEN',
|
|
'lastName',
|
|
'lastNameEN',
|
|
'gender',
|
|
'birthDate',
|
|
];
|
|
}
|
|
if (customerFormData.customerType === 'CORP') {
|
|
tabFieldRequired.main = ['legalPersonNo', 'registerName'];
|
|
}
|
|
let tapIsUndefined = validateTabField(
|
|
customerFormData.customerBranch?.[idx],
|
|
tabFieldRequired,
|
|
);
|
|
|
|
if (tapIsUndefined.length > 0) {
|
|
return dialog({
|
|
color: 'warning',
|
|
icon: 'mdi-alert',
|
|
title: t('dialog.title.incompleteDataEntry'),
|
|
actionText: t('general.ok'),
|
|
persistent: true,
|
|
message: t('dialog.message.incompleteDataEntry', {
|
|
tap: `${tapIsUndefined.map((v: string) => t(`customerBranch.tab.${v}`)).join(', ')}`,
|
|
}),
|
|
action: async () => {
|
|
return;
|
|
},
|
|
});
|
|
}
|
|
if (!customerFormData.customerBranch[idx].id) {
|
|
let res;
|
|
if (idx === 0) {
|
|
res =
|
|
await customerFormStore.submitFormCustomer(
|
|
onCreateImageList,
|
|
);
|
|
} else {
|
|
res = await customerStore.createBranch({
|
|
...customerFormData.customerBranch[idx],
|
|
customerId: customerFormState.editCustomerId || '',
|
|
});
|
|
}
|
|
if (res) {
|
|
customerFormState.readonly = true;
|
|
notify('create', $t('general.success'));
|
|
}
|
|
} else {
|
|
if (!customerFormState.editCustomerId) return;
|
|
await customerStore.editBranchById(
|
|
customerFormData.customerBranch[idx].id || '',
|
|
{
|
|
...customerFormData.customerBranch[idx],
|
|
id: undefined,
|
|
},
|
|
);
|
|
}
|
|
|
|
const uploadResult =
|
|
customerFormData.customerBranch[idx].file?.map(
|
|
async (v) => {
|
|
if (!v.file) return;
|
|
|
|
const ext = v.file.name.split('.').at(-1);
|
|
let filename = v.group + '-' + new Date().getTime();
|
|
if (ext) filename += `.${ext}`;
|
|
|
|
const res = await customerStore.putAttachment({
|
|
parentId:
|
|
customerFormData.customerBranch?.[idx].id || '',
|
|
file: v.file,
|
|
name: filename,
|
|
});
|
|
|
|
if (res) {
|
|
await customerFormStore.assignFormData(
|
|
customerFormState.editCustomerId,
|
|
);
|
|
}
|
|
},
|
|
) || [];
|
|
|
|
for (const r of uploadResult) await r;
|
|
|
|
await customerFormStore.assignFormData(
|
|
customerFormState.editCustomerId,
|
|
);
|
|
|
|
await fetchListCustomer(true, $q.screen.xs);
|
|
customerFormStore.resetForm();
|
|
}
|
|
"
|
|
>
|
|
<EmployerFormBranch
|
|
:index="idx"
|
|
prefixId="form"
|
|
v-if="customerFormData.customerBranch"
|
|
v-model:customer-branch="customerFormData.customerBranch[idx]"
|
|
:onCreate="customerFormState.dialogType === 'create'"
|
|
:customer-type="customerFormData.customerType"
|
|
:readonly="customerFormState.branchIndex !== idx"
|
|
:action-disabled="
|
|
!customerFormState.readonly ||
|
|
(customerFormState.branchIndex !== -1 &&
|
|
customerFormState.branchIndex !== idx)
|
|
"
|
|
@edit="() => (customerFormState.branchIndex = idx)"
|
|
@cancel="() => customerFormUndo(false)"
|
|
@delete="
|
|
async () => {
|
|
if (!customerFormState.editCustomerId) return;
|
|
|
|
if (idx === 0) {
|
|
deleteCustomerById(
|
|
customerFormState.editCustomerId,
|
|
async () =>
|
|
await fetchListCustomer(true, $q.screen.xs),
|
|
);
|
|
return;
|
|
}
|
|
if (!!customerFormData.customerBranch?.[idx].id) {
|
|
const action = await deleteCustomerBranchById(
|
|
customerFormData.customerBranch[idx].id || '',
|
|
);
|
|
if (action) {
|
|
await customerFormStore.assignFormData(
|
|
customerFormState.editCustomerId,
|
|
);
|
|
}
|
|
customerFormStore.resetForm();
|
|
}
|
|
}
|
|
"
|
|
@save="() => {}"
|
|
/>
|
|
</q-form>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</DialogContainer>
|
|
|
|
<!-- edit customer -->
|
|
<DrawerInfo
|
|
hide-action
|
|
v-model:drawer-open="customerFormState.drawerModal"
|
|
:title="
|
|
customerFormData.customerType === 'CORP' &&
|
|
customerFormData.customerBranch
|
|
? customerFormData.customerBranch[0]?.registerName || '-'
|
|
: (customerFormData.customerBranch[0]?.namePrefix
|
|
? $t(
|
|
'customer.form.prefix.' +
|
|
customerFormData.customerBranch[0]?.namePrefix,
|
|
) + ' '
|
|
: '') + customerNameInfo || '-'
|
|
"
|
|
:badge-label="
|
|
customerFormData.customerType === 'CORP'
|
|
? $t('customer.employerLegalEntity')
|
|
: $t('customer.employerNaturalPerson')
|
|
"
|
|
:badge-style="
|
|
customerFormData.customerType === 'CORP'
|
|
? `color: var(--${$q.dark.isActive ? 'violet-10' : 'violet-11'}); background: hsl(var(--${$q.dark.isActive ? 'violet-10-hsl' : 'violet-11-hsl'})/0.15)`
|
|
: `color: var(--${$q.dark.isActive ? 'teal-8' : 'teal-10'}); background: hsl(var(--${$q.dark.isActive ? 'teal-8-hsl' : 'teal-10-hsl'})/0.15)`
|
|
"
|
|
:close="
|
|
() => {
|
|
resetScrollBar('customer-form-content');
|
|
}
|
|
"
|
|
:submit="
|
|
async () => {
|
|
await customerFormStore.submitFormCustomer();
|
|
customerFormState.readonly = true;
|
|
notify('create', $t('general.success'));
|
|
await fetchListCustomer();
|
|
}
|
|
"
|
|
:show="
|
|
async () => {
|
|
// await fetchListOfOptionBranch();
|
|
// customerFormStore.resetForm(true);
|
|
}
|
|
"
|
|
:before-close="
|
|
() => {
|
|
if (customerFormStore.isFormDataDifferent()) {
|
|
customerConfirmUnsave();
|
|
return true;
|
|
} else {
|
|
fetchListCustomer();
|
|
customerFormState.branchIndex = -1;
|
|
customerFormStore.resetForm(true);
|
|
}
|
|
return false;
|
|
}
|
|
"
|
|
>
|
|
<div class="column full-height">
|
|
<div
|
|
:class="{
|
|
'q-mx-lg q-my-md': $q.screen.gt.sm,
|
|
'q-mx-md q-my-sm': !$q.screen.gt.sm,
|
|
}"
|
|
>
|
|
<ProfileBanner
|
|
v-if="customerFormData.customerBranch !== undefined"
|
|
:prefix="customerFormData.registeredBranchId"
|
|
:active="customerFormData.status !== 'INACTIVE'"
|
|
hide-fade
|
|
use-toggle
|
|
v-model:toggle-status="customerFormData.status"
|
|
:toggle-title="$t('status.title')"
|
|
:fallback-cover="`/images/customer-${customerFormData.customerType}-banner-bg.jpg`"
|
|
:img="
|
|
`${baseUrl}/customer/${customerFormState.editCustomerId}/image/${customerFormData.selectedImage}`.concat(
|
|
refreshImageState ? `?ts=${Date.now()}` : '',
|
|
) || null
|
|
"
|
|
:fallback-img="`/images/customer-${customerFormData.customerType}-avartar-${customerFormData.customerType === 'PERS' ? customerFormData.customerBranch[0]?.gender : 'male'}.png`"
|
|
:color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/1)`"
|
|
:bg-color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/0.1)`"
|
|
:icon="
|
|
customerFormData.customerType === 'PERS'
|
|
? 'mdi-account-plus-outline'
|
|
: 'mdi-office-building-outline'
|
|
"
|
|
:title="
|
|
customerFormData.customerType === 'PERS'
|
|
? setPrefixName(
|
|
{
|
|
namePrefix: customerFormData.customerBranch[0]?.namePrefix,
|
|
firstName: customerFormData.customerBranch[0]?.firstName,
|
|
lastName: customerFormData.customerBranch[0]?.lastName,
|
|
firstNameEN:
|
|
customerFormData.customerBranch[0]?.firstNameEN,
|
|
lastNameEN: customerFormData.customerBranch[0]?.lastNameEN,
|
|
},
|
|
{ locale },
|
|
)
|
|
: customerFormData.customerBranch[0]?.registerName
|
|
"
|
|
:caption="
|
|
customerFormData.customerType === 'PERS'
|
|
? `${customerFormData.customerBranch[0]?.firstNameEN} ${customerFormData.customerBranch[0]?.lastNameEN}`
|
|
: customerFormData.customerBranch[0]?.registerNameEN
|
|
"
|
|
@view="
|
|
() => {
|
|
customerFormState.imageDialog = true;
|
|
customerFormState.isImageEdit = false;
|
|
}
|
|
"
|
|
@edit="
|
|
customerFormState.imageDialog = customerFormState.isImageEdit = true
|
|
"
|
|
@update:toggle-status="
|
|
async (v) => {
|
|
if (!customerFormState.editCustomerId) return;
|
|
triggerChangeStatus(customerFormState.editCustomerId, v);
|
|
}
|
|
"
|
|
/>
|
|
</div>
|
|
|
|
<div
|
|
style="flex: 1; width: 100%; overflow-y: auto"
|
|
class="column"
|
|
id="customer-form"
|
|
:class="{
|
|
'q-px-lg q-pb-lg': $q.screen.gt.sm,
|
|
'q-px-md q-pb-sm': !$q.screen.gt.sm,
|
|
}"
|
|
>
|
|
<div class="col full-width surface-1 rounded bordered row">
|
|
<div class="col full-height scroll" v-if="$q.screen.gt.sm">
|
|
<div class="q-py-md q-pl-md q-pr-sm">
|
|
<SideMenu
|
|
:menu="[
|
|
{
|
|
name: $t('form.field.basicInformation'),
|
|
anchor: 'form-basic-info-customer',
|
|
},
|
|
{
|
|
name: $t('customer.form.group.branch'),
|
|
anchor: 'form-branch-customer-branch',
|
|
useBtn: true,
|
|
},
|
|
|
|
...(customerFormData.customerBranch?.map((v, i) => ({
|
|
name:
|
|
i === 0
|
|
? $t('customer.form.headQuarters.title')
|
|
: $t('customer.form.branch.title', {
|
|
name: i,
|
|
}),
|
|
anchor: `form-branch-customer-no-${i}`,
|
|
sub: true,
|
|
})) || []),
|
|
]"
|
|
background="transparent"
|
|
:active="{
|
|
background: 'hsla(var(--blue-6-hsl) / .2)',
|
|
foreground: 'var(--blue-6)',
|
|
}"
|
|
scroll-element="#customer-form-content"
|
|
>
|
|
<template v-slot:btn-form-branch-customer-branch>
|
|
<q-btn
|
|
dense
|
|
flat
|
|
icon="mdi-plus"
|
|
size="sm"
|
|
rounded
|
|
padding="0px 0px"
|
|
style="color: var(--stone-9)"
|
|
@click.stop="customerFormStore.addCurrentCustomerBranch()"
|
|
v-if="
|
|
customerFormState.branchIndex === -1 &&
|
|
!!customerFormState.editCustomerId &&
|
|
customerFormState.dialogType !== 'create'
|
|
"
|
|
:disabled="!customerFormState.readonly"
|
|
/>
|
|
</template>
|
|
</SideMenu>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
class="col-12 col-md-10"
|
|
:class="{
|
|
'q-py-md q-pr-md ': $q.screen.gt.sm,
|
|
'q-pa-sm': !$q.screen.gt.sm,
|
|
}"
|
|
id="customer-form-content"
|
|
style="height: 100%; max-height: 100%; overflow-y: auto"
|
|
>
|
|
<EmployerFormBasicInfo
|
|
v-if="
|
|
customerFormData.customerBranch !== undefined &&
|
|
customerFormData.customerBranch.length > 0
|
|
"
|
|
:readonly="
|
|
(customerFormState.dialogType === 'edit' &&
|
|
customerFormState.readonly === true) ||
|
|
customerFormState.dialogType === 'info'
|
|
"
|
|
:hide-action="customerFormData.status === 'INACTIVE'"
|
|
:action-disabled="customerFormState.branchIndex !== -1"
|
|
id="form-basic-info-customer"
|
|
:onCreate="customerFormState.dialogType === 'create'"
|
|
@edit="
|
|
((customerFormState.dialogType = 'edit'),
|
|
(customerFormState.readonly = false))
|
|
"
|
|
@cancel="() => customerFormUndo(false)"
|
|
@delete="
|
|
customerFormState.editCustomerId &&
|
|
deleteCustomerById(
|
|
customerFormState.editCustomerId,
|
|
async () => await fetchListCustomer(true, $q.screen.xs),
|
|
)
|
|
"
|
|
:customer-type="customerFormData.customerType"
|
|
v-model:registered-branch-id="customerFormData.registeredBranchId"
|
|
v-model:customer-name="customerNameInfo"
|
|
v-model:register-name="
|
|
customerFormData.customerBranch[0].registerName
|
|
"
|
|
v-model:citizen-id="customerFormData.customerBranch[0].citizenId"
|
|
v-model:legal-person-no="
|
|
customerFormData.customerBranch[0].legalPersonNo
|
|
"
|
|
v-model:business-type="
|
|
customerFormData.customerBranch[0].businessTypeId
|
|
"
|
|
v-model:job-position="
|
|
customerFormData.customerBranch[0].jobPosition
|
|
"
|
|
v-model:telephone-no="
|
|
customerFormData.customerBranch[0].telephoneNo
|
|
"
|
|
v-model:branch-options="registerAbleBranchOption"
|
|
/>
|
|
|
|
<div class="row q-col-gutter-sm" id="form-branch-customer-branch">
|
|
<div
|
|
class="col-12 text-weight-bold text-body1 row items-center q-mt-lg"
|
|
>
|
|
<q-icon
|
|
flat
|
|
size="xs"
|
|
class="q-pa-sm rounded q-mr-xs"
|
|
color="info"
|
|
name="mdi-briefcase-outline"
|
|
style="background-color: var(--surface-3)"
|
|
/>
|
|
<span>{{ $t('customer.form.group.branch') }}</span>
|
|
</div>
|
|
|
|
<template
|
|
v-for="(_, idx) in customerFormData.customerBranch"
|
|
:key="idx"
|
|
>
|
|
<q-form
|
|
class="full-width q-mb-xl"
|
|
v-if="customerFormData.customerBranch"
|
|
greedy
|
|
@submit.prevent="
|
|
async () => {
|
|
if (!customerFormData.customerBranch) return;
|
|
if (!customerFormState.editCustomerId) return;
|
|
|
|
if (customerFormData.customerType === 'PERS') {
|
|
tabFieldRequired.main = [
|
|
'citizenId',
|
|
'namePrefix',
|
|
'firstName',
|
|
'firstNameEN',
|
|
'lastName',
|
|
'lastNameEN',
|
|
'gender',
|
|
'birthDate',
|
|
];
|
|
}
|
|
if (customerFormData.customerType === 'CORP') {
|
|
tabFieldRequired.main = [
|
|
'legalPersonNo',
|
|
'registerName',
|
|
];
|
|
}
|
|
|
|
let tapIsUndefined = validateTabField(
|
|
customerFormData.customerBranch?.[idx],
|
|
tabFieldRequired,
|
|
);
|
|
|
|
if (tapIsUndefined.length > 0) {
|
|
return dialog({
|
|
color: 'warning',
|
|
icon: 'mdi-alert',
|
|
title: t('dialog.title.incompleteDataEntry'),
|
|
actionText: t('general.ok'),
|
|
persistent: true,
|
|
message: t('dialog.message.incompleteDataEntry', {
|
|
tap: `${tapIsUndefined.map((v: string) => t(`customerBranch.tab.${v}`)).join(', ')}`,
|
|
}),
|
|
action: async () => {
|
|
return;
|
|
},
|
|
});
|
|
}
|
|
if (!customerFormData.customerBranch[idx].id) {
|
|
await customerStore.createBranch({
|
|
...customerFormData.customerBranch[idx],
|
|
customerId: customerFormState.editCustomerId,
|
|
});
|
|
} else {
|
|
await customerStore.editBranchById(
|
|
customerFormData.customerBranch[idx].id || '',
|
|
{
|
|
...customerFormData.customerBranch[idx],
|
|
id: undefined,
|
|
},
|
|
);
|
|
}
|
|
|
|
customerFormData.customerBranch[idx].file?.forEach(
|
|
async (v) => {
|
|
if (!v.file) return;
|
|
|
|
const ext = v.file.name.split('.').at(-1);
|
|
let filename = v.group + '-' + new Date().getTime();
|
|
if (ext) filename += `.${ext}`;
|
|
|
|
const res = await customerStore.putAttachment({
|
|
parentId:
|
|
customerFormData.customerBranch?.[idx].id || '',
|
|
file: v.file,
|
|
name: filename,
|
|
});
|
|
|
|
if (res) {
|
|
await customerFormStore.assignFormData(
|
|
customerFormState.editCustomerId,
|
|
);
|
|
}
|
|
},
|
|
);
|
|
|
|
await customerFormStore.assignFormData(
|
|
customerFormState.editCustomerId,
|
|
);
|
|
|
|
customerFormStore.resetForm();
|
|
}
|
|
"
|
|
>
|
|
<EmployerFormBranch
|
|
prefix-id="info"
|
|
v-if="!!customerFormState.editCustomerId"
|
|
:index="idx"
|
|
:hide-action="customerFormData.status === 'INACTIVE'"
|
|
v-model:customer-branch="
|
|
customerFormData.customerBranch[idx]
|
|
"
|
|
:customer-type="customerFormData.customerType"
|
|
:action-disabled="
|
|
!customerFormState.readonly ||
|
|
(customerFormState.branchIndex !== -1 &&
|
|
customerFormState.branchIndex !== idx)
|
|
"
|
|
:hide-delete="!canAccess('customer', 'edit')"
|
|
:readonly="customerFormState.branchIndex !== idx"
|
|
@edit="() => (customerFormState.branchIndex = idx)"
|
|
@cancel="() => customerFormUndo(false)"
|
|
@delete="
|
|
async () => {
|
|
if (!!customerFormData.customerBranch?.[idx].id) {
|
|
const action = await deleteCustomerBranchById(
|
|
customerFormData.customerBranch[idx].id || '',
|
|
);
|
|
if (action) {
|
|
await customerFormStore.assignFormData(
|
|
customerFormState.editCustomerId,
|
|
);
|
|
}
|
|
customerFormStore.resetForm();
|
|
}
|
|
}
|
|
"
|
|
@save="() => {}"
|
|
/>
|
|
</q-form>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</DrawerInfo>
|
|
|
|
<!-- upload profile image -->
|
|
<ImageUploadDialog
|
|
ref="dialogCustomerImageUpload"
|
|
v-model:dialog-state="customerFormState.imageDialog"
|
|
v-model:file="customerFormData.image"
|
|
v-model:image-url="customerFormState.customerImageUrl"
|
|
v-model:data-list="customerFormState.imageList"
|
|
v-model:on-create-data-list="onCreateImageList"
|
|
:on-create="
|
|
customerFormState.dialogModal && !customerFormState.editCustomerId
|
|
"
|
|
:default-url="customerFormState.defaultCustomerImageUrl"
|
|
:hidden-footer="!customerFormState.isImageEdit"
|
|
@add-image="
|
|
async (v) => {
|
|
if (!v) return;
|
|
if (!customerFormState.editCustomerId) return;
|
|
await customerStore.addImageList(
|
|
v,
|
|
customerFormState.editCustomerId,
|
|
Date.now().toString(),
|
|
);
|
|
await fetchImageList(
|
|
customerFormState.editCustomerId,
|
|
customerFormData.selectedImage || '',
|
|
'customer',
|
|
);
|
|
}
|
|
"
|
|
@remove-image="
|
|
async (v) => {
|
|
if (!v) return;
|
|
if (!customerFormState.editCustomerId) return;
|
|
const name = v.split('/').pop() || '';
|
|
await customerStore.deleteImageByName(
|
|
customerFormState.editCustomerId,
|
|
name,
|
|
);
|
|
await fetchImageList(
|
|
customerFormState.editCustomerId,
|
|
customerFormData.selectedImage || '',
|
|
'customer',
|
|
);
|
|
}
|
|
"
|
|
@submit="
|
|
async (v) => {
|
|
console.log(customerFormState.editCustomerId);
|
|
if (
|
|
customerFormState.dialogModal &&
|
|
!customerFormState.editCustomerId
|
|
) {
|
|
console.log(1);
|
|
customerFormState.customerImageUrl = v;
|
|
customerFormState.imageDialog = false;
|
|
} else {
|
|
console.log(2);
|
|
refreshImageState = true;
|
|
customerFormData.selectedImage = v;
|
|
customerFormState.imageList
|
|
? (customerFormState.imageList.selectedImage = v)
|
|
: '';
|
|
customerFormState.customerImageUrl = `${baseUrl}/customer/${customerFormState.editCustomerId && customerFormState.editCustomerId}/image/${v}`;
|
|
console.log(customerFormData.selectedImage);
|
|
customerFormStore.resetForm();
|
|
console.log(customerFormData.selectedImage);
|
|
await customerFormStore.submitFormCustomer();
|
|
console.log(customerFormData.selectedImage);
|
|
customerFormState.imageDialog = false;
|
|
refreshImageState = false;
|
|
await fetchListCustomer();
|
|
console.log(customerFormData.selectedImage);
|
|
}
|
|
}
|
|
"
|
|
>
|
|
<template #title>
|
|
<span
|
|
v-if="
|
|
!customerFormState.dialogModal || customerFormState.editCustomerId
|
|
"
|
|
class="justify-center flex text-bold"
|
|
>
|
|
{{ $t('general.image') }}
|
|
{{
|
|
$i18n.locale === 'eng'
|
|
? customerFormData.customerType === 'CORP'
|
|
? customerFormData?.customerBranch?.[0].registerNameEN || '-'
|
|
: customerFormData?.customerBranch?.[0].firstNameEN +
|
|
' ' +
|
|
customerFormData?.customerBranch?.[0].lastNameEN || '-'
|
|
: customerFormData.customerType === 'CORP'
|
|
? customerFormData?.customerBranch?.[0].registerName || '-'
|
|
: customerFormData?.customerBranch?.[0].firstName +
|
|
' ' +
|
|
customerFormData?.customerBranch?.[0].lastName || '-'
|
|
}}
|
|
</span>
|
|
</template>
|
|
<template #error>
|
|
<div class="full-height full-width" style="background: white">
|
|
<div class="full-height full-width flex justify-center items-center">
|
|
<q-img
|
|
:src="`/images/customer-${customerFormData.customerType}-avartar-male.png`"
|
|
fit="contain"
|
|
style="height: 100%"
|
|
>
|
|
<template #error>
|
|
<span
|
|
class="full-width full-height column items-center justify-center"
|
|
>
|
|
<q-icon
|
|
size="3rem"
|
|
:name="
|
|
customerFormData.customerType === 'PERS'
|
|
? 'mdi-account-plus-outline'
|
|
: 'mdi-office-building-outline'
|
|
"
|
|
:style="`color: hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/1)`"
|
|
/>
|
|
</span>
|
|
</template>
|
|
</q-img>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</ImageUploadDialog>
|
|
|
|
<DrawerEmployee
|
|
:fetch-list-employee="fetchListEmployee"
|
|
:fetch-image-list="fetchImageList"
|
|
:current-tab="currentTab"
|
|
/>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.status-active {
|
|
--_branch-status-color: var(--green-6-hsl);
|
|
}
|
|
|
|
.status-inactive {
|
|
--_branch-status-color: var(--stone-5-hsl);
|
|
--_branch-badge-bg: var(--stone-5-hsl);
|
|
filter: grayscale(0.5);
|
|
opacity: 0.5;
|
|
}
|
|
|
|
.branch-card__icon {
|
|
background-color: hsla(var(--_branch-card-bg) / 0.15);
|
|
border-radius: 50%;
|
|
padding: var(--size-1);
|
|
position: relative;
|
|
transform: rotate(45deg);
|
|
|
|
&::after {
|
|
content: ' ';
|
|
display: block;
|
|
block-size: 0.5rem;
|
|
aspect-ratio: 1;
|
|
position: absolute;
|
|
border-radius: 50%;
|
|
right: -0.1rem;
|
|
top: calc(50% - 0.25rem);
|
|
bottom: calc(50% - 0.25rem);
|
|
background-color: hsla(var(--_branch-status-color) / 1);
|
|
}
|
|
|
|
& :deep(.q-avatar) {
|
|
transform: rotate(-45deg);
|
|
color: hsla(var(--_branch-card-bg) / 1);
|
|
}
|
|
}
|
|
|
|
.btn-arrow-right {
|
|
transform: rotate(0deg);
|
|
transition: transform 0.3s ease;
|
|
}
|
|
|
|
.btn-arrow-right.active {
|
|
transform: rotate(90deg);
|
|
transition: transform 0.3s ease;
|
|
}
|
|
|
|
.employer-active {
|
|
background-color: hsla(var(--info-bg) / 0.1);
|
|
color: hsl(var(--info-bg));
|
|
}
|
|
|
|
:deep(.q-table__middle.scroll) {
|
|
overflow: hidden;
|
|
}
|
|
</style>
|