<!-- 选择题 -->
<template>
  <QuestionBase>
    <template #content>
      <div class="stem">
        <el-input
          v-if="data.property.stem_type === stemTypeList[0].value"
          v-model="data.stem"
          rows="3"
          resize="none"
          type="textarea"
          placeholder="输入题干"
        />

        <RichText v-if="data.property.stem_type === stemTypeList[1].value" v-model="data.stem" placeholder="输入题干" />

        <el-input
          v-show="data.property.is_enable_description"
          v-model="data.description"
          rows="3"
          resize="none"
          type="textarea"
          placeholder="输入描述"
        />
      </div>

      <div class="content">
        <label class="title-little">题目：</label>
        <el-input v-model="data.content" rows="3" resize="none" type="textarea" placeholder="输入汉字，用空格分开" />
      </div>
    </template>

    <template #property>
      <el-form :model="data.property">
        <el-form-item label="题干">
          <el-radio
            v-for="{ value, label } in stemTypeList"
            :key="value"
            v-model="data.property.stem_type"
            :label="value"
          >
            {{ label }}
          </el-radio>
        </el-form-item>
        <el-form-item label="题号">
          <el-input v-model="data.property.question_number" />
        </el-form-item>
        <el-form-item label-width="45px">
          <el-radio
            v-for="{ value, label } in questionNumberTypeList"
            :key="value"
            v-model="data.other.question_number_type"
            :label="value"
          >
            {{ label }}
          </el-radio>
        </el-form-item>
        <el-form-item label="描述">
          <el-radio
            v-for="{ value, label } in switchOption"
            :key="value"
            v-model="data.property.is_enable_description"
            :label="value"
          >
            {{ label }}
          </el-radio>
        </el-form-item>
        <el-form-item label="分值">
          <el-radio
            v-for="{ value, label } in scoreTypeList"
            :key="value"
            v-model="data.property.score_type"
            :label="value"
          >
            {{ label }}
          </el-radio>
        </el-form-item>
        <el-form-item label-width="45px">
          <el-input v-model="data.property.score" type="number" />
        </el-form-item>
        <el-form-item label="类型">
          <el-radio
            v-for="{ value, label } in learnTypeList"
            :key="value"
            v-model="data.property.learn_type"
            :label="value"
          >
            {{ label }}
          </el-radio>
        </el-form-item>
      </el-form>
    </template>
  </QuestionBase>
</template>

<script>
import UploadAudio from '../common/UploadAudio.vue';
import QuestionMixin from '../common/QuestionMixin.js';

import { scoreTypeList, changeOptionType } from '@/views/exercise_questions/data/common';
import { chineseData, getOption, learnTypeList } from '@/views/exercise_questions/data/chinese';

export default {
  name: 'ChineseQuestion',
  components: {
    UploadAudio,
  },
  mixins: [QuestionMixin],
  data() {
    return {
      learnTypeList,
      changeOptionType,
      data: JSON.parse(JSON.stringify(chineseData)),
    };
  },
  methods: {
    /**
     * 智能识别
     * @param {String} text 识别数据
     */
    recognition(text) {
      let arr = text
        .split(/[\r\n]/)
        .map((item) => item.trim())
        .filter((item) => item);

      if (arr.length > 0) {
        this.data.stem = arr[0];
        this.data.option_list = arr.slice(1).map((content) => getOption(content));
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
