P-42 Мегалогика выбором сотрудников и отделов

Продолжить писать функцию
This commit is contained in:
iriska-gri committed 2024-05-30 16:56:58 +03:00
1 parent 5a9fa50127
commit 861647e87b
2 files changed
+254 -46

No files matched your search

@@ -0,0 +1,152 @@
<template>
<v-select
v-model="selectedStaff"
:items="staff"
label="Выберите из списка или найдите по ФИО"
item-title="department"
item-value="department"
multiple
hide-details
variant="outlined"
density="compact"
class="max-height-select"
return-object
>
<template v-slot:selection="{ item, index }">
<!-- <v-chip v-if="(index < 1) && allStaff">
<span>Выбраны все сотрудники</span>
</v-chip> -->
<v-chip>
<span> {{ item.value }}</span>
</v-chip>
<!-- <span
v-if="index === 2"
class="text-grey text-caption align-self-center"
>
(+{{ selectedFruits.length - 2 }} others)
</span> -->
</template>
<template v-slot:prepend-item>
<v-list-item @click="toggle" class="text-body-2">
<span class="text-body-2"> ВСЕ СОТРУДНИКИ </span>
<template v-slot:prepend>
{{selectedStaff}}
<v-checkbox-btn
:color="onePlusStaff ? 'indigo-darken-4' : undefined"
:indeterminate="onePlusStaff && !allStaff"
:model-value="allStaff"
></v-checkbox-btn>
</template>
</v-list-item>
<v-divider class="mt-2"></v-divider>
</template>
<template v-slot:item="{ props, item }">
<v-list-group v-bind="props" :value="item.raw.department">
<template v-slot:activator="{ props }">
<v-list-item
v-bind="props"
@click.stop=""
density="compact"
class="text-body-2"
>
</v-list-item>
</template>
<v-list-item
v-for="(x, i) in item.raw.staff"
:key="i"
:value="x.fio"
@click.stop="selectFIO(x, item.raw.id)"
density="compact"
>
<span class="text-body-2"> {{ x.fio }} </span>
</v-list-item>
</v-list-group>
<!-- <v-list-item v-bind="props" :title="item.raw.department">
<template v-slot:prepend>
<v-checkbox-btn
:color="onePlusStaff ? 'indigo-darken-4' : undefined"
:indeterminate="onePlusStaff && !allStaff"
:model-value="allStaff"
></v-checkbox-btn>
</template>
</v-list-item> -->
</template>
</v-select>
</template>
<script>
import { ref, onMounted, computed } from "vue";
export default {
setup() {
const staff = ref([
{
department: "ОКТП",
id: 1,
staff: [{ fio: "ГИС", id: 1 }, { fio: "СВВ", id: 2 }, { fio: "ФА", id: 3 }, { fio: "АА", id: 4 }],
},
{ department: "ОВТП", id: 2, staff: [{ fio: "ЩВ", id: 1 }, { fio: "ДК", id: 2 }] },
]);
const selectedStaff = ref([]);
const allStaff = computed(
() => selectedStaff.value.length === staff.value.length
);
const onePlusStaff = computed(() => selectedStaff.value.length > 0);
function toggle() {
if (allStaff.value) {
selectedStaff.value = [];
} else {
selectedStaff.value = staff.value.slice();
}
}
function selectFIO(user, dep) {
let ob = staff.value.find(el => el.id == dep)
ob['chek'] = false
let indx = selectedStaff.value.findIndex((i) => i.id == dep)
if (indx ==-1) {
selectedStaff.value.push(ob)
}
console.log(ob, 'ki')
}
return {
staff,
selectedStaff,
allStaff,
onePlusStaff,
selectFIO,
toggle,
};
},
};
</script>
<style>
.max-height-select .v-field__input {
max-height: 60px; /* Установите желаемую максимальную высоту */
overflow-y: auto; /* Добавьте прокрутку, если список превышает максимальную высоту */
overflow-x: hidden;
margin: 5px;
}
</style>