马宇豪
2024-02-06 6c153ca68080df99f9ec8ad1666413f65b6a5881
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<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>