refactor: worker select & employee nationality

This commit is contained in:
puriphatt 2024-10-03 18:10:40 +07:00
parent 8006314ce4
commit 9d745d8e52
5 changed files with 100 additions and 52 deletions

View file

@ -258,7 +258,7 @@ defineEmits<{
detail: [
{
icon: 'mdi-passport',
value: props.row.nationality,
value: optionStore.mapOption(props.row.nationality),
},
{

View file

@ -9,6 +9,7 @@ defineEmits<{
withDefaults(
defineProps<{
employeeAmount: number;
fallbackImg?: string;
rows: {
foreignRefNo: string;
employeeName: string;
@ -92,7 +93,11 @@ const columns = [
>
<template v-slot:img-column="{ props }">
<q-avatar class="q-mr-sm" size="md">
<q-img :src="props.row.imgUrl"></q-img>
<q-img :src="props.row.imgUrl" class="full-height full-width">
<template #error>
<q-img :src="fallbackImg" :ratio="1" />
</template>
</q-img>
<div
class="absolute-bottom-right"
style="
@ -121,7 +126,7 @@ const columns = [
class="surface-tab bordered rounded flex items-center justify-center q-mx-md"
style="width: 30px; height: 30px"
>
{{ employeeAmount }}
{{ employeeAmount || '0' }}
</div>
</div>
</div>

View file

@ -21,7 +21,7 @@ const props = withDefaults(
},
);
defineExpose({ select });
defineExpose({ select, assignSelect });
function select(item?: unknown, all?: boolean) {
if (all) {
@ -44,6 +44,19 @@ function select(item?: unknown, all?: boolean) {
} else selectedItem.value.push(item);
}
}
function assignSelect(to: unknown[], from: unknown[]) {
const existingItems = new Set(to);
for (let i = to.length - 1; i >= 0; i--) {
if (!from.includes(to[i])) {
to.splice(i, 1);
}
}
const newItems = from.filter((item) => !existingItems.has(item));
to.push(...newItems);
}
</script>
<template>
<section class="full-width column">