roleCtrl.js
4.8 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
(function(angular) {
function roleCtrl($scope, DTOptionsBuilder, DTColumnBuilder, systemService, $uibModal, $filter, $state) {
$scope.fieldName='merchantId';
$scope.createTime = {};
$scope.drOptions = {
opens: 'right',
eventHandlers: {
'apply.daterangepicker':function(ev, picker){
$scope.createTime.startDate = picker.startDate;
$scope.createTime.endDate = picker.endDate;
},
'cancel.daterangepicker': function (ev, picker) {
$scope.createTime = {}
$scope.createTime.startDate = null
$scope.createTime.endDate = null
$scope.$apply()
}
}
}
$scope.dtColumns = [
DTColumnBuilder.newColumn('name').withOption('width',140).withTitle('角色'),
DTColumnBuilder.newColumn('description').withOption('width',200).withTitle('角色说明'),
DTColumnBuilder.newColumn('merchantName').withOption('width',200).withTitle('创建商户名称'),
DTColumnBuilder.newColumn('createdDate').withOption('width',140).withTitle('创建时间').renderWith(function(e, dt, node, config){
return $filter('date')(new Date(node.createdDate), 'yyyy-MM-dd HH:mm:ss');
}),
DTColumnBuilder.newColumn(null).withTitle(function(){
return '操作';
}).withOption('width', 140).withClass('text-center').renderWith(function(data, type, full, oSettings) {
if(data.isSuper){
return "";
}
var str = '<div class="form-inline">'
+'<div class="form-group"><a class="btn btn-link" ng-click="editRole('+ data.id +')">编辑</a></div>'
+'<div class="form-group"><a class="btn btn-link" ng-click="deleteRole('+ data.id +')">删除</a></div>';
str += '</div>';
return str;
})
];
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('id','id')
.withFixedColumns({
leftColumns: 2,
rightColumns: 0
})
$scope.dtInstance = {
serverData : systemService.getRoleList
};
function getParams(){
var obj = {};
if($scope.name){
obj.name = $scope.name;
}
if($scope.fieldName){
if($scope.fieldValue){
if($scope.fieldName == 'merchantId'){
var m = -1;
if(/^[1-9]\d*$/.test($scope.fieldValue)){
m = parseInt($scope.fieldValue) || -1;
if(m > 2147483647){
m = -1;
}
}
obj[$scope.fieldName] = m;
}else{
obj[$scope.fieldName] = $scope.fieldValue;
}
}else {
obj[$scope.fieldName] = '';
}
}
if($scope.createTime.startDate && $scope.createTime.endDate){
obj.startTime = $scope.createTime.startDate.format('YYYY-MM-DD HH:mm:ss');
obj.endTime = $scope.createTime.endDate.format('YYYY-MM-DD HH:mm:ss');
}
return obj;
}
//查询列表
$scope.roleListForm = function(){
$scope.dtInstance.query(getParams());
}
$scope.addRole = function(){
$state.go('system.userAdmin.roleEdit');
}
$scope.editRole = function(id){
$state.go('system.userAdmin.roleEdit',{id:id});
}
$scope.batchAdd = function(){
$state.go('system.userAdmin.roleBatchEdit',{batchOper:'0'});
}
$scope.batchSub = function(){
$state.go('system.userAdmin.roleBatchEdit',{batchOper:'1'});
}
$scope.deleteRole = function(id){
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'deleteRoleModal',
controller: 'deleteRoleCtrl',
size: 'sm',
resolve: {
id: id,
dtInstance: $scope.dtInstance,
queryParams: getParams()
}
});
}
}
function deleteRoleCtrl($scope, $uibModalInstance, systemService, id, dtInstance, queryParams){
$scope.confirm = function() {
$scope.isWorking = true;
systemService.deleteRole({id: id}, function(result){
$uibModalInstance.close();
if(result.returnCode == '0'){
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('roleCtrl', roleCtrl)
.controller('deleteRoleCtrl', deleteRoleCtrl)
})(angular);