134 lines
3.3 KiB
Vue
134 lines
3.3 KiB
Vue
<template>
|
|
<transition-group name="list" tag="div">
|
|
<QuestionItem
|
|
v-for="(question, index) in form.questions"
|
|
:key="index"
|
|
:allEmployees="allEmployees"
|
|
:allEmployeesgroupedbydep="allEmployeesgroupedbydep"
|
|
:checkremote="checkremote"
|
|
:findEmployeeById="findEmployeeById"
|
|
:handleSelectAll="handleSelectAll"
|
|
:index="index"
|
|
:onEmployeesChange="onEmployeesChange"
|
|
:onlyDepdict="onlyDepdict"
|
|
:question="question"
|
|
:questionTypes="questionTypes"
|
|
:removeQuestion="removeQuestion"
|
|
:rules="rules"
|
|
:spravURL="spravURL"
|
|
:isTest="isTest"
|
|
@update:question="form.questions[index] = $event"
|
|
/>
|
|
</transition-group>
|
|
</template>
|
|
|
|
<script>
|
|
import { computed } from 'vue';
|
|
import { checkremote } from '@/utils/universal_functions';
|
|
import { spravURL } from '@/utils/axios-api';
|
|
import QuestionItem from '@/components/vote/ConstructorVote/QuestionItem.vue';
|
|
|
|
export default {
|
|
components: { QuestionItem },
|
|
props: {
|
|
form: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
rules: {
|
|
type: Object,
|
|
default: () => ({
|
|
required: (value) => !!value || 'Это поле обязательно для заполнения',
|
|
}),
|
|
},
|
|
quests: {
|
|
type: Array,
|
|
default: () => [],
|
|
},
|
|
allEmployees: {
|
|
type: Array,
|
|
required: true,
|
|
},
|
|
allEmployeesgroupedbydep: {
|
|
type: Array,
|
|
required: true,
|
|
},
|
|
handleSelectAll: {
|
|
type: Function,
|
|
required: true,
|
|
},
|
|
onEmployeesChange: {
|
|
type: Function,
|
|
required: true,
|
|
},
|
|
findEmployeeById: {
|
|
type: Function,
|
|
required: true,
|
|
},
|
|
onlyDepdict: {
|
|
type: Array,
|
|
},
|
|
isTest: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
},
|
|
emits: ['update:form'],
|
|
setup(props, { emit }) {
|
|
const localForm = computed({
|
|
get() {
|
|
return props.form;
|
|
},
|
|
set(newForm) {
|
|
emit('update:form', newForm);
|
|
},
|
|
});
|
|
|
|
const questionTypes = [
|
|
{ name: 'Ввести вручную', choice: 'free' },
|
|
{ name: 'Выбрать сотрудника', choice: 'employee' },
|
|
];
|
|
|
|
const updateQuest = (index) => {
|
|
const updatedQuests = [...props.quests];
|
|
updatedQuests[index] = localForm.value.questions[index].text.trim().length > 0;
|
|
emit('update:quests', updatedQuests);
|
|
};
|
|
|
|
const removeQuestion = (index) => {
|
|
localForm.value.questions.splice(index, 1);
|
|
};
|
|
|
|
const addAnswer = (index) => {
|
|
const updatedQuestions = [...localForm.value.questions];
|
|
updatedQuestions[index] = {
|
|
...updatedQuestions[index],
|
|
answers: [...updatedQuestions[index].answers, { text: '', image: null }],
|
|
};
|
|
localForm.value = { ...localForm.value, questions: updatedQuestions };
|
|
};
|
|
|
|
const removeAnswer = (qIndex, aIndex) => {
|
|
const updatedQuestions = [...localForm.value.questions];
|
|
updatedQuestions[qIndex] = {
|
|
...updatedQuestions[qIndex],
|
|
answers: updatedQuestions[qIndex].answers.filter((_, i) => i !== aIndex),
|
|
};
|
|
localForm.value = { ...localForm.value, questions: updatedQuestions };
|
|
};
|
|
|
|
return {
|
|
localForm,
|
|
questionTypes,
|
|
updateQuest,
|
|
removeQuestion,
|
|
addAnswer,
|
|
removeAnswer,
|
|
checkremote,
|
|
spravURL,
|
|
isTest: props.isTest
|
|
};
|
|
},
|
|
};
|
|
</script>
|