HTML部分
<el-button type=“primary” @click=“addtemplate” style=“margin-top:10px;margin-left:30px;”>下载模板
Excel表内必填数据:
*姓名 * 手机号、身份证号
注:带“*”为必填字段
JS部分
//批量导入-下载模板
addtemplate(){
axios({
method:‘post’,
url:API_OBJ.TEMPLATE
}).then((res=>{
window.location.href=res.config.url;
this.step.active=1;
}))
},
//批量导入-上传文件
handleTestSuccess(file) {
this.close.load=true;
// 验证图片格式
if (file.file.type.indexOf(‘excel’) == -1) {
// 文件格式
this.
m
e
s
s
a
g
e
.
e
r
r
o
r
(
′
请
上
传
表
格
类
型
的
文
件
′
)
/
/
删
除
上
传
失
败
的
图
片
,
不
然
会
占
位
t
h
i
s
.
message.error('请上传表格类型的文件') //删除上传失败的图片,不然会占位 this.
message.error(′请上传表格类型的文件′)//删除上传失败的图片,不然会占位this.refs.upload_img.uploadFiles = this.$refs.upload_img.uploadFiles.filter(
(item) => {
return file.file.name != item.name
}
)
return
}
//构建一个formData对象,因为这里要求表单类型的数据
const formData = new FormData();
formData.append(‘uploadFile’, file.file);
formData.append(‘companyId’,this.Info.companyId)
// axios({
// method:‘post’,
// url:API_OBJ.ADDFILE+’?companyId=’+t.Info.companyId
// })
axios.post('/Platform_N/lmmanage/web/companyUser/batchUploadUser', formData, {
headers: {
}
})
.then((res) => {
this.step.active=2;
if(res.data.resultCode=='404'){
this.close.error=false;
this.close.showerror=true
for(let i=0;i<res.data.data.length;i++){
res.data.data[i].data.errorMsg=res.data.data[i].errorMsg
this.tableerror.push(res.data.data[i].data)
}
this.errornum=res.data.data.length;
this.close.load=false;
}else if(res.data.resultCode=='200'){
this.close.error=false;
this.close.success=true;
this.step.num=res.data.data
this.close.load=false;
}
})
.catch((err) => {
//删除上传失败的图片,不然会占位
this.$refs.upload_img.uploadFiles = this.$refs.upload_img.uploadFiles.filter(
(item) => {
return file.file.name != item.name
}
)
this.$message.error('上传失败!')
})
},
shangc(){
this.$refs.upload_img.submit();
},
//批量导入-取消上传
canael(){
this.$refs.upload_img.clearFiles();
this.close.btn=true;
this.close.odd=false;//关闭弹窗
this.close.piliang=false;//关闭对应弹窗
this.step.active=0;//设置步骤条
},
//批量导入-文件状态改变
changefile(file, fileList){
// console.log(file);
// console.log(fileList);
if(fileList.length!=0){
this.close.btn=false;
this.step.active=1;
}else{
this.close.btn=true;
}
},