importCusModal.js
4.23 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
(function(angular) {
function importCusModalCtrl($scope,Utils,importConfig,$uibModal,$http, $uibModalInstance) {
$scope.params={};
var defaultConfig = {
pageTitle:'导入',//弹框标题
ajaxUrl:'', //导入服务地址
downloadType:'',//下载导入模板类型
importTemplate:'模版',//下载导入模板文件名
errorDown:'报错下载.xlsx',//导入excel错误文件名
params:{}
};
$scope.init=function(){
$scope.options = $.extend(defaultConfig,importConfig);
};
/**
* 下载模板
* */
$scope.exportExcelTemplate=function(){
var data = $.extend($scope.options.params,{downloadType:$scope.options.downloadType,name:$scope.options.importTemplate});
var options = {url:'common/downloadTemplate'};
Utils.exportExcel(options,data);
};
/**
* 常量定义
* */
$scope.showValidate = false;
/**
* 关闭弹框方法
* */
$scope.close = function(){
$uibModalInstance.dismiss(0);
};
/**
* 选择上传excel
* */
$scope.choseUploadFile=function(file){
if($(file).val()){
$scope.uploadFileName = $(file).val();
$scope.$apply();
};
};
/**
* 确定导入附件
* */
$scope.sendUploadFile=function(){
var fileName = $scope.uploadFileName;
var b = '';
if(fileName){
var a = fileName.split('.');
b = a[a.length-1];
}
if(!fileName||b != 'xlsx'){
$scope.showValidate = true;
return false;
};
$scope.showLoadingImg = true;
$http({
url: $scope.options.ajaxUrl,
method: 'POST',
headers: {
'Content-Type': undefined
},
transformRequest: function() {
var formData = new FormData();
formData.append('file', $('#upfile')[0].files[0]);
if($scope.params){
for(var p in $scope.params){
formData.append(p, $scope.params[p]);
}
}
return formData;
}
}).success(function (res) {
$scope.showValidate = false;
$scope.showLoadingImg = false;
if(res.returnCode == 0){
$scope.importClickEvent(res);
}else{
swal({
type: 'error',
title: '',
text: res.message||'操作失败',
showConfirmButton:false,
timer: 1500
},function(){
swal.close();
});
};
});
};
/**
* 确定导入excel方法
* */
$scope.importClickEvent=function(res){
$scope.errorMsgList = '';
if(res.returnCode == 0){
var list = res.data;
$scope.isShowErrorMsg = true;
$scope.sTipMsg = list.succNum;
$scope.eTipMsg = list.failNum;
}
};
$scope.exportExcel=function(){
$http({
url: 'excelResultOut/export',
method: "GET",//接口方法
headers: {
'Content-type': 'application/json'
},
responseType: 'arraybuffer'
}).success(function (data, status, headers, config) {
var blob = new Blob([data], {type: "application/vnd.ms-excel"});
var objectUrl = URL.createObjectURL(blob);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display:none');
a.setAttribute('href', objectUrl);
var filename=$scope.options.errorDown;
a.setAttribute('download', filename);
a.click();
URL.revokeObjectURL(objectUrl);
}).error(function (data, status, headers, config) {
});
};
$scope.init();
}
angular.module('qualityUpgrade').controller('importCusModalCtrl', importCusModalCtrl);
})(angular);