<template>
  <div class="chatper-work-answer-item">
    <div class="chapter-work-answer-item-hd">{{ nickname }}:</div>
    <div class="chapter-work-answer-item-bd">
      <div class="item" v-for="item in workList" :key="item.question_id">
        <div v-html="decode(item.descreption)"></div>
        <a :href="item.file_url" target="_blank" class="file" v-if="item.file_url">
          <i class="el-icon-document"></i>
          {{ $t('viewerWork.downloadName') }}
        </a>
      </div>
    </div>
    <slot />
  </div>
</template>

<script>
import Base64 from 'Base64'

export default {
  props: {
    index: { type: Number, default: 0 },
    data: { type: Object, default: () => ({}) }
  },
  data() {
    return {}
  },
  computed: {
    // 作业列表
    workList() {
      return this.data.work_contents ? JSON.parse(this.data.work_contents) : []
    },
    nickname() {
      const name = this.data.personal_name
      return name ? name + this.$t('viewerWork.student') : this.$t('viewerWork.student') + (this.index + 1)
    }
  },
  methods: {
    decode(value) {
      return value ? Base64.decode(value) : ''
    }
  }
}
</script>

<style lang="scss">
.chatper-work-answer-item {
  border-bottom: 1px solid #c9c9c97a;
  margin-bottom: 20px;
  .item + .item {
    border-top: 1px dashed #c9c9c97a;
  }
  .file {
    display: inline-block;
    margin-bottom: 10px;
    text-decoration: none;
    color: #333;
    &:hover {
      color: #b49441;
    }
  }
}
</style>
