 <template>
  <ai-detail>
    <template slot="title">
      <ai-title title="返回学习回答列表" isShowBack isShowBottomBorder @onBackClick="cancel(false)">
      </ai-title>
    </template>
    <template slot="content">
      <ai-card :title="info.content">
        <div slot="right" class="right-text">{{info.createUserName}}发布于{{info.createTime}} <span>已有{{info.answerCount || 0}}个回答</span></div>
        <template #content>
          <div class="item" v-for="(item, index) in info.answers" :key="index">
            <div class="flex">
              <img :src="item.createUserAvatar" alt="">
              <div class="user-info">
                <h3>{{item.createUserName}}</h3>
                <p>{{item.createUserDeptName}}</p>
              </div>
            </div>
            <div class="content" v-html="item.content"></div>
            <ai-uploader :instance="instance" disabled v-model="item.files"></ai-uploader>
            <p class="time"><span>发布于 </span>{{item.createTime}}</p>
          </div>
          <ai-empty v-if="!info.answers.length">暂无回答</ai-empty>
        </template>
      </ai-card>
    </template>
  </ai-detail>
</template>

<script>
  export default {
    name: 'Detail',
    props: {
      instance: Function,
      dict: Object,
      params: Object
    },
    data () {
      return {
        info: {}
      }
    },
    created () {
      this.getInfo()
    },
    methods: {
      getInfo () {
        this.instance.post(`/app/applearningquestion/queryDetailById?id=${this.params.id}`).then(res => {
          if (res.code == 0) {
            if (res.data) {
              this.info = {...res.data}
            }
          }
        })
      },
      cancel () {
        this.$emit('change', {
          type: 'List',
          isRefresh: true
        })
      }
    }
  }
</script>

<style scoped lang="scss">
.right-text {
  color: #999!important;
  span {
    margin-left: 8px;
  }
}
.item {
  margin-bottom: 32px;
  border-bottom: 1px solid #eee;
  .flex {
    display: flex;
    img {
      width: 80px;
      height: 80px;
      margin-right: 16px;
      border-radius: 50%;
    }
    h3 {
      line-height: 40px;
      font-size: 30px;
      font-weight: 700;
      margin-bottom: 10px;
    }
  }
  .content {
    margin: 16px 0;
  }
  p {
    line-height: 30px;
    color: #999;
    font-size: 14px;
  }
  .time {
    margin-bottom: 16px;
  }
  .img-list {
    img {
      width: 300px;
      height: 300px;
      margin: 0 8px 8px 0;
    }
  }
}
.item:nth-last-of-type(1) {
  border-bottom: 0;
  margin-bottom: 0;
}
</style>
