<el-Button @click="dialogVisible = true">批量导入数据</el-Button>
<el-dialog title="批量导入数据" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" append-to-body>
<el-row>
<div class="el-form-item__content">
<el-upload ref="upload" accept=".xls,.xlsx" action="#" :auto-upload="false" :multiple="false"
:file-list="fileList" :before-upload="beforeUpload" :http-request="uploadHttpRequest"
:on-remove="fileRemove" :on-change="fileChange">
<el-button size="small" type="primary">选择文件</el-button>
<div slot="tip" class="el-upload__tip">一次只能上传一个xls/xlsx文件,且不超过10M</div>
</el-upload>
</div>
</el-row>
<el-row>
<el-button size="small" @click="closeDialog">取 消</el-button>
<el-button type="primary" size="small" @click="submitUpload">上 传</el-button>
</el-row>
</el-dialog>
data() {
return {
dialogVisible: false,
uploadLoading: '',
fileList: [],
}
}
handleClose(done) {
this.dialogVisible = false;
},
beforeUpload(file) {
const isType = file.type === 'application/vnd.ms-excel'
const isTypeComputer = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
const fileType = isType || isTypeComputer
if (!fileType) {
this.$message.error('上传文件只能是xls/xlsx格式!')
}
const fileLimit = file.size / 1024 / 1024 < 10;
if (!fileLimit) {
this.$message.error('上传文件大小不超过10M!');
}
return fileType && fileLimit
},
uploadHttpRequest(param) {
const formData = new FormData()append('key', value)
formData.append('fileName', param.file)
formData.append('storeId', this.storeId)
getgoodsExcil(formData).then(res => {
if(res.code=='200' && res.message=="success"){
this.$Message.success("批量上传成功");
this.dialogVisible=false;
param.onSuccess();
this.init();
this.fileList=[];
}else{
this.dialogVisible=false;
this.$Message.success(this.success);
param.onError();
this.init();
this.fileList=[];
}
})