<template>
|
<el-dialog
|
:visible.sync="uploadDialogVisible"
|
append-to-body
|
title="导入企业"
|
:close-on-click-modal="false"
|
>
|
<el-form
|
ref="importForm"
|
label-position="right"
|
label-width="120px"
|
style="margin-left:50px;width:500px;"
|
element-loading-text="导入中..."
|
>
|
<el-form-item label="导入文件:">
|
<input ref="upload" type="file" accept=".xls, .xlsx" >
|
</el-form-item>
|
<el-form-item label="excel参考模板:">
|
<el-button type="text" @click="viewHandle">下载模板</el-button>
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button @click="uploadDialogVisible = false">取消</el-button>
|
<el-button type="primary" @click="importHandle()">导入</el-button>
|
</div>
|
</el-dialog>
|
</template>
|
|
<script>
|
import { importEnterprise} from "../../../api/enterprise";
|
const exampleFile = require('@/assets/example/enterprise.xlsx')
|
|
export default {
|
name: "uploadExcel",
|
data(){
|
return{
|
uploadDialogVisible:false,
|
}
|
},
|
methods:{
|
showUploadExcel(){
|
this.uploadDialogVisible = true
|
},
|
viewHandle() {
|
window.open(exampleFile, '_blank')
|
},
|
async importHandle(){
|
const formData = new FormData()
|
const files = this.$refs['upload'].files
|
if (files && files.length > 0) {
|
formData.append('file', files[0])
|
}
|
let res = await importEnterprise(formData)
|
if(res.data.code === "200"){
|
this.uploadDialogVisible = false
|
this.$emit('getinfo')
|
this.$notify({
|
title:'成功',
|
duration:2000,
|
message:'导入成功',
|
type:'success'
|
})
|
}else{
|
this.$message({
|
message:res.data.message,
|
type:'warning'
|
})
|
}
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|