<template>
  <div v-loading="loading" style="min-height:400px;">
    <el-form
      v-if="isRender"
      ref="questions"
      size="small"
      :model="questionForm"
    >
      <QSFormItem
        v-for="question of questions"
        :key="question.Id"
        :question="question"
        :question-form="questionForm"
        @resetFormItemData="resetFormItemData"
      />
    </el-form>
  </div>

</template>

<script>

import { getQuestionView } from '@/api/dictionary'
import QSFormItem from './QSFormItem'
export default {
  name: 'QcQuestionPreview',
  components: {
    QSFormItem
  },
  props: {
    trialId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      questions: [],
      questionForm: {},
      isRender: false
    }
  },
  mounted() {
    this.getQuestions()
  },
  methods: {
    getQuestions() {
      this.loading = true
      var param = {
        trialId: this.trialId
      }
      getQuestionView(param).then(res => {
        res.Result.map((v) => {
          this.$set(this.questionForm, v.Id, '')
          if (v.Childrens.length > 0) {
            this.setChild(v.Childrens)
          }
        })
        this.questions = res.Result

        this.isRender = true
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    setChild(obj) {
      obj.forEach(i => {
        this.$set(this.questionForm, i.Id, '')
        if (i.Childrens && i.Childrens.length > 0) {
          this.setChild(i.Childrens)
        }
      })
    },
    resetFormItemData(v) {
      this.questionForm[v] = ''
    }
  }
}
</script>
<style lang="scss" scoped>
::-webkit-scrollbar {
    width: 7px;
    height: 7px;
  }
  ::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background: #d0d0d0;
  }
.tabContent{
  height:300px;
  overflow-y: auto;

}
</style>
