<template>
  <ai-detail>
    <template slot="title">
      <ai-title title="课程详情" isShowBack isShowBottomBorder @onBackClick="cancel(false)">
      </ai-title>
    </template>
    <template slot="content">
      <ai-card title="基本信息">
        <template #content>
          <ai-wrapper
            label-width="120px">
            <ai-info-item label="题目描述" isLine :value="info.title"></ai-info-item>
            <ai-info-item label="题目类型" :value="dict.getLabel('qjQBType', info.type)"></ai-info-item>
            <ai-info-item label="正确答案" :value="info.answer"></ai-info-item>
            <ai-info-item label="题目选项" isLine>
              <div class="">
                <div class="options" v-for="(item, index) in info.items" :key="index">
                  <span>{{ item.sort }}：</span>
                  <span>{{ item.content }}</span>
                </div>
              </div>
            </ai-info-item>
            <ai-info-item label="答案解析" isLine>
              <AiArticle :value="info.analysis"></AiArticle>
            </ai-info-item>
          </ai-wrapper>
        </template>
      </ai-card>
    </template>
  </ai-detail>
</template>

<script>
  export default {
    name: 'Detail',

    props: {
      instance: Function,
      dict: Object,
      params: Object
    },

    data () {
      return {
        info: {}
      }
    },

    created () {
      this.dict.load('qjQBType').then(() => {
        this.getInfo(this.params.id)
      })
    },

    methods: {
      getInfo (id) {
        this.instance.post(`/app/appquestionbank/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = {
              ...res.data,
              answer: res.data.items.filter(v => v.checked === '1').map(v => v.content).join(',')
            }
          }
        })
      },

      cancel (isRefresh) {
        this.$emit('change', {
          type: 'List',
          isRefresh: !!isRefresh
        })
      }
    }
  }
</script>

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