<template>
  <div class="importExcel mrg-l">
    <!-- <el-button type="primary" @click="dialogVisible=true">{{btnName}}</el-button> -->
    <el-dialog
    title="文件导入"
    :visible.sync="dialogVisible"
    :before-close="close=done=>done()">
      <el-upload
      ref="upload"
      :action="actionUrl"
      :auto-upload="false"
      :on-success="handleSuccess">
      <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
     <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">开始导入</el-button>
      </el-upload>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data () {
    return {
      dialogVisible: false,
    }
  },
  props: {
    btnName: {
      type: String,
      default: '导入'
    },
    excelConfig: String,
    baseUrl: String
  },
  computed: {
    actionUrl () {
      return `${this.baseUrl}/fileController/springUpload?excelConfig=${this.excelConfig}`
    }
  },
  methods: {

    submitUpload () {
      this.$refs.upload.submit()
    },
    handleSuccess (res, file, fileList) {
      if (res.success) {
        const url = `${this.baseUrl}/excelController/parsingExcel.shtml?fileId=${res.fileIds}&excelConfig=${this.excelConfig}`
        this.$https.get(url).then(data => {
          console.log(data)
          this.$message.info(data.message)
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.importExcel{
  display: inline-block
}
.mrg-l{
  margin-left: 10px
}
</style>
