fix [P-276]: изменения логики добавления сотрудников в конструкторе
This commit is contained in:
1 parent
04b3d9298e
commit
533d020c92
4 files changed
+127
-16
No files matched your search
@@ -45,7 +45,7 @@
|
|||||||
>
|
>
|
||||||
<template v-slot:label>
|
<template v-slot:label>
|
||||||
<div class="text-body-2 font-weight-bold">
|
<div class="text-body-2 font-weight-bold">
|
||||||
Голосование по отделам:
|
Голосование:
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<v-radio
|
<v-radio
|
||||||
@@ -59,7 +59,17 @@
|
|||||||
</v-radio>
|
</v-radio>
|
||||||
</v-radio-group>
|
</v-radio-group>
|
||||||
</div>
|
</div>
|
||||||
|
<v-alert
|
||||||
|
v-if="question.settings.onlyDep !== null"
|
||||||
|
type="info"
|
||||||
|
variant="tonal"
|
||||||
|
density="compact"
|
||||||
|
class="mt-2"
|
||||||
|
>
|
||||||
|
Все сотрудники будут автоматически добавлены в варианты ответов
|
||||||
|
</v-alert>
|
||||||
<v-autocomplete
|
<v-autocomplete
|
||||||
|
v-if="question.settings.onlyDep === null"
|
||||||
v-model="question.selectedEmployees"
|
v-model="question.selectedEmployees"
|
||||||
:items="allEmployeesgroupedbydep"
|
:items="allEmployeesgroupedbydep"
|
||||||
class="text-no-wrap"
|
class="text-no-wrap"
|
||||||
@@ -68,6 +78,8 @@
|
|||||||
item-value="id"
|
item-value="id"
|
||||||
label="Выберите сотрудников"
|
label="Выберите сотрудников"
|
||||||
multiple
|
multiple
|
||||||
|
chips
|
||||||
|
closable-chips
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@update:model-value="onEmployeeUpdate"
|
@update:model-value="onEmployeeUpdate"
|
||||||
>
|
>
|
||||||
@@ -79,9 +91,11 @@
|
|||||||
@update:model-value="toggleSelectAll"
|
@update:model-value="toggleSelectAll"
|
||||||
></v-checkbox>
|
></v-checkbox>
|
||||||
</template>
|
</template>
|
||||||
<template #selection="{ item }">
|
<template #selection="{ item, index }">
|
||||||
<v-chip
|
<v-chip
|
||||||
:prepend-avatar="checkremote(`${spravURL}${item.raw.login}.jpg`)"
|
:prepend-avatar="checkremote(`${spravURL}${item.raw.login}.jpg`)"
|
||||||
|
closable
|
||||||
|
@click:close="removeSelectedEmployee(item.raw.id)"
|
||||||
>
|
>
|
||||||
{{ item.raw.familyname }}
|
{{ item.raw.familyname }}
|
||||||
</v-chip>
|
</v-chip>
|
||||||
@@ -116,7 +130,17 @@
|
|||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
</v-autocomplete>
|
</v-autocomplete>
|
||||||
<transition-group name="list" tag="div">
|
<v-alert
|
||||||
|
v-if="question.settings.onlyDep !== null && question.answers.length > 0"
|
||||||
|
type="success"
|
||||||
|
variant="tonal"
|
||||||
|
density="compact"
|
||||||
|
class="mt-2"
|
||||||
|
>
|
||||||
|
Выбраны все {{ question.answers.length }} сотрудников
|
||||||
|
</v-alert>
|
||||||
|
|
||||||
|
<transition-group v-if="question.settings.onlyDep === null" name="list" tag="div">
|
||||||
<div
|
<div
|
||||||
v-for="(person, pIndex) in question.answers"
|
v-for="(person, pIndex) in question.answers"
|
||||||
:key="person"
|
:key="person"
|
||||||
@@ -125,6 +149,8 @@
|
|||||||
<v-col class="py-0" cols="7">
|
<v-col class="py-0" cols="7">
|
||||||
<v-chip
|
<v-chip
|
||||||
:prepend-avatar="checkremote(`${spravURL}${findEmployeeById(person.text)?.login}.jpg`)"
|
:prepend-avatar="checkremote(`${spravURL}${findEmployeeById(person.text)?.login}.jpg`)"
|
||||||
|
closable
|
||||||
|
@click:close="removeEmployeeAnswer(pIndex)"
|
||||||
>
|
>
|
||||||
{{ findEmployeeById(person.text)?.fio }}
|
{{ findEmployeeById(person.text)?.fio }}
|
||||||
</v-chip>
|
</v-chip>
|
||||||
@@ -158,7 +184,7 @@
|
|||||||
import QuestionHeader from '@/components/vote/ConstructorVote/QuestionHeader.vue';
|
import QuestionHeader from '@/components/vote/ConstructorVote/QuestionHeader.vue';
|
||||||
import QuestionSettings from '@/components/vote/ConstructorVote/QuestionSettings.vue';
|
import QuestionSettings from '@/components/vote/ConstructorVote/QuestionSettings.vue';
|
||||||
import AnswerList from '@/components/vote/ConstructorVote/AnswerList.vue';
|
import AnswerList from '@/components/vote/ConstructorVote/AnswerList.vue';
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -295,20 +321,77 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onEmployeeUpdate = (selected) => {
|
const onEmployeeUpdate = (selected) => {
|
||||||
|
// Filter existing answers to keep only those that are still selected
|
||||||
props.question.answers = props.question.answers.filter((e) =>
|
props.question.answers = props.question.answers.filter((e) =>
|
||||||
selected.includes(e.text)
|
selected.includes(e.text)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Add new answers for newly selected employees that don't have answers yet
|
||||||
|
const existingAnswerIds = props.question.answers.map(a => a.text);
|
||||||
|
const newEmployeeIds = selected.filter(id => !existingAnswerIds.includes(id));
|
||||||
|
|
||||||
|
// Add new answers for the newly selected employees
|
||||||
|
newEmployeeIds.forEach(employeeId => {
|
||||||
|
props.question.answers.push({ text: employeeId, image: null });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Also update the saved state for potential future switching between radio options
|
||||||
|
props.question._savedSelectedEmployees = [...selected];
|
||||||
|
props.question._savedAnswers = [...props.question.answers];
|
||||||
|
|
||||||
emit('update:question', props.question);
|
emit('update:question', props.question);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const removeSelectedEmployee = (employeeId) => {
|
||||||
|
// Находим индекс сотрудника в массиве selectedEmployees
|
||||||
|
const index = props.question.selectedEmployees.indexOf(employeeId);
|
||||||
|
if (index !== -1) {
|
||||||
|
// Удаляем сотрудника из списка выбранных
|
||||||
|
props.question.selectedEmployees.splice(index, 1);
|
||||||
|
// Находим соответствующий ответ и удаляем его
|
||||||
|
const answerIndex = props.question.answers.findIndex(a => a.text === employeeId);
|
||||||
|
if (answerIndex !== -1) {
|
||||||
|
props.question.answers.splice(answerIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обновляем сохраненное состояние
|
||||||
|
if (props.question._savedSelectedEmployees) {
|
||||||
|
const savedIndex = props.question._savedSelectedEmployees.indexOf(employeeId);
|
||||||
|
if (savedIndex !== -1) {
|
||||||
|
props.question._savedSelectedEmployees.splice(savedIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const savedAnswerIndex = props.question._savedAnswers?.findIndex(a => a.text === employeeId);
|
||||||
|
if (savedAnswerIndex !== -1) {
|
||||||
|
props.question._savedAnswers.splice(savedAnswerIndex, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emit('update:question', props.question);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const toggleSelectAll = (value) => {
|
const toggleSelectAll = (value) => {
|
||||||
props.handleSelectAll(value, props.index);
|
props.handleSelectAll(value, props.index);
|
||||||
emit('update:question', props.question);
|
emit('update:question', props.question);
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeEmployeeAnswer = (pIndex) => {
|
const removeEmployeeAnswer = (pIndex) => {
|
||||||
props.question.selectedEmployees.splice(pIndex, 1);
|
const employeeId = props.question.answers[pIndex].text;
|
||||||
|
|
||||||
|
props.question.selectedEmployees = props.question.selectedEmployees.filter(id => id !== employeeId);
|
||||||
props.question.answers.splice(pIndex, 1);
|
props.question.answers.splice(pIndex, 1);
|
||||||
|
|
||||||
|
// Обновляем сохраненное состояние
|
||||||
|
if (props.question._savedSelectedEmployees) {
|
||||||
|
props.question._savedSelectedEmployees = props.question._savedSelectedEmployees.filter(id => id !== employeeId);
|
||||||
|
|
||||||
|
const savedAnswerIndex = props.question._savedAnswers?.findIndex(a => a.text === employeeId);
|
||||||
|
if (savedAnswerIndex !== -1) {
|
||||||
|
props.question._savedAnswers.splice(savedAnswerIndex, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit('update:question', props.question);
|
emit('update:question', props.question);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -321,6 +404,27 @@ export default {
|
|||||||
return route.path && String(route.path).includes('test');
|
return route.path && String(route.path).includes('test');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Добавляем наблюдение за изменением выбора типа голосования
|
||||||
|
watch(() => props.question.settings.onlyDep, (newValue, oldValue) => {
|
||||||
|
// Если выбрано любое значение кроме null, автоматически выбрать всех сотрудников
|
||||||
|
if (newValue !== null) {
|
||||||
|
// Сохраняем выбранных сотрудников перед выбором "все"
|
||||||
|
if (oldValue === null) {
|
||||||
|
// Сохраняем текущий выбор сотрудников для возможного возврата к "произвольным сотрудникам"
|
||||||
|
props.question._savedSelectedEmployees = [...props.question.selectedEmployees];
|
||||||
|
props.question._savedAnswers = [...props.question.answers];
|
||||||
|
}
|
||||||
|
toggleSelectAll(true);
|
||||||
|
}
|
||||||
|
// Если переключаемся на "За произвольного сотрудника" (null) и у нас есть сохраненный выбор
|
||||||
|
else if (newValue === null && oldValue !== null && props.question._savedSelectedEmployees) {
|
||||||
|
// Восстанавливаем ранее сохраненный выбор сотрудников
|
||||||
|
props.question.selectedEmployees = [...props.question._savedSelectedEmployees];
|
||||||
|
props.question.answers = [...props.question._savedAnswers];
|
||||||
|
emit('update:question', props.question);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
resetAnswers,
|
resetAnswers,
|
||||||
addAnswer,
|
addAnswer,
|
||||||
@@ -328,6 +432,7 @@ export default {
|
|||||||
onEmployeeUpdate,
|
onEmployeeUpdate,
|
||||||
toggleSelectAll,
|
toggleSelectAll,
|
||||||
removeEmployeeAnswer,
|
removeEmployeeAnswer,
|
||||||
|
removeSelectedEmployee,
|
||||||
onEmployeesChange,
|
onEmployeesChange,
|
||||||
isTestRoute,
|
isTestRoute,
|
||||||
questionImagePreview,
|
questionImagePreview,
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ export default {
|
|||||||
const groupedAnswers = (question) => {
|
const groupedAnswers = (question) => {
|
||||||
const filtered = question.answers.filter(answer => answer.employee?.id !== accountStore.user.is_idEmployee);
|
const filtered = question.answers.filter(answer => answer.employee?.id !== accountStore.user.is_idEmployee);
|
||||||
|
|
||||||
if (question.settings.onlyDep === null) {
|
if (question.settings.onlyDep === null || question.settings.onlyDep === 'any') {
|
||||||
return groupByDepartment(filtered);
|
return groupByDepartment(filtered);
|
||||||
} else if (question.settings.onlyDep) {
|
} else if (question.settings.onlyDep) {
|
||||||
const byDepartment = filtered.filter(
|
const byDepartment = filtered.filter(
|
||||||
|
|||||||
@@ -263,12 +263,17 @@
|
|||||||
Голосование по отделам:
|
Голосование по отделам:
|
||||||
{{ onlyDepdict.find((e) => e.value === question.settings.onlyDep).name }}
|
{{ onlyDepdict.find((e) => e.value === question.settings.onlyDep).name }}
|
||||||
</div>
|
</div>
|
||||||
<p><strong>Выбранные сотрудники:</strong></p>
|
<div v-if="question.settings.onlyDep !== null">
|
||||||
<ul>
|
<p><strong>Выбрано {{ question.answers.length }} сотрудников</strong></p>
|
||||||
<li v-for="employeeId in question.answers" :key="employeeId">
|
</div>
|
||||||
{{ findEmployeeById(employeeId.text).fio }}
|
<div v-else>
|
||||||
</li>
|
<p><strong>Выбранные сотрудники:</strong></p>
|
||||||
</ul>
|
<ul>
|
||||||
|
<li v-for="employeeId in question.answers" :key="employeeId">
|
||||||
|
{{ findEmployeeById(employeeId.text).fio }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</v-card>
|
</v-card>
|
||||||
@@ -627,12 +632,13 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onlyDepdict = [
|
const onlyDepdict = [
|
||||||
{ name: 'За любого сотрудника', value: null },
|
{ name: 'За любого сотрудника', value: 'any' },
|
||||||
{
|
{
|
||||||
name: 'Кроме своего отдела',
|
name: 'Только за сотрудника из другого отдела',
|
||||||
value: false,
|
value: false,
|
||||||
},
|
},
|
||||||
{ name: 'Только за свой отдел', value: true },
|
{ name: 'Только за сотрудника из своего отдела', value: true },
|
||||||
|
{ name: 'За произвольного сотрудника (есть возможность добавить картинку)', value: null },
|
||||||
];
|
];
|
||||||
|
|
||||||
const quests = computed(() => form.value.questions.map((question) => question.text.length > 0));
|
const quests = computed(() => form.value.questions.map((question) => question.text.length > 0));
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
</v-tabs>
|
</v-tabs>
|
||||||
<v-tabs-window v-model="activeTab">
|
<v-tabs-window v-model="activeTab">
|
||||||
<v-tabs-window-item v-for="(question, questionIndex) in questions" :key="questionIndex">
|
<v-tabs-window-item v-for="(question, questionIndex) in questions" :key="questionIndex">
|
||||||
<v-row v-if="question.settings.onlyDep">
|
<v-row v-if="question.settings.onlyDep === true">
|
||||||
<v-col
|
<v-col
|
||||||
v-for="(winner, department) in getWinnersByDepartment(question).winnersByDepartment"
|
v-for="(winner, department) in getWinnersByDepartment(question).winnersByDepartment"
|
||||||
:key="department"
|
:key="department"
|
||||||
|
|||||||
Reference in new issue
Block a user