<template>
  <el-dialog
    v-if="visible"
    :visible.sync="visible"
    :before-close="handleClose"
    :title="title"
    :append-to-body="appendToBody"
    width="60%">
    <UploadFile :file-list.sync = "files" :accept="accept"/>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeWindow">取 消</el-button>
      <el-button type="primary" @click="confirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import waves from '@/directive/waves' // waves directive
import UploadFile from '@/components/UploadFile'

export default {
  components: { Pagination, UploadFile },
  directives: { waves },
  props: {
    title: {
      type: String,
      default: ''
    },
    appendToBody: {
      type: Boolean,
      default: false
    },
    limit: {
      type: Number,
      default: 1
    },
    accept: {
      type: String,
      default: '.pdf'
    }
  },
  data() {
    return {
      visible: false,
      files: [],
      heirloom: {}
    }
  },
  methods: {
    init(e) {
      this.visible = true
      this.heirloom = e
    },
    handleClose() {
      this.visible = false
      this.files = []
    },
    closeWindow() {
      this.handleClose()
    },
    confirm() {
      if (this.files.length <= 0) {
        this.$message.error('未选择文件')
        return
      }
      const str = this.files[0].name
      if (str.substr(str.indexOf('.') + 1, str.length) !== 'pdf') {
        this.$message.error('导入类型与模板类型不一致')
        return
      }
      this.$emit('getChoose', { heirloom: this.heirloom, info: this.files, name: 'uploadPdf' })
      this.visible = false
    }
  }
}

</script>

<style scoped>
.information >>> .el-scrollbar__wrap {
  overflow-x: hidden;
}
</style>
