import { Tag, Image } from 'vant' import { computed, defineComponent, PropType, reactive } from 'vue' import { AnswerType, labelOptions, QuestionType } from '../../unit' import AnserTitle from '../anser-title' import AnswerAnalysis from '../answer-analysis' import UnitAudio from '../unit-audio' import styles from './index.module.less' // 单选题 - 多选题 export default defineComponent({ name: 'choice-question', props: { value: { type: Array, default: () => [] }, type: { type: String as PropType<'radio' | 'checkbox'>, default: 'radio' }, index: { // 题目是第几道 type: Number, default: 1 }, data: { type: Object, default: () => ({}) }, readOnly: { type: Boolean, default: false }, showRate: { tyep: Boolean, default: false }, showAnalysis: { // 是否显示解析 type: Boolean, default: false }, analysis: { type: Object, default: () => ({ message: '', topic: false, // 是否显示结果 userResult: true // 用户答题对错 }) } }, emits: ['update:value'], setup(props, { emit }) { const onSelect = (item: any) => { console.log(item, 'onSelect') if (props.readOnly) return const value: any = props.value || [] const result = { answerId: item.examinationQuestionAnswerId, answer: item.questionAnswer, answerExtra: item.questionExtra } console.log(result, 'onSelect') if (props.type === 'checkbox') { const tempIndex = value.findIndex( (c: any) => c.answerId === item.examinationQuestionAnswerId ) if (tempIndex >= 0) { value.splice(tempIndex, 1) emit('update:value', [...value]) } else { emit('update:value', [...value, result]) } } else { emit('update:value', [result]) } } const answers = computed(() => { const list: any = props.data.answers || [] const value: any = props.value || [] list.forEach((item: any) => { const tempIndex = value.findIndex( (c: any) => c.answerId === item.examinationQuestionAnswerId ) item.checked = tempIndex !== -1 ? true : false }) return list }) return () => ( <>