importModalCtrl.js
6.27 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
(function(angular) {
function importModalCtrl($scope,Utils,pagetType,$uibModal,$http, $uibModalInstance) {
$scope.init=function(){
switch(pagetType.source){
case 'saleShopCount':
$scope.pageLayerTitle = '销售门店导入';
$scope.isDelete = '导入';
$scope.deleteMsg = '导入Excel';
$scope.ajaxUrl = 'setmining/productInfo/importSaleShopCount';
$scope.btnMsg = '关闭';
$scope.downloadType=8;
$scope.importTemplate='销售门店导入-模版.xlsx';
$scope.errorDown = '销售门店报错下载.xlsx';
break;
case 'productManager':
$scope.pageLayerTitle = '产品导入';
$scope.isDelete = '导入';
$scope.deleteMsg = '导入Excel';
$scope.ajaxUrl = 'setmining/productInfo/import';
$scope.btnMsg = '关闭';
$scope.downloadType=6;
$scope.importTemplate='产品导入-模版.xlsx';
$scope.errorDown = '产品报错下载.xlsx';
break;
case 'categoryManager':
$scope.pageLayerTitle = '类目导入';
$scope.isDelete = '导入';
$scope.deleteMsg = '导入Excel';
$scope.ajaxUrl = 'category/importCategory';
$scope.btnMsg = '关闭';
$scope.downloadType=5;
$scope.importTemplate='类目导入-模版.xlsx';
$scope.errorDown = '类目报错下载.xlsx';
break;
case 'supplierManager':
$scope.pageLayerTitle = '供应商导入';
$scope.isDelete = '导入';
$scope.deleteMsg = '导入Excel';
$scope.ajaxUrl = 'supplier/import';
$scope.btnMsg = '关闭';
$scope.downloadType=7;
$scope.importTemplate='供应商导入-模版.xlsx';
$scope.errorDown = '供应商报错下载.xlsx';
break;
default:
$scope.pageLayerTitle = '产品导入';
$scope.isDelete = '导入';
$scope.deleteMsg = '导入Excel';
$scope.ajaxUrl = 'setmining/productInfo/import';
$scope.btnMsg = '关闭';
$scope.downloadType=6;
$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.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.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.saveBtnClickEvent=function(){
};
$scope.exportExcel=function(){
var options = $scope.getParam();
$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('electronicDirectory').controller('importModalCtrl', importModalCtrl);
})(angular);