activeListCtrl.js
7.46 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
(function(angular) {
function activeListCtrl($scope, reportService, $resource, DTOptionsBuilder, DTColumnBuilder, localStorageService, $location, $rootScope) {console.log('t2:'+$rootScope.storageIsUsed)
$scope.dateRange = {
startDate: moment().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
endDate: moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')
}
$scope.onlineOptions = [
{id: '', name: '全部'},
{id: 1, name: '在线'},
{id: 2, name: '离线'}
];
$scope.onlineOptions.selected = $scope.onlineOptions[0];
//获取分组列表
reportService.getAllVehicleGroup(function(result){
if(result.returnCode == '0'){
var data = result.data;
data.unshift({
id: '',
name: '选择分组'
});
$scope.groupOptions = data;
$scope.groupOptions.selected = data[0];
if($rootScope.storageIsUsed && initParams.groupId){
angular.forEach($scope.groupOptions, function(o, idx){
if(o.id == initParams.groupId){
$scope.groupOptions.selected = $scope.groupOptions[idx];
}
});
if(initParams.classIdList){
$scope.getClassListByGroupId(initParams.groupId);
}
}
}
});
$scope.classOptions = [];
$scope.classOptions.selected = {};
//获取分类
$scope.getClassListByGroupId = function(groupId){
reportService.getClassListByGroupId({groupId: groupId}, function(result){
if(result.returnCode == '0'){
var data = result.data;
$scope.classOptions = data;
$scope.classOptions.selected = data[0];
if($rootScope.storageIsUsed && initParams.classIdList){
angular.forEach($scope.classOptions, function(o, idx){
if(o.id == initParams.classIdList){
$scope.classOptions.selected = $scope.classOptions[idx];
}
});
}
}
});
}
//查询类型
$scope.queryTypeOptions = [
{id: '', name: '请选择'},
{id: 1, name: '设备号'},
{id: 2, name: '车架号'},
{id: 3, name: '姓名'},
{id: 4, name: '工单号'}
];
$scope.queryTypeOptions.selected = $scope.queryTypeOptions[0];
$scope.activeListForm = function(){
var params = getParams();
setStorage(params);
if(!params.sTime&&!params.eTime){
delete params.sTime;
delete params.eTime;
}
$scope.dtInstance.query(params);
}
initTable();
var initParams;
if($rootScope.storageIsUsed){
var key = $location.url();
var initParams = angular.fromJson(localStorageService.get(key));
$scope.dateRange = {
startDate: initParams.sTime,
endDate: initParams.eTime
};
if(!angular.isUndefined(initParams.isOnLine)){
angular.forEach($scope.onlineOptions, function(o, idx){
if(o.id == initParams.isOnLine){
$scope.onlineOptions.selected = $scope.onlineOptions[idx];
}
});
}
if(!angular.isUndefined(initParams.sn)){
$scope.queryTerm = initParams.sn;
$scope.queryTypeOptions.selected = $scope.queryTypeOptions[1];
}
if(!angular.isUndefined(initParams.standNo)){
$scope.queryTerm = initParams.standNo;
$scope.queryTypeOptions.selected = $scope.queryTypeOptions[2];
}
if(!angular.isUndefined(initParams.name)){
$scope.queryTerm = initParams.name;
$scope.queryTypeOptions.selected = $scope.queryTypeOptions[3];
}
if(!angular.isUndefined(initParams.workOrderNo)){
$scope.queryTerm = initParams.workOrderNo;
$scope.queryTypeOptions.selected = $scope.queryTypeOptions[4];
}
}else{
setStorage();
initParams = getParams();
}
if(!initParams.sTime&&!initParams.eTime){
delete initParams.sTime;
delete initParams.eTime;
}
$scope.condition = initParams;
$scope.dtInstance = {
serverData : reportService.getActiveList
};
function getParams(){
var params = {};
var _startDate = $scope.dateRange.startDate;
var _endDate = $scope.dateRange.endDate;
if(angular.isObject(_startDate)){
params.sTime = _startDate.format('YYYY-MM-DD HH:mm:ss');
params.eTime = _endDate.format('YYYY-MM-DD HH:mm:ss');
}else{
params.sTime = _startDate;
params.eTime = _endDate;
}
if(angular.isNumber($scope.onlineOptions.selected.id)){
params.isOnLine = $scope.onlineOptions.selected.id;
}
var classGroupSelected = $scope.classOptions.selected;
if(!angular.isUndefined(classGroupSelected.id)){
params.classIdList = classGroupSelected.id;
}
if(!angular.isUndefined(classGroupSelected.groupId)){
params.groupId = classGroupSelected.groupId;
}
var _queryTypeSelected = $scope.queryTypeOptions.selected;
if(angular.isString($scope.queryTerm) && angular.isNumber(_queryTypeSelected.id)){
switch(_queryTypeSelected.id){
case 1:
params.sn = $scope.queryTerm;
break;
case 2:
params.standNo = $scope.queryTerm;
break;
case 3:
params.name = $scope.queryTerm;
break;
case 4:
params.workOrderNo = $scope.queryTerm;
break;
}
}
return params;
}
function initTable(){
$scope.dtColumns = [
DTColumnBuilder.newColumn('sqbh').withOption('width',100).withTitle('工单号'),
DTColumnBuilder.newColumn('name').withOption('width',60).withTitle('姓名'),
DTColumnBuilder.newColumn('standno').withOption('width',160).withTitle('车架号'),
DTColumnBuilder.newColumn('brand').withOption('width',100).withTitle('品牌车型'),
DTColumnBuilder.newColumn('sn').withOption('width',100).withTitle('设备号'),
DTColumnBuilder.newColumn('unitType').withOption('width',100).withTitle('设备型号'),
DTColumnBuilder.newColumn('isOnLine').withOption('width',60).withTitle('是否在线'),
DTColumnBuilder.newColumn('className').withOption('width',100).withTitle('所属分类'),
DTColumnBuilder.newColumn('activeDate').withOption('width',100).withTitle('激活时间'),
DTColumnBuilder.newColumn('operator').withOption('width',200).withTitle('激活操作人')
]
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withButtons([{
text : '导出excel',
className: 'btn btn-primary',
action : function(e, dt, node, config) {
var _selectedItems = $scope.dtInstance.getSelectItems();
var params = getParams();
if(_selectedItems.length){
var _ids = [];
angular.forEach(_selectedItems, function(o){
_ids.push(o.id);
});
params.idList = _ids.join(',');
}
exportForm('deviceActive/exportDeviceActive', params);
}
}])
.withOption('id','id')
.withFixedColumns({
leftColumns: 7,
rightColumns: 0
})
.withOption('select', {
type: 'checkbox'
});
}
function exportForm(url,oParam,formId){
if(!formId){
formId = 'exportForm';
}
if($("#"+formId).length>0){
$("#"+formId).remove();
}
var _form =
$('<form action="'+url+'" id="'+formId+'" method="get" accept-charset="utf-8" style="display:none;">'+
'</form>');
var _input='';
if(!$.isEmptyObject(oParam)){
for(var key in oParam){
_input+='<input type="hidden" name="'+key+'" id="'+key+'" value="'+(oParam[key])+'"/>';
}
}
_form.append(_input);
$('body').append(_form[0]);
$("#"+formId).submit();
}
function setStorage(params){
var key = $location.url();
var _params = params || getParams();
var _str = angular.toJson(_params);
localStorageService.set(key, _str);
}
}
angular.module('report').controller('activeListCtrl', activeListCtrl)
})(angular);