accountCtrl.js
4.02 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
(function(angular) {
function acountCtrl($scope, DTOptionsBuilder, DTColumnBuilder, systemService, $uibModal, $filter, $state) {
$scope.createTime = {}
$scope.drOptions = {
opens: 'right',
eventHandlers: {
'apply.daterangepicker':function(ev, picker){
$scope.createTime.startDate = picker.startDate;
$scope.createTime.endDate = picker.endDate;
}
}
}
$scope.dtColumns = [
DTColumnBuilder.newColumn('createTime').withOption('width',160).withTitle('创建时间'),
DTColumnBuilder.newColumn('username').withOption('width',100).withTitle('登录账号'),
DTColumnBuilder.newColumn('name').withOption('width',100).withTitle('用户名'),
DTColumnBuilder.newColumn('groupName').withOption('width',100).withTitle('所属用户组'),
DTColumnBuilder.newColumn('mobile').withOption('width',100).withTitle('联系电话'),
DTColumnBuilder.newColumn('roleNames').withOption('width',200).withTitle('角色'),
DTColumnBuilder.newColumn(null).withTitle(function(){
return '操作';
}).withOption('width', 140).withClass('text-center').renderWith(function(data, type, full, oSettings) {
var str = '<div class="form-inline">'
+'<div class="form-group"><a class="btn btn-link" ng-click="editAccount('+ data.id +')">编辑</a></div>'
+'<div class="form-group"><a class="btn btn-link" ng-click="deleteAccount('+ data.id +')">删除</a></div>';
str += '</div>';
return str;
})
];
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('id','id')
.withFixedColumns({
leftColumns: 2,
rightColumns: 0
})
$scope.dtInstance = {
serverData : systemService.getUserList
};
function getParams(){
var obj = {};
if($scope.name){
obj.name = $scope.name;
}
if($scope.createTime.startDate && $scope.createTime.endDate){
obj.sTime = $scope.createTime.startDate.format('YYYY-MM-DD HH:mm:ss');
obj.eTime = $scope.createTime.endDate.format('YYYY-MM-DD HH:mm:ss');
}
return obj;
}
//查询
$scope.accountListForm = function(){
$scope.dtInstance.query(getParams());
}
$scope.addAccount = function(){
$state.go('system.userAdmin.accountEdit');
}
$scope.editAccount = function(id){
$state.go('system.userAdmin.accountEdit', {id: id});
}
$scope.deleteAccount = function(id){
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'deleteAccountModal',
controller: 'deleteAccountCtrl',
size: 'sm',
resolve: {
id: id,
dtInstance: $scope.dtInstance,
queryParams: getParams()
}
});
}
}
function deleteAccountCtrl($scope, $uibModalInstance, systemService, id, dtInstance, queryParams){
systemService.getUserById({
userId: id
}, function(result){
if(result.returnCode == 0){
$scope.username = result.data.username;
}
})
$scope.confirm = function() {
$scope.isWorking = true;
systemService.batchDelUser($.param({ids: id}), function(result){
if(result.returnCode == '0'){
$uibModalInstance.close();
swal({
type: 'success',
title: '',
text: result.message,
closeOnConfirm: false,
confirmButtonText: "确定",
timer: 3000
});
dtInstance.query(queryParams);
}else{
swal({
type: 'error',
title: '',
text: result.message,
closeOnConfirm: false,
confirmButtonText: "确定"
});
}
$scope.isWorking = false;
});
};
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
}
angular.module('system').controller('accountCtrl', acountCtrl)
.controller('deleteAccountCtrl', deleteAccountCtrl)
})(angular);