<template>
  <div v-loading="loading" class="preview-wrapper">
    <el-tabs tab-position="right" type="card">
      <el-tab-pane v-for="file in fileList" :key="file.Id" :label="file.FileName">

        <iframe
          v-if="file.Type.indexOf('jpg') !== -1 || file.Type.indexOf('png') !== -1"
          frameborder="0"
          :src="file.FullFilePath"
          width="100%"
          style="width: 100%; height: 100%"
        />
        <embed v-else-if="file.Type.indexOf('pdf') !== -1" :src="file.FullFilePath" style="width: 100%; height: 100%">
        <div v-else>
          该文件不支持在线预览，可点击<el-link type="primary" @click="downLoadFile(file.FullFilePath)">下载</el-link>原件
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import { getNoneDicomStudyFileList } from '@/api/trials'
export default {
  name: 'PreviewFiles',
  props: {
    noneDicomId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      fileType: '',
      fileUrl: '',
      loading: false,
      fileList: []
    }
  },
  mounted() {
    this.getFileList()
  },
  methods: {
    getFileList() {
      this.loading = true
      getNoneDicomStudyFileList(this.noneDicomId).then(res => {
        this.fileList = res.Result
        this.fileList.forEach(file => {
          const fileName = file.FileName
          file.Type = fileName.substring(fileName.lastIndexOf('.') + 1).toLocaleLowerCase()
        })
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    downLoadFile(filePath) {
      if (!filePath) return
      window.open(filePath, '_blank')
    }
  }
}
</script>
<style lang="scss">
.preview-wrapper{
  height: 100%;
  ::-webkit-scrollbar {
    width: 7px;
    height: 7px;
  }
  ::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background: #d0d0d0;
  }
  .el-tabs{
    display: flex;
    flex-direction: row !important;
    width: 100%;
    height: 100%;
    .el-tabs__header{
      margin-right: 10px !important;
      height: 100% !important;
      width: 300px;
      border: 2px solid #E4E7ED;
     overflow: auto;
    }
    .el-tabs__content{
      flex: 1;
      height: 100%;
      .el-tab-pane{
        height: 100%;
      }
    }
  }

}
</style>
