<template>
  <div>
    <div class="my-title">查看</div>
    <div style="margin-left: 20px;margin-right: 20px">
      <e-desc title="基本信息" column="3">
        <e-desc-item label="文件名称">{{dataForm.fileName}}</e-desc-item>
        <e-desc-item label="文件描述">{{dataForm.fileDescribe}}</e-desc-item>
        <e-desc-item label="文件类别">{{fileTypeName}}</e-desc-item>

        <e-desc-item label="备注说明" span="2">{{dataForm.notes}}</e-desc-item>
      </e-desc>
      <e-desc title="附件">
        <e-desc-item span="2" label="电子文件">
          <div v-for="(item, index) in dataForm.attachList" style="display: inline">
            <span v-if="index > 0">,</span>
            <a :key="item.fileName + index" type="primary" href="#" @click="previewFile(item.fileName, item.url)">{{ item.fileName }}</a>
          </div>
        </e-desc-item>
      </e-desc>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="onChose">返回</el-button>
    </span>
    <!-- 文件预览 -->
    <preview-component v-if="previewVisible" ref="preview"/>
  </div>
  <!-- </el-dialog> -->
</template>

<script>
  import EDesc from '../common/e-desc'
  import EDescItem from '../common/e-desc-item'
  import { getDocDetail } from '@/api/file'
  import { getDictValue } from '@/api/dict'
  import PreviewComponent from '../common/preview-component'
export default {
    name: 'product-detail',
    components: {
      PreviewComponent,
      EDesc,
      EDescItem
    },
    data () {
      return {
        visible: false,
        previewVisible: false,
        id: 0,
        dataForm: {},
        fileTypeName: ''
      }
    },
    methods: {
      onChose () {
        this.$emit('onChose')
      },
      async init (id) {
        this.visible = true
        this.id = id || 0
        this.dataForm = {}
        this.fileTypeName = ''
        this.getDetails()
      },
      getDetails () {
        getDocDetail(this.id).then(({data}) => {
          if (data && data.code === '200') {
            this.dataForm = data.data
            if (data.data.fileType) {
              getDictValue({type: 'doc_file_type', code: data.data.fileType}).then((data1) => {
                if (data1.data) {
                  this.fileTypeName = data1.data.value
                }
              })
            }
          }
        })
      },
      // 预览
      previewFile (fileName, url) {
        this.previewVisible = true
        this.$nextTick(() => {
          this.$refs.preview.init(fileName, url)
        })
      }
    }
  }
</script>

<style scoped>
.my-line{
  border-bottom: 1px solid #c0c4cc;
  margin-bottom: 10px;
}
.title{
  padding: 10px 0 ;
}
</style>
