(function ($app) { $app.module('ylmis').controller('roleCtrl', function ($scope, $http, $filter, $modal, $ocLazyLoad, $alert, $loading, $state, AuthUser, $bsRouterState, $rootScope) { $scope.dataList = []; $state.params = $bsRouterState.$params($scope); //初始化查询参数 $scope.selectparams = { roleName: '', pageIndex: 1, pageSize: 10 }; $scope.pageInfo = { ptotal: 0 }; //监视页数变化 $scope.$watch("selectparams.pageIndex", function (newVal, oldVal) { if ($scope.pageInfo.ptotal > 0) { $scope.loadData(); } }); //查询 $scope.search = function () { $scope.loadData(); }; //加载列表数据 $scope.loadData = function () { $http ({ method: 'post', url: '../../api/systemsetting/Role/GetRoleList', data: $scope.selectparams }).then(function (result) { $scope.dataList = result.data.Data.rows; $scope.pageInfo.ptotal = result.data.Data.total; }); }; $scope.showMsg = function (title, content) { $alert({ title: title + ':', content: content, placement: 'top', type: 'info', show: true, duration: 3 }); }; $scope.addRole = function () { $scope.edit(null, '添加角色'); }; $scope.editRole = function (roleID) { $scope.edit(roleID, '修改角色'); }; $scope.delRole = function () { if (confirm("是否要删除该角色?")) { var ids = $.map($filter('filter')($scope.dataList, { rowChecked: true }), function (x) { return x.RoleID; }); if (ids.length <= 0) { $scope.showMsg("消息", "请选择需要删除的数据"); return false; } $http.post('../../api/systemsetting/Role/Delete', { roleIDs: ids }).then(function (res) { if (res.data.IsSuccess) { $scope.loadData(); $scope.showMsg('成功', '删除成功'); } else { $scope.showMsg('错误', res.data.Message); } }); } }; $scope.editData = {}; $scope.edit = function (id, title) { $scope.editData.params = { roleID: id, title: title }; $scope.editData.parentLoad = $scope.loadData; editModal.$promise.then(editModal.show); }; //定义模态框 var editModal = $modal({ resolve: { load: ['$ocLazyLoad', function ($ocLazyLoad) { $ocLazyLoad.load('systemsetting/role/edit.js?' + window.sysVersion); }] }, scope: $scope, controller: 'editRoleCtrl', templateUrl: '../main/systemsetting/role/edit.html', show: false, animation: 'am-fade-and-slide-top' }); //添加人员管理弹出模块 var roleUsersModal = $modal({ resolve: { load: ['$ocLazyLoad', function ($ocLazyLoad) { $rootScope.aid = "100"; return $ocLazyLoad.load('../main/systemsetting/role/UserManageList.js'); }] }, scope: $scope, controller: 'UserManageListController', templateUrl: '../main/systemsetting/role/UserManageList.html', show: false, animation: 'am-fade-and-slide-top' }); $scope.editRoleUsers = function (e) { $rootScope.role = { roleName: e.RoleName, roleId: e.RoleID } roleUsersModal.$promise.then(roleUsersModal.show); }; $scope.hideRoleUsersModal = function () { roleUsersModal.$promise.then(roleUsersModal.hide); } $scope.loadData(); }); })(angular);