importModalCtrl.js
5.14 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
(function(angular) {
function importModalCtrl1($scope,Utils,pagetType,$uibModal,$http, $uibModalInstance) {
$scope.init=function(){
switch(pagetType.source){
case 'importQuestionItem':
$scope.pageLayerTitle = '被调查商户导入';
$scope.isDelete = '导入';
$scope.deleteMsg = '导入Excel';
$scope.ajaxUrl = 'questionnaire/importQuestionItem';
$scope.btnMsg = '关闭';
$scope.downloadType=11;
$scope.importTemplate='被调查商户导入-模版.xlsx';
$scope.errorDown = '被调查商户报错下载.xlsx';
break;
case 'importRespondents':
$scope.pageLayerTitle = '调查商户导入';
$scope.isDelete = '导入';
$scope.deleteMsg = '导入Excel';
$scope.ajaxUrl = 'questionnaire/importRespondents';
$scope.btnMsg = '关闭';
$scope.downloadType=10;
$scope.importTemplate='调查商户导入-模版.xlsx';
$scope.errorDown = '调查商户报错下载.xlsx';
break;
}
};
/**
* 下载模板
* */
$scope.exportExcelTemplate=function(){
var data = {downloadType:$scope.downloadType};
var options = {
url:'common/downloadTemplate',
name:$scope.importTemplate
};
Utils.exportExcel(options,data);
};
/**
* 常量定义
* */
$scope.showValidate = false;
/**
* 关闭弹框方法
* */
$scope.close = function(){
$uibModalInstance.close($scope.importData);
};
/**
* 选择上传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.ajaxUrl,
method: 'POST',
headers: {
'Content-Type': undefined
},
transformRequest: function() {
var formData = new FormData();
formData.append('file', $('#upfile')[0].files[0]);
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.errMsg = list.errMsg;
$scope.importData = {
list:list.list
};
if(list.succNum > 0){
$scope.importData.execlName = list.execlName;
}
}
};
/**
* 确定按钮公共方法
* */
$scope.saveBtnClickEvent=function(){
};
$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.errorDown;
a.setAttribute('download', filename);
a.click();
URL.revokeObjectURL(objectUrl);
}).error(function (data, status, headers, config) {
});
};
$scope.init();
}
angular.module('questionnaire').controller('importModalCtrl1', importModalCtrl1);
})(angular);