<template>
	<div>
		<div class="exersices-content">
			<IconText :text="$t('evaluation.judge') + $t('evaluation.newExercise.stem')" :color="'#2d8cf0'" :icon="'ios-create'" style="margin-bottom:15px;"></IconText>
			<div>
				<div ref="editor" style="text-align:left"></div>
			</div>
		</div>
		<div class="exersices-option">
			<IconText :text="$t('evaluation.newExercise.option')" :color="'#FF871C'" :icon="'md-reorder'"></IconText>
			<RadioGroup v-model="trueAnswer" type="button" size="large">
				<Radio label="A">{{$t('evaluation.isTrue')}}</Radio>
				<Radio label="B">{{$t('evaluation.isFalse')}}</Radio>
			</RadioGroup>
		</div>
	</div>
</template>
<script>
	import E from 'wangeditor'
	import IconText from '@/components/evaluation/IconText.vue'
	export default {
		components: {
			IconText
		},
		props: ['editInfo'],
		data() {
			return {
				trueAnswer: 'A',
				defaultConfig: {
					uploadImgShowBase64: true,
					menus: this.$tools.wangEditorMenu
				},
				stemContent: '',
				stemEditor: null
			}
		},
		methods: {

		},
		mounted() {
			let stemEditor = new E(this.$refs.editor)
			stemEditor.config.onchange = (html) => {
				this.stemContent = html
			}
			stemEditor.config.uploadImgShowBase64 = true;
			this.$editorTools.initMyEditor(stemEditor,this)
			
			stemEditor.create()
			this.stemEditor = stemEditor
			
			if(this.editInfo && this.editInfo.question){
				console.log('判断题Mount编辑')
				this.stemEditor.txt.html(this.editInfo.question)
				this.stemContent = this.editInfo.question
				this.trueAnswer = this.editInfo.answer[0] === 'A' ? 'A' : 'B'
			}

			// 判断是否为编辑状态
			// if (Object.keys(this.editInfo).length > 0) {
			// 	this.stemEditor.txt.html(this.editInfo.question)
			// 	this.stemContent = this.editInfo.question
			// 	this.trueAnswer = this.editInfo.answer[0] === 'A' ? '正确' : '错误'
			// }
		},
		watch:{
			editInfo:{
				handler(n){
					console.log('主观题富文本接收到的数据')
					console.log(n)
					if(n){
						this.stemEditor.txt.html(this.editInfo.question)
						this.stemContent = this.editInfo.question
						this.trueAnswer = this.editInfo.answer[0] === 'A' ? 'A' : 'B'
					}
				}
			}
		}
	}
</script>
