123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <template>
- <div :class="classes">
- <div class="elem-title" v-if="data.startNumber === data.parent.startNumber">
- {{ data.parent.topicName }}
- </div>
- <div class="elem-body">
- <ul
- class="group-item"
- v-for="(group, gindex) in questions"
- :key="gindex"
- :style="gindex !== questions.length - 1 ? groupGapStyles : null"
- >
- <li
- class="question-item"
- v-for="(question, qindex) in group"
- :key="qindex"
- :style="questionGapStyles"
- >
- <span
- class="option-item"
- v-for="(option, oindex) in question"
- :key="oindex"
- :style="optionGapStyles"
- >
- <i>{{ option }}</i>
- </span>
- </li>
- </ul>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: "elem-fill-question",
- props: {
- data: {
- type: Object
- }
- },
- computed: {
- classes() {
- return [
- "elem-fill-question",
- `elem-fill-question-${this.data.optionDirection}`
- ];
- },
- groupGapStyles() {
- return {
- marginRight: this.data.groupGap + "px"
- };
- },
- questionGapStyles() {
- return this.data.optionDirection === "vertical"
- ? { marginRight: this.data.questionGap + "px" }
- : { marginBottom: this.data.questionGap + "px" };
- },
- optionGapStyles() {
- const styles =
- this.data.optionDirection === "vertical"
- ? { marginBottom: this.data.optionGap + "px" }
- : { marginRight: this.data.optionGap + "px" };
- // styles.fontSize = this.data.fontSize;
- return styles;
- }
- },
- data() {
- return {
- questions: []
- };
- },
- methods: {
- parseQuestion(data) {
- let questionNo = data.startNumber;
- let questions = [];
- const choiceList = this.getChoiceList(data);
- if (data.questionDirection === "vertical") {
- const groupNum = Math.ceil(
- data.questionsCount / data.questionCountPerGroup
- );
- for (let i = 0; i < groupNum; i++) {
- questions[i] = [];
- const questionCountPerGroup =
- i === groupNum - 1
- ? data.questionsCount - data.questionCountPerGroup * i
- : data.questionCountPerGroup;
- for (let j = 0; j < questionCountPerGroup; j++) {
- questions[i][j] = [questionNo++, ...choiceList];
- }
- }
- } else {
- for (let i = 0; i < data.questionsCount; i++) {
- const groupIndex = i % data.groupPerLine;
- if (!questions[groupIndex]) questions[groupIndex] = [];
- questions[groupIndex].push([questionNo++, ...choiceList]);
- }
- }
- this.questions = questions;
- },
- getChoiceList(data) {
- if (data.isBoolean) {
- return data.booleanType.split(",");
- } else {
- return "abcdefghijklmnopqrstuv"
- .toUpperCase()
- .slice(0, data.optionCount)
- .split("");
- }
- }
- },
- watch: {
- data: {
- immediate: true,
- handler(val) {
- this.parseQuestion(val);
- }
- }
- }
- };
- </script>
|