refactor: เพิ่ม list ของ ลูกจ้าง

This commit is contained in:
Net 2024-07-08 16:38:17 +07:00
parent 461cd9fab8
commit 26d6c58390

View file

@ -6,6 +6,7 @@ import useCustomerStore from 'src/stores/customer';
import useEmployeeStore from 'src/stores/employee';
import useOptionStore from 'src/stores/options';
import useMyBranchStore from 'src/stores/my-branch';
import useUserStore from 'src/stores/user';
import { Status } from 'src/stores/types';
@ -65,10 +66,53 @@ const { t, locale } = useI18n();
const utilsStore = useUtilsStore();
const userCustomer = useCustomerStore();
const useMyBranch = useMyBranchStore();
const userStore = useUserStore();
const { fetchListOptionBranch } = useMyBranch;
const columns = [
const columnsEmployee = [
{
name: 'firstName',
align: 'left',
label: 'nameEmployee',
field: 'firstName',
sortable: true,
},
{
name: 'type',
align: 'left',
label: 'type',
field: 'type',
sortable: true,
},
{
name: 'formDialogInputNationality',
align: 'left',
label: 'formDialogInputNationality',
field: 'nationality',
},
{
name: 'formDialogEmployeeNRCNo',
align: 'left',
label: 'formDialogEmployeeNRCNo',
field: 'nrcNo',
},
{
name: 'formDialogInputAge',
align: 'left',
label: 'formDialogInputAge',
field: 'dateOfBirth',
},
{
name: 'branchLabel',
align: 'left',
label: 'branchLabel',
field: 'customerBranch',
},
] satisfies QTableProps['columns'];
const columnsCustomer = [
{
name: 'customerName',
align: 'left',
@ -77,7 +121,7 @@ const columns = [
sortable: true,
},
{
name: 'customerType',
name: 'type',
align: 'left',
label: 'type',
field: 'customerType',
@ -168,7 +212,7 @@ const fieldSelectedCustomer = ref<{ label: string; value: string }>({
value: 'all',
});
const fieldDisplay = ref<
const fieldDisplayEmployer = ref<
{
label: string;
value: string;
@ -181,7 +225,7 @@ const fieldDisplay = ref<
{
label: t('type'),
value: 'customerType',
value: 'type',
},
{
@ -199,15 +243,69 @@ const fieldDisplay = ref<
value: 'branchEmail',
},
]);
const fieldDisplayEmployee = ref<
{
label: string;
value: string;
}[]
>([
{
label: t('nameEmployee'),
value: 'firstName',
},
{
label: t('type'),
value: 'type',
},
{
label: t('formDialogInputNationality'),
value: 'formDialogInputNationality',
},
{
label: t('formDialogEmployeeNRCNo'),
value: 'formDialogEmployeeNRCNo',
},
{
label: t('formDialogInputAge'),
value: 'formDialogInputAge',
},
{
label: t('branchLabel'),
value: 'branchLabel',
},
]);
const fieldSelected = ref<
(
| 'customerName'
| 'customerType'
| 'type'
| 'personName'
| 'telephoneNo'
| 'branchEmail'
| 'firstName'
| 'formDialogInputNationality'
| 'formDialogEmployeeNRCNo'
| 'formDialogInputAge'
| 'branchLabel'
)[]
>(['customerName', 'customerType', 'personName', 'telephoneNo', 'branchEmail']);
>([
'customerName',
'type',
'personName',
'telephoneNo',
'branchEmail',
'firstName',
'formDialogInputNationality',
'formDialogInputNationality',
'formDialogEmployeeNRCNo',
'formDialogInputAge',
'branchLabel',
]);
const splitterModel = ref(15);
const modeView = ref(true);
@ -391,8 +489,8 @@ const inputFile = (() => {
return element;
})();
const listCustomer = ref<(Customer & { branch: CustomerBranch[] })[]>();
const listEmployee = ref();
const listCustomer = ref<(Customer & { branch: CustomerBranch[] })[]>([]);
const listEmployee = ref<Employee[]>([]);
const itemCard = [
{
@ -1124,7 +1222,7 @@ async function assignFormDataEmployee(id: string) {
};
formDataEmployee.value = {
image: foundEmployee.profileImageUrl,
image: null,
customerBranchId: foundEmployee.customerBranchId,
nrcNo: foundEmployee.nrcNo,
dateOfBirth: foundEmployee.dateOfBirth,
@ -1169,7 +1267,7 @@ async function assignFormDataEmployee(id: string) {
}
if (infoEmployeePersonCard.value) {
infoEmployeePersonCard.value[0].img = foundEmployee.profileImageUrl;
infoEmployeePersonCard.value[0].img = foundEmployee.profileImageUrl || '';
}
}
flowStore.rotate();
@ -1536,12 +1634,15 @@ watch([inputSearch, currentStatus], async () => {
{ label: $t('statusINACTIVE'), value: 'INACTIVE' },
]"
></q-select>
<q-select
v-if="modeView === false"
id="select-field"
for="select-field"
:options="fieldDisplay"
:options="
currentTab === 'employer'
? fieldDisplayEmployer
: fieldDisplayEmployee
"
:display-value="$t('displayField')"
v-model="fieldSelected"
option-label="label"
@ -1727,7 +1828,7 @@ watch([inputSearch, currentStatus], async () => {
bordered
:grid="modeView"
:rows="listCustomer"
:columns="columns"
:columns="columnsCustomer"
card-container-class=" q-col-gutter-md"
row-key="name"
:rows-per-page-options="[0]"
@ -1751,6 +1852,8 @@ watch([inputSearch, currentStatus], async () => {
<q-tr
:class="{
'app-text-muted': props.row.status === 'INACTIVE',
'status-active': props.row.status !== 'INACTIVE',
'status-inactive': props.row.status === 'INACTIVE',
}"
:props="props"
@click="
@ -1769,14 +1872,7 @@ watch([inputSearch, currentStatus], async () => {
<q-td v-if="fieldSelected.includes('customerName')">
<div class="row items-center">
<div
:class="{
'status-active':
props.row.status !== 'INACTIVE',
'status-inactive':
props.row.status === 'INACTIVE',
'branch-card__hq': props.row.isHeadOffice,
'branch-card__br': !props.row.isHeadOffice,
}"
:class="{}"
style="
width: 50px;
display: flex;
@ -1813,7 +1909,7 @@ watch([inputSearch, currentStatus], async () => {
</div>
</div>
</q-td>
<q-td v-if="fieldSelected.includes('customerType')">
<q-td v-if="fieldSelected.includes('type')">
<span
class="tags"
:class="{
@ -1838,7 +1934,7 @@ watch([inputSearch, currentStatus], async () => {
</q-td>
<q-td>
<q-btn
icon="mdi-eye"
icon="mdi-eye-outline"
size="sm"
dense
round
@ -2032,6 +2128,7 @@ watch([inputSearch, currentStatus], async () => {
},
],
}"
:disabled="props.row.status === 'INACTIVE'"
@history="openHistory(props.row.id)"
@update-card="
() => {
@ -2237,7 +2334,332 @@ watch([inputSearch, currentStatus], async () => {
class="col column justify-between q-px-md q-pt-md scroll"
v-if="listEmployee.length !== 0"
>
<!-- eeee -->
<q-table
flat
bordered
:grid="modeView"
:rows="listEmployee"
:columns="columnsEmployee"
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 class="surface-2" :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="{
'app-text-muted': props.row.status === 'INACTIVE',
'status-active': props.row.status !== 'INACTIVE',
'status-inactive': props.row.status === 'INACTIVE',
}"
:props="props"
@click="
() => {
currentCustomerName = props.row.customerName;
customerType = props.row.customerType;
currentCustomerUrlImage = props.row.imageUrl;
currentCustomerId = props.row.id;
const { branch, ...payload } = props.row;
currentCustomer = payload;
isMainPage = false;
}
"
>
<q-td v-if="fieldSelected.includes('firstName')">
<div class="row items-center">
<div
style="
width: 50px;
display: flex;
margin-bottom: var(--size-2);
"
>
<div class="branch-card__icon">
<q-avatar size="md">
<q-img
:src="
props.row.profileImageUrl ??
'/no-profile.png'
"
>
<template #error>
<q-img src="/no-profile.png" />
</template>
</q-img>
</q-avatar>
<!-- <q-icon
size="md"
style="scale: 0.8"
:name="props.row.imageUrl"
/> -->
</div>
</div>
<div class="col">
<div class="col">
{{
`${props.row.firstName} ${props.row.lastName}` ||
'-'
}}
</div>
<div class="col app-text-muted">
{{
`${props.row.firstNameEN} ${props.row.lastNameEN}` ||
'-'
}}
</div>
</div>
</div>
</q-td>
<q-td v-if="fieldSelected.includes('type')">
<span class="tags tags__parimary">
{{ $t('EMPLOYEE') }}
</span>
</q-td>
<q-td
v-if="
fieldSelected.includes('formDialogInputNationality')
"
>
{{ props.row.nationality || '-' }}
</q-td>
<q-td
v-if="
fieldSelected.includes('formDialogEmployeeNRCNo')
"
>
{{ props.row.nrcNo || '-' }}
</q-td>
<q-td
v-if="fieldSelected.includes('formDialogInputAge')"
>
{{ userStore.calculateAge(props.row.dateOfBirth) }}
</q-td>
<q-td
v-if="fieldSelected.includes('formDialogInputAge')"
>
<div class="row items-center">
<div class="col">
<div class="col">
{{ props.row.customerBranch.code }}
</div>
<div class="col app-text-muted">
{{
$i18n.locale === 'en-US' ? `${props.row.customerBranch.nameEN}` : `${props.row.customerBranch.name}`
}}
</div>
</div>
</div>
</q-td>
<q-td>
<q-btn
icon="mdi-eye-outline"
size="sm"
dense
round
flat
@click.stop="
() => {
openDialogInputForm('INFO', props.row.id) }
"
/>
<q-btn
icon="mdi-dots-vertical"
size="sm"
dense
round
flat
@click.stop
:key="props.row.id"
>
<q-menu class="bordered">
<q-list v-close-popup>
<q-item
:id="`view-detail-btn-${props.row.name}-view`"
@click.stop="
() => {
openDialogInputForm('INFO', props.row.id);
}
"
clickable
dense
class="row q-py-sm"
style="white-space: nowrap"
>
<q-icon
name="mdi-eye-outline"
class="col-3"
size="xs"
style="color: hsl(var(--green-6-hsl))"
/>
<span class="col-9 q-px-md flex items-center">
{{ $t('viewDetail') }}
</span>
</q-item>
<q-item
:id="`view-detail-btn-${props.row.name}-edit`"
clickable
dense
class="row q-py-sm"
style="white-space: nowrap"
@click="
() => {
openDialogInputForm(
'INFO',
props.row.id,
true,
);
}
"
>
<q-icon
name="mdi-pencil-outline"
class="col-3"
size="xs"
style="color: hsl(var(--cyan-6-hsl))"
/>
<span class="col-9 q-px-md flex items-center">
{{ $t('edit') }}
</span>
</q-item>
<q-item
:id="`view-detail-btn-${props.row.name}-delete`"
dense
:clickable="props.row.status === 'CREATED'"
class="row"
:class="{
'surface-3': props.row.status !== 'CREATED',
'app-text-muted':
props.row.status !== 'CREATED',
}"
style="white-space: nowrap"
@click="onDelete(props.row.id)"
>
<q-icon
name="mdi-trash-can-outline"
size="xs"
class="col-3"
:class="{
'app-text-negative':
props.row.status === 'CREATED',
}"
/>
<span class="col-9 q-px-md flex items-center">
{{ $t('delete') }}
</span>
</q-item>
<q-item dense>
<q-item-section class="q-py-sm">
<div class="q-pa-sm surface-2 rounded">
<q-toggle
:id="`view-detail-btn-${props.row.name}-status`"
dense
size="sm"
:label="
props.row.status !== 'INACTIVE'
? $t('switchOnLabel')
: $t('switchOffLabel')
"
@click="
async () => {
toggleStatusEmployee(
props.row.id,
props.row.status === 'ACTIVE'
? true
: false,
);
}
"
:model-value="
props.row.status !== 'INACTIVE'
"
/>
</div>
</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</q-td>
</q-tr>
</template>
<template v-slot:item="props">
<div class="col-3">
<PersonCard
:field-selected="fieldSelected"
history
:data="{
code: props.row.code,
name:
$i18n.locale === 'en-US'
? `${props.row.firstName} ${props.row.lastName} `.trim()
: `${props.row.firstNameEN} ${props.row.lastNameEN} `.trim(),
img: props.row.imageUrl,
male: props.row.gender === 'male',
female: props.row.gender === 'female',
detail: [
{
icon: 'mdi-passport',
value: props.row.nationality,
},
{
icon: 'mdi-clock-outline',
value: props.row.dateOfBirth
? userStore.calculateAge(
props.row.dateOfBirth,
) ?? ''
: '',
},
],
}"
:disabled="props.row.status === 'INACTIVE'"
@history="openHistory(props.row.id)"
@update-card="
(action) =>
openDialogInputForm(action, props.row.id, true)
"
@enter-card="
(action) =>
openDialogInputForm(action, props.row.id)
"
@delete-card="onDelete(props.row.id)"
@toggle-status="
toggleStatusEmployee(
props.row.id,
props.row.status === 'ACTIVE' ? true : false,
)
"
/>
</div>
</template>
</q-table>
</div>
<div
v-if="listEmployee.length !== 0"
@ -3643,6 +4065,10 @@ watch([inputSearch, currentStatus], async () => {
padding-inline: var(--size-2);
}
.tags__parimary {
--_color: var(--blue-6-hsl);
}
.tags__purple {
--_color: var(--violet-11-hsl);
}
@ -3651,6 +4077,10 @@ watch([inputSearch, currentStatus], async () => {
--_color: var(--teal-10-hsl);
}
.dark .tags__parimary {
--_color: var(--blue-12-hsl);
}
.dark .tags__purple {
--_color: var(--violet-10-hsl);
}
@ -3666,8 +4096,7 @@ watch([inputSearch, currentStatus], async () => {
.status-inactive {
--_branch-status-color: var(--red-4-hsl);
--_branch-badge-bg: var(--red-4-hsl);
filter: grayscale(1);
background-color: hsl(var(--gray-6-hsl) / 0.1);
filter: grayscale(0.5);
opacity: 0.5;
}