<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="info.showIndex"></ai-info-item>
            <ai-info-item label="状态" :value="dict.getLabel('qjExamineStatus', info.examineStatus)"></ai-info-item>
            <ai-info-item label="已学习人数" :value="info.learnerNumber"></ai-info-item>
            <ai-info-item label="评论数" :value="info.msgCount"></ai-info-item>
            <ai-info-item label="课程类型" :value="dict.getLabel('qjCourseType', info.courseType)"></ai-info-item>
            <ai-info-item label="正文" v-if="info.courseType === '0'" isLine>
              <AiArticle :value="info.content"></AiArticle>
            </ai-info-item>
            <ai-info-item v-if="info.courseType === '0'" isLine label="封面">
              <ai-uploader
                disabled
                :value="[{
                  url: info.pictureUrl
                }]"
                :limit="1">
              </ai-uploader>
            </ai-info-item>
            <ai-info-item v-if="info.courseType === '1'" label="视频时长" :value="info.videoDuration"></ai-info-item>
            <ai-info-item v-if="info.courseType === '1'" isLine label="视频">
              <video style="width:100%; height:100%; object-fit: fill;" :src="info.videoUrl" controls></video>
            </ai-info-item>
            <ai-info-item v-if="info.courseType === '1'" isLine label="视频封面">
              <ai-uploader
                disabled
                :value="[{
                  url: info.pictureUrl
                }]"
                :limit="1">
              </ai-uploader>
            </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: {},
        id: ''
      }
    },

    created () {
      if (this.params && this.params.id) {
        this.id = this.params.id
        this.getInfo(this.params.id)
      }
    },

    methods: {
      getInfo (id) {
        this.instance.post(`/app/appcourseinfo/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data
          }
        })
      },

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

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