doImportCreateFee.vue
2.51 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
<el-dialog
:title="$t('doImportCreateFee.customCreateFee')"
:visible.sync="visible"
width="50%"
>
<el-form label-width="150px">
<el-form-item :label="$t('doImportCreateFee.selectFile')">
<el-upload
class="upload-demo"
:before-upload="beforeUpload"
:show-file-list="false"
>
<el-button size="small" type="primary">
<i class="el-icon-upload"></i>
{{ $t('common.selectFile') }}
</el-button>
<div slot="tip" class="el-upload__tip" style="margin-top:10px">
{{ fileName || $t('doImportCreateFee.requiredFile') }}
</div>
</el-upload>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="visible = false">{{ $t('doImportCreateFee.cancel') }}</el-button>
<el-button type="primary" @click="handleImport" :disabled="!file">
{{ $t('doImportCreateFee.import') }}
</el-button>
</div>
</el-dialog>
</template>
<script>
import { importCustomFee } from '@/api/fee/carCreateFeeApi'
export default {
name: 'DoImportCreateFee',
data() {
return {
visible: false,
file: null,
fileName: ''
}
},
methods: {
open() {
this.visible = true
this.file = null
this.fileName = ''
},
beforeUpload(file) {
const validTypes = ['xlsx', 'xls']
const fileType = file.name.split('.').pop().toLowerCase()
const isExcel = validTypes.includes(fileType)
const isLt2M = file.size / 1024 / 1024 < 2
if (!isExcel) {
this.$message.error(this.$t('common.invalidExcelType'))
return false
}
if (!isLt2M) {
this.$message.error(this.$t('common.fileSizeExceed'))
return false
}
this.file = file
this.fileName = file.name
return false // 阻止自动上传
},
async handleImport() {
if (!this.file) {
this.$message.warning(this.$t('doImportCreateFee.requiredFile'))
return
}
try {
const res = await importCustomFee({
file: this.file
})
if (res.code === 0) {
this.$message.success(this.$t('common.importSuccess'))
this.visible = false
this.$emit('success')
} else {
this.$message.error(res.msg || this.$t('common.importError'))
}
} catch (error) {
this.$message.error(this.$t('common.importError'))
}
}
}
}
</script>