feat: 09 => select ready select all (order)

This commit is contained in:
puriphatt 2025-01-24 13:22:50 +07:00
parent 21452b6a9f
commit 52a0baa1a4
2 changed files with 86 additions and 16 deletions

View file

@ -318,6 +318,8 @@ function assignTempGroup() {
<div class="q-pa-md full-width"> <div class="q-pa-md full-width">
<TableEmployee <TableEmployee
checkbox-on checkbox-on
check-all
select-ready
:step-on="!creditNote" :step-on="!creditNote"
:statusOn="creditNote" :statusOn="creditNote"
:rows=" :rows="

View file

@ -12,12 +12,14 @@ import { RequestWork } from 'src/stores/request-list';
import { QuotationFull } from 'src/stores/quotations/types'; import { QuotationFull } from 'src/stores/quotations/types';
import { dateFormatJS, calculateAge } from 'src/utils/datetime'; import { dateFormatJS, calculateAge } from 'src/utils/datetime';
import { TaskStatus } from 'src/stores/task-order/types'; import { TaskStatus } from 'src/stores/task-order/types';
import { computed } from 'vue';
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
validate?: boolean; validate?: boolean;
checkboxOn?: boolean; checkboxOn?: boolean;
checkAll?: boolean; checkAll?: boolean;
selectReady?: boolean;
stepOn?: boolean; stepOn?: boolean;
statusOn?: boolean; statusOn?: boolean;
rows: QTableProps['rows']; rows: QTableProps['rows'];
@ -43,6 +45,12 @@ const selectedEmployee = defineModel<
default: [], default: [],
}); });
const selectedEmployeeInTable = computed(() => {
return selectedEmployee.value.filter((s) =>
props.rows.some((r) => s.id === r.id),
);
});
defineEmits<{ defineEmits<{
( (
e: 'changeAllStatus', e: 'changeAllStatus',
@ -98,6 +106,8 @@ function goToRequestList(id: string) {
} }
function handleCheckAll() { function handleCheckAll() {
if (disableCheckAll()) return;
const arr = JSON.parse(JSON.stringify(props.rows)); const arr = JSON.parse(JSON.stringify(props.rows));
const shouldExclude = (status: TaskStatus, validate: boolean) => const shouldExclude = (status: TaskStatus, validate: boolean) =>
validate validate
@ -120,13 +130,53 @@ function handleCheckAll() {
} | null; } | null;
taskStatus: TaskStatus; taskStatus: TaskStatus;
}, },
) => !shouldExclude(t.taskStatus, props.validate), ) =>
props.selectReady
? !selectedEmployee.value.some(
(v) => v._template?.id !== t._template?.id,
)
: !shouldExclude(t.taskStatus, props.validate),
); );
if (selectedEmployee.value.length !== selectableTasks.length) { const selectedIds = new Set(selectedEmployee.value.map((v) => v.id));
selectedEmployee.value = selectableTasks;
if (selectedEmployeeInTable.value.length !== selectableTasks.length) {
selectableTasks.forEach(
(
task: RequestWork & {
_template?: {
id: string;
templateName: string;
templateStepName: string;
step: number;
} | null;
taskStatus: TaskStatus;
},
) => {
if (!selectedIds.has(task.id)) {
selectedEmployee.value.push(task);
}
},
);
} else { } else {
selectedEmployee.value = []; const selectableTaskIds = new Set(
selectableTasks.map(
(
task: RequestWork & {
_template?: {
id: string;
templateName: string;
templateStepName: string;
step: number;
} | null;
taskStatus: TaskStatus;
},
) => task.id,
),
);
selectedEmployee.value = selectedEmployee.value.filter(
(task) => !selectableTaskIds.has(task.id),
);
} }
} }
@ -159,6 +209,14 @@ function handleCheck(
selectedEmployee.value.push(row); selectedEmployee.value.push(row);
} }
} }
function disableCheckAll() {
if (!props.selectReady) return false;
const firstTemplate = props.rows[0]?._template.id;
const hasDifferent = props.rows.some((r) => r._template.id !== firstTemplate);
return hasDifferent && selectedEmployee.value.length === 0;
}
</script> </script>
<template> <template>
<q-table <q-table
@ -212,10 +270,17 @@ function handleCheck(
<q-th v-if="checkboxOn" class="relative-position"> <q-th v-if="checkboxOn" class="relative-position">
<q-checkbox <q-checkbox
v-if="checkAll" v-if="checkAll"
:disable="disableCheckAll()"
:model-value=" :model-value="
selectedEmployee.length > 0 && selectedEmployeeInTable.length > 0 &&
selectedEmployee.length === selectedEmployeeInTable.length ===
(validate (selectReady
? rows.filter(
(t) =>
t._template.id ===
selectedEmployeeInTable[0]?._template?.id,
).length
: validate
? rows.filter( ? rows.filter(
(t) => (t) =>
t.taskStatus !== TaskStatus.Complete && t.taskStatus !== TaskStatus.Complete &&
@ -231,7 +296,10 @@ function handleCheck(
@click="handleCheckAll" @click="handleCheckAll"
size="sm" size="sm"
/> />
<div v-if="checkAll" class="absolute-right row items-center"> <div
v-if="checkAll && !selectReady"
class="absolute-right row items-center"
>
<q-btn <q-btn
flat flat
dense dense