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>
@@ -12,39 +12,23 @@
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>
<span> {{ item.title }}</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>
<!-- <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> -->
<template v-slot:item="{ props, item }">
<v-list-group v-bind="props" :value="item.raw.department">
@@ -55,7 +39,6 @@
density="compact"
class="text-body-2"
>
<!-- <span class="text-body-2">{{item.title}}</span> -->
</v-list-item>
</template>
@@ -69,15 +52,6 @@
<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>
@@ -87,18 +61,29 @@ 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 }],
staff: [
{ fio: "ГИС", id: 1 },
{ fio: "СВВ", id: 2 },
{ fio: "ФА", id: 3 },
{ fio: "АА", id: 4 },
],
},
{
department: "ОВТП",
id: 2,
staff: [
{ fio: "ЩВ", id: 1 },
{ fio: "ДК", id: 2 },
],
},
{ department: "ОВТП", id: 2, staff: [{ fio: "ЩВ", id: 1 }, { fio: "ДК", id: 2 }] },
]);
const selectedStaff = ref([]);
const selectDepartnment = ref({});
const allStaff = computed(
() => selectedStaff.value.length === staff.value.length
@@ -115,16 +100,89 @@ export default {
}
function selectFIO(user, dep) {
let ob = staff.value.find(el => el.id == dep)
staff.value.forEach((e) => {
if (!selectDepartnment.value[e.id]) {
selectDepartnment.value[e.id] = [];
}
});
// selectDepartnment.forEach((e) => {
ob['chek'] = false
let indx = selectedStaff.value.findIndex((i) => i.id == dep)
if (indx ==-1) {
selectedStaff.value.push(ob)
}
console.log(ob, 'ki')
// if (!ob[e.author.id]) {
// ob[e.author.id] = 0
// }
// ob[e.author.id] += 1
// })
let ob = staff.value.find((el) => el.id == dep);
if(selectDepartnment.value[dep].includes(user.fio)) {
let inddep = selectDepartnment.value[dep].indexOf(user.fio)
selectDepartnment.value[dep].splice(inddep, 1);
}
else {
selectDepartnment.value[dep].push(user.fio)
// if(selectDepartnment.value[dep].length == ob.staff.length){
// selectDepartnment.value[dep]['dep'] = ob.department
// }
// else {
// selectDepartnment.value[dep]['dep'] = ''
// }
}
if (selectedStaff.value.includes(user.fio)) {
let index = selectedStaff.value.indexOf(user.fio);
selectedStaff.value.splice(index, 1);
}
else {
if (selectDepartnment.value[dep].length == ob.staff.length) {
selectedStaff.value.filter( ( el ) => !~selectDepartnment.value[dep].indexOf( el ) )
selectedStaff.value.push(ob.department)
}
else {
selectedStaff.value.push(user.fio);
}
//
}
// selectedStaff.value = selectDepartnment.value[dep]
// console.log(selectedStaff.value, '------------');
// selectedStaff.value.push(selectDepartnment.value[dep])
// if (selectedStaff.value.includes(user.fio)) {
// let index = selectedStaff.value.indexOf(user.fio);
// selectedStaff.value.splice(index, 1);
// let inddep = selectDepartnment.value[dep].indexOf(user.fio)
// selectDepartnment.value[dep].splice(inddep, 1);
// } else {
// selectDepartnment.value[dep].push(user.fio);
// if (selectDepartnment.value[dep].length == ob.staff.length) {
// selectDepartnment.value[dep] = []
// selectedStaff.value.push(ob.department);
// } else {
// selectedStaff.value.push(user.fio);
// }
// }
console.log(selectedStaff.value, 'selectedStaff.valueselectedStaff.value')
console.log(selectDepartnment.value, selectDepartnment.value[dep].length == ob.staff.length, "11111111111111111");
//
// userDep.department = ob.department
// userDep.staff = user
// ob['chek'] = false
// let indx = selectedStaff.value.findIndex((i) => i.id == dep)
// if (indx ==-1) {
// selectedStaff.value.push(ob)
// }
// console.log(userDep, 'ki')
}
return {
@@ -133,10 +191,8 @@ export default {
allStaff,
onePlusStaff,
selectFIO,
selectDepartnment,
toggle,
};
},
};