/**
* 选择文件事件
* @param event 事件触发点
* @return {boolean}*/onChangeFile:function(event) {
vm.file= "";
$("#showFileName").html("未选择文件");
$("#showFileName").removeAttr("title");var str = $("#file").val();var index = str.lastIndexOf(‘.‘);var photoExt1 = str.substr(index, 5).toLowerCase();var photoExt2 = str.substr(index, 4).toLowerCase();if (photoExt1 != ‘‘ && !(photoExt1 == ‘.xlsx‘ || photoExt2 == ‘.xls‘)) {this.$message({
message:‘请上传xlsx/xls文件!‘,
type:‘warning‘});
$("#file").val("");
vm.isNeedFileExtension= false;return false;
}else{var maxsize = 2 * 1024 * 1024;//2M
var file = event.target.files[0];var fileSize =file.size;if (fileSize >maxsize) {this.$message({
message:‘上传的文件不能大于2M‘,
type:‘warning‘});
$("#file").val("");
vm.fileSizeIsFit= false;return false;
}else{
vm.file=file;
$("#showFileName").attr("title", vm.file.name);
$("#showFileName").html(vm.file.name);
vm.isNeedFileExtension= true;
vm.fileSizeIsFit= true;
}
}
},/**
* 上传选择的文件
* @param event*/uploadFile:function(event) {if ($("#showFileName").text() == "No file chosen") {this.$message({
message:‘请选择文件‘,
type:‘warning‘});
}else if (!vm.isNeedFileExtension) {this.$message({
message:‘请上传xlsx/xls文件!‘,
type:‘warning‘});
}else if (!vm.fileSizeIsFit) {this.$message({
message:‘上传的文件不能大于2M‘,
type:‘warning‘});
}else{
event.preventDefault();var formData = newFormData();
formData.append(‘file‘, this.file);
formData.append(‘token‘, this.token);var url = baseURL + ‘informationManagement/taxpayerInformationManagement/import‘;var loading = vm.getLoading("上传中...");
$.ajax({
type:"POST",
url: url,
data: formData,
dataType:"json",
cache:false,//上传文件无需缓存
processData: false,//用于对data参数进行序列化处理 这里必须false
contentType: false, //必须
success: function(response) {
console.log(response)
loading.close();
$("#showFileName").html(‘未选择文件‘);if (response.code == 0) {this.$message({
message: response.msg,
type:‘success‘});//vm.query();
//vm.uploadDialog = false;
/*var para = {
‘fileNumber‘: vm.aId
};*/
//vm.findFileList(para);
/*var pdfName = "";
for (var i = 0; i < response.list.length; i++) {
var data = response.list[i];
if (data.readPdfSuccess) {
pdfName += ‘
文件:‘ + data.pdfName + ‘ 成功
‘;electron.listData.push(data);
} else {
pdfName += ‘
文件:‘ + data.pdfName + ‘ 失败
‘;}
}
$("#pdfName").append(pdfName);*/}else{
loading.close();this.$message.error(‘系统错误!请稍后再试!‘);
}
},
error:function(response) {
loading.close();this.$message.error(‘系统错误!请稍后再试!‘);
}
});
}
},