+
liuyg
2021-10-09 df26c5424389cbd7fb1aa28a610b124cbac26c54
src/components/Subjects/PracticalOperation/index.vue
@@ -3,154 +3,149 @@
        <div class="subject-content">
            <div class="subject-title">
                {{ index }}
                <span class="subject-title-content"
                      v-html="subjectInfo.subjectName" />
        <span class="subject-title-content" v-html="subjectInfo.subjectName" />
                <span class="subject-title-content">
                    (&nbsp;实操题&nbsp;<span v-if="subjectInfo.score !== undefined && subjectInfo.score !== 0">&nbsp;{{subjectInfo.score}}分&nbsp;</span>)
          (&nbsp;实操题&nbsp;<span
            v-if="subjectInfo.score !== undefined && subjectInfo.score !== 0"
            >&nbsp;{{ subjectInfo.score }}分&nbsp;</span
          >)
                </span>
            </div>
            <ul class="subject-options"
      <ul
        class="subject-options"
                v-for="(option, index) in options"
                :key="option.id">
        :key="option.id"
      >
                <li class="subject-option pbox">
                    <span class="num"
                          @click="selectCheckbox($event, option)"> {{ userAnswer[index].value }} </span>
          <span class="num" @click="selectCheckbox($event, option)">
            {{ userAnswer[index].value }}
          </span>
                    <label :for="'option' + option.id">
                        <span class="subject-option-prefix">{{ option.optionName + '.' }}&nbsp;</span>
                        <span v-html="option.optionContent"
                              class="subject-option-prefix" />
            <span class="subject-option-prefix"
              >{{ option.optionName + "." }}&nbsp;</span
            >
            <span v-html="option.optionContent" class="subject-option-prefix" />
                    </label>
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
export default {
    name: 'MultipleChoices',
  name: "MultipleChoices",
    data () {
        return {
            subjectCount: 0,
            subjectInfo: {
                subjectName: '',
                score: 0
        subjectName: "",
        score: 0,
            },
            options: [],
            userAnswer: [],
            index: ''
        }
      index: "",
    };
    },
    watch: {
    },
  watch: {},
    methods: {
        getAnswer () {
            return this.userAnswer
      return this.userAnswer;
        },
        setAnswer (answer, option) {
            console.log(answer);
            if (answer != '') {
                this.userAnswer = answer
      if (answer != "") {
        this.userAnswer = answer;
            } else {
                this.userAnswer = []
                option.forEach(item => {
                    this.userAnswer.push({ key: item.optionName, value: '' })
                })
        this.userAnswer = [];
        option.forEach((item) => {
          this.userAnswer.push({ key: item.optionName, value: "" });
        });
            }
        },
        setSubjectInfo (subject, subjectCount, index) {
            this.subjectCount = subjectCount
            this.subjectInfo = subject
            if (subject.hasOwnProperty('examSubjectOptions')) {
                this.options = subject.examSubjectOptions
      this.subjectCount = subjectCount;
      this.subjectInfo = subject;
      if (subject.hasOwnProperty("examSubjectOptions")) {
        this.options = subject.examSubjectOptions;
            }
            if (subject.hasOwnProperty('answer')) {
                this.setAnswer(subject.answer, subject.examSubjectOptions)
      if (subject.hasOwnProperty("answer")) {
        this.setAnswer(subject.answer, subject.examSubjectOptions);
            }
            this.index = index + '.'
      this.index = index + ".";
        },
        getSubjectInfo () {
            this.subjectInfo.options = this.options
            return this.subjectInfo
      this.subjectInfo.options = this.options;
      return this.subjectInfo;
        },
        selectCheckbox ($event, option) {
            var flag = false;
            this.userAnswer.forEach(item => {
      this.userAnswer.forEach((item) => {
                if (item.value != "") {
                    flag = true
          flag = true;
                }
            })
      });
            this.userAnswer
      this.userAnswer;
            if (flag == true) {
                // 其中最少有一个有值的
                var onlyFlag = false;
                var onlyValue = '';
        var onlyValue = "";
                var ind = 0;
                this.userAnswer.forEach(item => {
                    if (item.value != '' && item.value > ind) {
                        ind = item.value
        this.userAnswer.forEach((item) => {
          if (item.value != "" && item.value > ind) {
            ind = item.value;
                    }
                })
        });
                this.userAnswer.forEach(item => {
        this.userAnswer.forEach((item) => {
                    if (item.key == option.optionName) {
                        if (item.value != '') {
                            onlyValue = item.value
                            onlyFlag = true
                            item.value = ''
            if (item.value != "") {
              onlyValue = item.value;
              onlyFlag = true;
              item.value = "";
                        } else {
                            item.value = ind + 1
              item.value = ind + 1;
                        }
                    }
                })
        });
                this.userAnswer.forEach(item => {
        this.userAnswer.forEach((item) => {
                    if (onlyFlag == true) {
                        if (item.value > onlyValue) {
                            item.value -= 1
              item.value -= 1;
                        }
                    }
                })
        });
            } else {
                // 全部都为空
                this.userAnswer.forEach(item => {
        this.userAnswer.forEach((item) => {
                    if (item.key == option.optionName) {
                        item.value = 1
            item.value = 1;
                    }
                })
        });
            }
            console.log(this.userAnswer)
      console.log(this.userAnswer, 123);
      for (var k in this.userAnswer) {
        console.log(this.userAnswer[k]);
      }
        },
        isChecked (optionName) {
            return this.userAnswer.includes(optionName)
        }
    }
}
      return this.userAnswer.includes(optionName);
    },
  },
};
</script>
<style lang="scss" scoped>
@import '../../../assets/css/subject.scss';
@import "../../../assets/css/subject.scss";
.pbox .num {
    // margin: 2px;