app.controller('powerCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "Restangular", "api_user_data", "api_configure_data", "api_conversation", function($rootScope, $scope, $state, $timeout, $interval, SweetAlert, $modal, Restangular, api_user_data, api_configure_data, api_conversation) { var loginUser = $rootScope.user; $scope.xinzeng=false; $scope.shanchu=false; $scope.bianji=false; $scope.fenpeiquanxian=false; // $scope.role={}; // $scope.role.flag=1; for(var i=0;i 0) { angular.forEach(branch.dashboard, function(item) { if (index.id == item.id) { $scope.dashboard_tree[i].checks = true; } }) } }) } // 责任部门 $scope.hospitalAndDutyDept = {}; $scope.dutyDeptList = []; $scope.branchObj = {}; $scope.getDutyDeptList = function(roleObj) { api_user_data.fetchDataList('branch', { "idx": 0, "sum": 1000 }).then(function(res) { if (res.status == 200) { api_user_data.fetchDataList('dutyDepartment', { "idx": 0, "sum": 1000 }).then(function(response) { if (response.status == 200) { // 院区数据处理 $scope.branchObj = angular.copy(res.list).find(v=>v.children.length>0); $scope.branchObj.children.sort((a,b)=>a.id-b.id); // 清空 response.list.forEach(v=>{ v.flag = false }); $scope.dutyDeptList = response.list; $scope.branchObj.flag = false; $scope.branchObj.children.forEach(v=>{ v.flag = false; }) // 回显数据 if(roleObj){ roleObj.dutyDepts.forEach(v=>{ $scope.dutyDeptList.forEach(vv=>{ if(v.id == vv.id){ vv.flag = true; } }) }) roleObj.branchs.forEach(v=>{ if(v.id == $scope.branchObj.id){ $scope.branchObj.flag = true; } $scope.branchObj.children.forEach(vv=>{ if(v.id == vv.id){ vv.flag = true; } }) }) } // 处理责任科室数据 $scope.hospitalAndDutyDept = {}; $scope.dutyDeptList.forEach(v=>{ if($scope.hospitalAndDutyDept[v.branch]){ $scope.hospitalAndDutyDept[v.branch].push(v); }else{ $scope.hospitalAndDutyDept[v.branch] = [v]; } }) console.log($scope.branchObj,$scope.hospitalAndDutyDept) } else { SweetAlert.swal({ title: "系统错误!", text: "请刷新重试!", type: "error" }); } }); } else { SweetAlert.swal({ title: "系统错误!", text: "请刷新重试!", type: "error" }); } }); }; //角色树 $scope.my_tree = {}; $scope.my_power = {}; $scope.try_async_load = function() { $scope.my_data = []; $scope.doing_async = true; api_user_data.fetchDataList('role', { "idx": 0, "sum": 1000 }).then(function(response) { if (response.status == 200) { var data = response.list; var objects = []; for (var i = 0; i < data.length; i++) { var object = {}; object.id = data[i].id; if (data[i].parent && data[i].parent.id != 0) { object.parent = data[i].parent.id; } angular.extend(object, data[i]); object.label = object.role; if (loginUser.id == 1) { objects.push(object); } else { if (object.rolecode != "system_menus") { objects.push(object); } } } $scope.my_data = convertParentToChildList(objects); $scope.tree_data = angular.copy($scope.my_data); if ($scope.my_data.length > 0) { $scope.doing_async = false; } } else { SweetAlert.swal({ title: "系统错误!", text: "请刷新重试!", type: "error" }); } }); }; function convertListToTree(data, treeMap) { var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup var root = null; //Initially set our loop to null //loop over data for (var i = 0; i < data.length; i++) { var datum = data[i]; //each node will have children, so let's give it a "children" poperty datum.children = []; //add an entry for this node to the map so that any future children can //lookup the parent idToNodeMap[datum.id] = datum; //Does this node have a parent? // console.log("datum="+JSON.stringify(datum)) if (typeof datum.parent === "undefined" || datum.parent === null) { //Doesn't look like it, so this node is the root of the tree root = datum; treeMap[datum.id] = root; } else { //This node has a parent, so let's look it up using the id parentNode = idToNodeMap[datum.parent.id]; //We don't need this property, so let's delete it. // delete datum.parent; //Let's add the current node as a child of the parent node. parentNode.children.push(datum); } } return root; } function convertParentToChildList(data) { var treeMap = {}; var list = []; convertListToTree(data, treeMap); angular.forEach(treeMap, function(item) { list.push(item); }); return list; } $scope.try_async_load(); $scope.getDutyDeptList(); //end power //普通用户菜单权限 $scope.try_async_powerload = function(items) { if (items) { $scope.getbranchs = items.menu; } // $scope.my_power = []; var objects = []; var selected = []; api_user_data.roleMenu(items.id).then(function(response) { console.log(response); // api_configure_data.fetchDataList('menu', { "idx": 0, "sum": 1000 }).then(function(response) { if (response.status == 200) { // //旧的树 // var data = response.data; // var objects = []; // for (var i = 0; i < data.length; i++) { // var object = {}; // object.id = data[i].id; // if (data[i].parent && data[i].parent.id != 0) { // object.parent = data[i].parent.id; // } // angular.extend(object, data[i]); // object.label = object.title; // objects.push(object); // } // selected = angular.copy($scope.tile); // $scope.my_power = angular.copy($scope.tree_power); // if (data.length > 0) { // angular.forEach(selected, function(index, i) { // angular.forEach(objects, function(item) { // if (index.id == item.id) { // selected[i].checks = true; // } // }) // }) // $scope.my_power = convertParentToChildList(selected); // } else { // $scope.my_power = convertParentToChildList($scope.tile); // } // if ($scope.my_power.length > 0) { // $scope.doing_asyncpower = false; // } // 新的树 $scope.allPower_select=[]; var data=response.data; for(var i=0;i<$scope.allPower.length;i++){ $scope.allPower[i].biaoshi=false } $scope.allPower_select=$scope.allPower; for(var i=0;i<$scope.allPower_select.length;i++){ for(var j=0;j 0) { $scope.doing_asyncpower = false; } } else { SweetAlert.swal({ title: "系统错误!", text: "请刷新重试!", type: "error" }); } }); }; $scope.dianjiceshi=function(){ console.log($scope.my_power); console.log($scope.allPower_select); } //普通用户底菜单权限 $scope.allPower=[]; $scope.my_power = []; $scope.tile = []; $scope.try_async_powerloadlow = function() { var objects = []; api_user_data.pageMenuByCode("system_menus").then(function(response) { if (response.status == 200) { var data = response.data; $scope.allPower= response.data; var objects = []; for (var i = 0; i < data.length; i++) { data[i]["biaoshi"]=false; var object = {}; object.id = data[i].id; if (data[i].parent && data[i].parent.id != 0) { object.parent = data[i].parent.id; } angular.extend(object, data[i]); object.label = object.title; objects.push(object); } $scope.tile = objects; $scope.my_power = convertParentToChildList(objects); $scope.tree_power = angular.copy($scope.my_power); if ($scope.my_data.length > 0) { $scope.doing_asyncpower = false; } console.log($scope.my_power) } else { SweetAlert.swal({ title: "系统错误!", text: "请刷新重试!", type: "error" }); } }); }; // $scope.jry_AllPower=[]; // $scope.getJry_AllPower=function(){ // api_user_data.pageMenuByCode("system_menus").then(function(res) { // console.log(res.data); // $scope.jry_AllPower=res.data // }) // } // $scope.getJry_AllPower() //管理员 底菜单 $scope.try_async_powerloadadmin = function() { var objects = []; // api_conversation.pageMenuByCode("system_menus").then(function(response) { api_user_data.getMenu({}).then(function(response) { if (response.status == 200) { var data = response.data; var objects = []; for (var i = 0; i < data.length; i++) { var object = {}; object.id = data[i].id; if (data[i].parent && data[i].parent.id != 0) { object.parent = data[i].parent.id; } angular.extend(object, data[i]); object.label = object.title; objects.push(object); } $scope.tile = objects; $scope.my_power = convertParentToChildList(objects); $scope.tree_power = angular.copy($scope.my_power); if ($scope.tree_power.length > 0) { $scope.doing_asyncpower = false; } } else { SweetAlert.swal({ title: "系统错误!", text: "请刷新重试!", type: "error" }); } }); }; //点击角色 $scope.role = {}; // $scope.role.flag=1; $scope.chaoguan=true;//超级管理员禁止修改判断 $scope.flagSwitch=true; $scope.change = true; $scope.my_tree_handler = function(branch) { console.log(branch); if(branch.flag==0){ $scope.flagSwitch=true }else{ $scope.flagSwitch=false } if(branch.label=="超级管理员"){ $scope.chaoguan=false }else{ $scope.chaoguan=true } $scope.role = branch; for (var i = 0; i < $scope.roledetail.length; i++) { if ($scope.role.model == $scope.roledetail[i].name) { $scope.role.model = { 'id': $scope.roledetail[i].id, 'name': $scope.roledetail[i].name } } } $scope.formlist = branch.dashboard; dashboardaborad($scope.role); $scope.try_async_powerload(branch); $scope.compareDutydept(branch); $scope.change = false; } $scope.compareDutydept = function(roleObj){ // $scope.dutyDeptList.forEach(v=>{ // v.flag = false; // }) // dutyDepts.forEach(v=>{ // $scope.dutyDeptList.forEach(vv=>{ // if(v.id == vv.id){ // vv.flag = true; // } // }) // }) $scope.getDutyDeptList(roleObj); } // if (loginUser.id == 1) { // $scope.try_async_powerloadadmin(); // } else { $scope.try_async_powerloadlow(); // } // $scope.try_async_powerloadadmin(); // console.log(loginUser); //start remove $scope.getbranchs = {}; $scope.formbranch = function(branchData) { $scope.getbranchs = branchData; } //change right $scope.selectAllBiaoshi=true; // 全选/反选 $scope.allSelect=function(){ if($scope.selectAllBiaoshi){ for(var i=0;i<$scope.my_power.length;i++){ $scope.my_power[i].biaoshi=true; if($scope.my_power[i].children){ for(var j=0;j<$scope.my_power[i].children.length;j++){ $scope.my_power[i].children[j].biaoshi=true if($scope.my_power[i].children[j].children){ for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){ $scope.my_power[i].children[j].children[k].biaoshi=true if($scope.my_power[i].children[j].children[k].children){ for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){ $scope.my_power[i].children[j].children[k].children[l].biaoshi=true } } } } } } } $scope.selectAllBiaoshi=false; }else{ for(var i=0;i<$scope.my_power.length;i++){ $scope.my_power[i].biaoshi=false; if($scope.my_power[i].children){ for(var j=0;j<$scope.my_power[i].children.length;j++){ $scope.my_power[i].children[j].biaoshi=false if($scope.my_power[i].children[j].children){ for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){ $scope.my_power[i].children[j].children[k].biaoshi=false if($scope.my_power[i].children[j].children[k].children){ for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){ $scope.my_power[i].children[j].children[k].children[l].biaoshi=false } } } } } } } $scope.selectAllBiaoshi=true; } } // 点击选项 $scope.changeCheckBox1=function(data){ console.log($scope.my_power); for(var i=0;i<$scope.my_power.length;i++){ if(data.id === $scope.my_power[i].id){ if(!$scope.my_power[i].biaoshi){ if($scope.my_power[i].children){ for(var j=0;j<$scope.my_power[i].children.length;j++){ $scope.my_power[i].children[j].biaoshi=false if($scope.my_power[i].children[j].children){ for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){ $scope.my_power[i].children[j].children[k].biaoshi=false if($scope.my_power[i].children[j].children[k].children){ for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){ $scope.my_power[i].children[j].children[k].children[l].biaoshi=false } } } } } } }else{ if($scope.my_power[i].children){ for(var j=0;j<$scope.my_power[i].children.length;j++){ $scope.my_power[i].children[j].biaoshi=true if($scope.my_power[i].children[j].children){ for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){ $scope.my_power[i].children[j].children[k].biaoshi=true if($scope.my_power[i].children[j].children[k].children){ for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){ $scope.my_power[i].children[j].children[k].children[l].biaoshi=true } } } } } } } } } } $scope.changeCheckBox2=function(){ for(var i=0;i<$scope.my_power.length;i++){ if($scope.my_power[i].children){ for(var j=0;j<$scope.my_power[i].children.length;j++){ if(!$scope.my_power[i].children[j].biaoshi){ if($scope.my_power[i].children[j].children){ for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){ $scope.my_power[i].children[j].children[k].biaoshi=false if($scope.my_power[i].children[j].children[k].children){ for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){ $scope.my_power[i].children[j].children[k].children[l].biaoshi=false } } } } }else{ $scope.my_power[i].biaoshi=true } } } } } $scope.changeCheckBox3=function(){ for(var i=0;i<$scope.my_power.length;i++){ if($scope.my_power[i].children){ for(var j=0;j<$scope.my_power[i].children.length;j++){ if($scope.my_power[i].children[j].children){ for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){ if(!$scope.my_power[i].children[j].children[k].biaoshi){ for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){ $scope.my_power[i].children[j].children[k].children[l].biaoshi=false } }else{ $scope.my_power[i].biaoshi=true; $scope.my_power[i].children[j].biaoshi=true; } } } } } } } $scope.changeCheckBox4=function(){ for(var i=0;i<$scope.my_power.length;i++){ if($scope.my_power[i].children){ for(var j=0;j<$scope.my_power[i].children.length;j++){ if($scope.my_power[i].children[j].children){ for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){ if($scope.my_power[i].children[j].children[k].children){ for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){ if($scope.my_power[i].children[j].children[k].children[l].biaoshi){ $scope.my_power[i].biaoshi=true; $scope.my_power[i].children[j].biaoshi=true; $scope.my_power[i].children[j].children[k].biaoshi=true; } } } } } } } } } //修改权限 $scope.changeData = function() { if($scope.role.id){ var menu = []; $rootScope.isMask = true; // 旧的树 // angular.forEach($scope.getbranchs, function(it) { // menu.push({ "id": it.id }); // }) // 新的树 for(var i=0;i<$scope.my_power.length;i++){ if($scope.my_power[i].biaoshi){ menu.push({ "id": $scope.my_power[i].id }); } if($scope.my_power[i].children){ for(var j=0;j<$scope.my_power[i].children.length;j++){ if($scope.my_power[i].children[j].biaoshi){ menu.push({ "id": $scope.my_power[i].children[j].id }); } if($scope.my_power[i].children[j].children){ for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){ if($scope.my_power[i].children[j].children[k].biaoshi){ menu.push({ "id": $scope.my_power[i].children[j].children[k].id }); } if($scope.my_power[i].children[j].children[k].children){ for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){ if($scope.my_power[i].children[j].children[k].children[l].biaoshi){ menu.push({ "id": $scope.my_power[i].children[j].children[k].children[l].id }); } } } } } } } } var branch = { 'menu': menu }; // 院区和责任科室 var dutyDepts = $scope.dutyDeptList.filter(v=>v.flag).map(v=>({id:v.id})); var branchs = []; if($scope.branchObj.flag){ branchs.push($scope.branchObj); } var branchs_lin = $scope.branchObj.children.filter(v=>v.flag); branchs = branchs.concat(branchs_lin); angular.extend(branch, { 'id': $scope.role.id, dutyDepts:dutyDepts,branchs:branchs, 'role': $scope.role.role,'flag':$scope.role.flag, 'rolecode': $scope.role.rolecode, 'roletype': $scope.role.roletype,'remark': $scope.role.remark }) // var modelData = {role: branch}; api_user_data.addData('role', { 'role': branch }).then(function(response) { if (response && response.status == 200) { $scope.role={}; SweetAlert.swal({ title: "提交成功!", type: "success", confirmButtonColor: "#007AFF" }, function() { $rootScope.isMask = false; $scope.try_async_load(); $scope.getDutyDeptList(); }); } else { SweetAlert.swal({ title: "系统错误", text: "系统错误,请稍后重试!", type: "error", confirmButtonColor: "#DD6B55" }, function() { $rootScope.isMask = false; }); } }) }else{ SweetAlert.swal({ title: "操作失败", text: "请选择需要修改的角色!", type: "error", }) } // $state.go('app.system.form',{formKey:'system_add_menu', service:'api_configure_data', model : JSON.stringify(modelData)}); } //新增角色 // $scope.addData = function() { // $state.go('app.system.form', { formKey: 'system_add_menu', service: 'api_configure_data' }); // } //change menu // $scope.choiceMenu = []; // $scope.showHandler = function(branch) { // $scope.choiceMenu = branch; // } // $scope.changeMenu = function() { // // if ($scope.choiceMenu && $scope.choiceMenu != null) { // // } // api_configure_data.fetchDataById('menu', $scope.choiceMenu.id).then(function(response) { // if (response.status == 200) { // if (response.data.link != null) { // response.data.type = "link"; // } else if (response.data.service) { // response.data.type = "service"; // } else if (response.data.event) { // response.data.type = "event"; // } // response.data['menu'] = { parent: response.data.parent }; // var modelData = { model: response.data } // $state.go('app.system.form', { formKey: 'system_add_menu', service: 'api_configure_data', model: JSON.stringify(modelData) }); // } // }) // } //remove menu $scope.removeData = function() { var modalInstance = $modal.open({ templateUrl: 'assets/views/delete.html', controller: function($scope, scope, $modalInstance) { $scope.rmvList = []; angular.forEach(scope.getbranchs, function(item) { $scope.rmvList.push(item.id); }) $scope.ok = function() { $modalInstance.close($scope.rmvList); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; }, size: 'sm', resolve: { scope: function() { return $scope; } } }); modalInstance.result.then(function(selectedItem) { if (selectedItem) { if (selectedItem.length > 0) { api_configure_data.rmvData('menu', selectedItem).then(function(response) { if (response.data) { SweetAlert.swal({ title: "删除成功!", type: "success", confirmButtonColor: "#007AFF" }, function() { if (loginUser.id == 1) { $scope.try_async_powerloadadmin(); } else { $scope.try_async_powerload(); } }); } else { SweetAlert.swal({ title: "操作异常!", text: "系统异常,请稍后重试,或者联系管理员!", type: "error" }); } }) } } }) } //add role $scope.addRole = function() { var modalInstance = $modal.open({ templateUrl: 'assets/views/system/tpl/addpower.html', controller: function($scope, scope, $modalInstance, api_user_data) { $scope.role={ "role":"", "remark":"", "flag":0 } $scope.addSwitch=true; $scope.addSwitchChange=function(data){ console.log(data); if(data==true){ $scope.role.flag=0 }else{ $scope.role.flag=1 } } $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }, { 'id': 4, 'name': '发布流程' }, { 'id': 5, 'name': '知识库模块' }, { 'id': 6, 'name': '资产模块' }, { 'id': 7, 'name': '系统管理模块' }] $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; $scope.ok = function(role) { if(role.role&&role.remark){ if (role.role) { var roledisable = false; for (var i = 0; i < scope.my_data.length; i++) { if (scope.my_data[i].role == role.role) { roledisable = true; break; } } if (!roledisable) { angular.extend(role, { 'roletype': '0' }); if (role.model) { role.model = role.model.name; } var fildata = { loginUser: loginUser, role }; $modalInstance.close(fildata); } else { SweetAlert.swal({ title: "新增失败!", text: "该角色已存在", type: "error" }) } } else { SweetAlert.swal({ title: "新增失败!", text: "请填写角色名", type: "error" }) } }else{ SweetAlert.swal({ title: "新增失败!", text: "请填写必填项", type: "error" }) } } }, resolve: { scope: function() { return $scope; } } }); modalInstance.result.then(function(selectedItem) { if (selectedItem) { api_user_data.addData('role', selectedItem).then(function(response) { if (response) { if (response.status == 200) { SweetAlert.swal({ title: "新增成功!", type: "success" }, function() { $scope.try_async_load(); $scope.getDutyDeptList(); }) } else { SweetAlert.swal({ title: "新增失败!", type: "error" }) } // $modalInstance.close(); } }) } }) } // $scope.addRole = function(role) { // // $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }] // angular.extend(role, { 'roletype': '0' }); // if (role.model) { // role.model = role.model.name; // } // var fildata = { loginUser: loginUser, role }; // // var fildata = { loginUser: loginUser, 'role': { 'id': $scope.role.id, 'role': $scope.role.role, 'roletype': $scope.role.roletype, 'model': model, 'remark': $scope.role.remark } }; // api_user_data.addData('role', fildata).then(function(response) { // if (response) { // if (response.status == 200) { // SweetAlert.swal({ // title: "新增成功!", // type: "success" // }, function() { // $scope.try_async_load(); // // $scope.refreshData('expand-right', defaultFilterData); // }) // } else { // SweetAlert.swal({ // title: "新增失败!", // type: "error" // }) // } // // $modalInstance.close(); // } // }) // } //角色详情 $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }] //change role $scope.changeIfEnableEdit=function(data){ console.log(data); if(data){ $scope.role.flag=0; $scope.flagSwitch=true }else{ $scope.role.flag=1; $scope.flagSwitch=false } } $scope.changerole = function(role) { if($scope.role.id){ if($scope.role.role&&$scope.role.remark){ var model = ""; if ($scope.role.model) { model = $scope.role.model.name } var dutyDepts = $scope.dutyDeptList.filter(v=>v.flag).map(v=>({id:v.id})); var branchs = []; if($scope.branchObj.flag){ branchs.push($scope.branchObj); } var branchs_lin = $scope.branchObj.children.filter(v=>v.flag); branchs = branchs.concat(branchs_lin); var fildata = { loginUser: loginUser, 'role': { 'id': $scope.role.id,dutyDepts:dutyDepts,branchs:branchs,'menu':$scope.role.menu,'flag':$scope.role.flag, 'role': $scope.role.role, 'roletype': $scope.role.roletype, 'model': model, 'remark': $scope.role.remark } }; api_user_data.addData('role', fildata).then(function(response) { if (response) { if (response.status == 200) { $scope.role={}; SweetAlert.swal({ title: "修改成功!", type: "success" }, function() { $scope.try_async_load(); $scope.getDutyDeptList(); // $scope.refreshData('expand-right', defaultFilterData); }) } else { SweetAlert.swal({ title: "修改失败!", type: "error" }) } // $modalInstance.close(); } }) }else{ SweetAlert.swal({ title: "修改失败!", text:"请填写必填项", type: "error" }) } }else{ SweetAlert.swal({ title: "操作失败!", text:"请选择需要修改的角色", type: "error" }) } } // }) // } //change role $scope.changeRole = function() { var modalInstance = $modal.open({ templateUrl: 'assets/views/system/tpl/addpower.html', controller: function($scope, scope, $modalInstance, api_user_data) { $scope.role = scope.role; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; $scope.ok = function(item) { var fildata = { loginUser: loginUser, 'role': { 'id': item.id, 'role': item.role, 'roletype': item.roletype } }; $modalInstance.close(fildata); } }, resolve: { scope: function() { return $scope; } } }); modalInstance.result.then(function(selectedItem) { if (selectedItem) { api_user_data.addData('role', selectedItem).then(function(response) { if (response) { if (response.status == 200) { SweetAlert.swal({ title: "修改成功!", type: "success" }, function() { $scope.try_async_load(); $scope.getDutyDeptList(); // $scope.refreshData('expand-right', defaultFilterData); }) } else { SweetAlert.swal({ title: "修改失败!", type: "error" }) } // $modalInstance.close(); } }) } }) } //remove role $scope.removeRole = function() { if ($scope.role && $scope.role.roletype == 0) { var modalInstance = $modal.open({ templateUrl: 'assets/views/delete.html', controller: function($scope, scope, $modalInstance) { var rmvList = []; // angular.forEach(scope.getbranchs, function(item) { // $scope.rmvList.push(item.id); // }) rmvList.push(scope.role.id); $scope.ok = function() { $modalInstance.close(rmvList); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; $scope.title = '角色删除'; $scope.connect = '是否删除该角色' }, size: 'sm', resolve: { scope: function() { return $scope; } } }); modalInstance.result.then(function(selectedItem) { if (selectedItem) { if (selectedItem.length > 0) { api_user_data.rmvData('role', selectedItem).then(function(response) { if (response.data) { $scope.role={}; SweetAlert.swal({ title: "删除成功!", type: "success", confirmButtonColor: "#007AFF" }, function() { $scope.try_async_load(); $scope.getDutyDeptList(); }); } else { SweetAlert.swal({ title: "操作异常!", text: "系统异常,请稍后重试,或者联系管理员!", type: "error" }); } }) } } }) } else { SweetAlert.swal({ title: "操作错误!", text: "该角色不能删除!", type: "error" }); } } //仪表盘 //查看仪表盘权限 $scope.doing_asyncdash = true; $scope.dashboard_tree = []; // $scope.try_async_dashboard = function() { // api_user_data.fetchDataList("dashboard", { "idx": 0, "sum": 1000 }).then(function(response) { // if (response.status == 200) { // var data = response.list; // var objects = []; // for (var i = 0; i < data.length; i++) { // var object = {}; // object.id = data[i].id; // object.label = data[i].name; // objects.push(object); // } // $scope.dashboard_tree = objects; // $scope.dashboard_data = angular.copy($scope.dashboard_tree); // if ($scope.dashboard_data.length > 0) { // $scope.doing_asyncdash = false; // } // } else { // SweetAlert.swal({ // title: "系统错误!", // text: "请刷新重试!", // type: "error" // }); // } // }); // } // $scope.try_async_dashboard(); $scope.formlist = {}; $scope.formdashboard = function(branchData) { // $scope.formlist = {}; $scope.formlist = branchData; } //修改仪表盘权限 // var dashboard = []; $scope.changeDashboard = function() { var firldata = {}; var dashboard = []; $rootScope.isMask = true; angular.forEach($scope.formlist, function(item) { dashboard.push({ 'id': item.id, 'name': item.label }); }) firldata = { 'dashboard': dashboard, 'id': $scope.role.id, 'role': $scope.role.role, 'rolecode': $scope.role.rolecode, 'roletype': $scope.role.roletype, 'menu': $scope.role.menu } api_user_data.addData('role', { 'role': firldata }).then(function(response) { if (response && response.status == 200) { $scope.getDutyDeptList(); $scope.try_async_load(); SweetAlert.swal({ title: "提交成功!", type: "success", confirmButtonColor: "#007AFF" }, function() { $rootScope.isMask = false; // $scope.formlist = {} }); } else { SweetAlert.swal({ title: "系统错误", text: "系统错误,请稍后重试!", type: "error", confirmButtonColor: "#DD6B55" }, function() { $rootScope.isMask = false; }); } }) } }]);