powerCtrl.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. 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) {
  2. var loginUser = $rootScope.user;
  3. $scope.xinzeng=false;
  4. $scope.shanchu=false;
  5. $scope.bianji=false;
  6. $scope.fenpeiquanxian=false;
  7. // $scope.role={};
  8. // $scope.role.flag=1;
  9. for(var i=0;i<loginUser.menu.length;i++){
  10. if(loginUser.menu[i].link=="quanxianguanli_xinzeng"){
  11. $scope.xinzeng=true
  12. }
  13. if(loginUser.menu[i].link=="quanxianguanli_shanchu"){
  14. $scope.shanchu=true
  15. }
  16. if(loginUser.menu[i].link=="quanxianguanli_bianji"){
  17. $scope.bianji=true
  18. }
  19. if(loginUser.menu[i].link=="quanxianguanli_fenpeiquanxian"){
  20. $scope.fenpeiquanxian=true
  21. }
  22. }
  23. //user tree
  24. var apple_selected, tree, treedata_avm, treedata_geography;
  25. var i = 0;
  26. $scope.bodyHeight = Math.max((window.innerHeight - 290), 500);
  27. $(window).resize(function() {
  28. $scope.bodyHeight = Math.max((window.innerHeight - 290), 500);
  29. });
  30. $rootScope.isMask = false;
  31. //角色仪表权限
  32. function dashboardaborad(branch) {
  33. $scope.dashboard_tree = angular.copy($scope.dashboard_data);
  34. angular.forEach($scope.dashboard_tree, function(index, i) {
  35. if (branch.dashboard && branch.dashboard.length > 0) {
  36. angular.forEach(branch.dashboard, function(item) {
  37. if (index.id == item.id) {
  38. $scope.dashboard_tree[i].checks = true;
  39. }
  40. })
  41. }
  42. })
  43. }
  44. // 责任部门
  45. $scope.hospitalAndDutyDept = {};
  46. $scope.dutyDeptList = [];
  47. $scope.branchObj = {};
  48. $scope.getDutyDeptList = function(roleObj) {
  49. api_user_data.fetchDataList('branch', { "idx": 0, "sum": 1000 }).then(function(res) {
  50. if (res.status == 200) {
  51. api_user_data.fetchDataList('dutyDepartment', { "idx": 0, "sum": 1000 }).then(function(response) {
  52. if (response.status == 200) {
  53. // 院区数据处理
  54. $scope.branchObj = angular.copy(res.list).find(v=>v.children.length>0);
  55. $scope.branchObj.children.sort((a,b)=>a.id-b.id);
  56. // 清空
  57. response.list.forEach(v=>{
  58. v.flag = false
  59. });
  60. $scope.dutyDeptList = response.list;
  61. $scope.branchObj.flag = false;
  62. $scope.branchObj.children.forEach(v=>{
  63. v.flag = false;
  64. })
  65. // 回显数据
  66. if(roleObj){
  67. roleObj.dutyDepts.forEach(v=>{
  68. $scope.dutyDeptList.forEach(vv=>{
  69. if(v.id == vv.id){
  70. vv.flag = true;
  71. }
  72. })
  73. })
  74. roleObj.branchs.forEach(v=>{
  75. if(v.id == $scope.branchObj.id){
  76. $scope.branchObj.flag = true;
  77. }
  78. $scope.branchObj.children.forEach(vv=>{
  79. if(v.id == vv.id){
  80. vv.flag = true;
  81. }
  82. })
  83. })
  84. }
  85. // 处理责任科室数据
  86. $scope.hospitalAndDutyDept = {};
  87. $scope.dutyDeptList.forEach(v=>{
  88. if($scope.hospitalAndDutyDept[v.branch]){
  89. $scope.hospitalAndDutyDept[v.branch].push(v);
  90. }else{
  91. $scope.hospitalAndDutyDept[v.branch] = [v];
  92. }
  93. })
  94. console.log($scope.branchObj,$scope.hospitalAndDutyDept)
  95. } else {
  96. SweetAlert.swal({
  97. title: "系统错误!",
  98. text: "请刷新重试!",
  99. type: "error"
  100. });
  101. }
  102. });
  103. } else {
  104. SweetAlert.swal({
  105. title: "系统错误!",
  106. text: "请刷新重试!",
  107. type: "error"
  108. });
  109. }
  110. });
  111. };
  112. //角色树
  113. $scope.my_tree = {};
  114. $scope.my_power = {};
  115. $scope.try_async_load = function() {
  116. $scope.my_data = [];
  117. $scope.doing_async = true;
  118. api_user_data.fetchDataList('role', { "idx": 0, "sum": 1000 }).then(function(response) {
  119. if (response.status == 200) {
  120. var data = response.list;
  121. var objects = [];
  122. for (var i = 0; i < data.length; i++) {
  123. var object = {};
  124. object.id = data[i].id;
  125. if (data[i].parent && data[i].parent.id != 0) {
  126. object.parent = data[i].parent.id;
  127. }
  128. angular.extend(object, data[i]);
  129. object.label = object.role;
  130. if (loginUser.id == 1) {
  131. objects.push(object);
  132. } else {
  133. if (object.rolecode != "system_menus") {
  134. objects.push(object);
  135. }
  136. }
  137. }
  138. $scope.my_data = convertParentToChildList(objects);
  139. $scope.tree_data = angular.copy($scope.my_data);
  140. if ($scope.my_data.length > 0) {
  141. $scope.doing_async = false;
  142. }
  143. } else {
  144. SweetAlert.swal({
  145. title: "系统错误!",
  146. text: "请刷新重试!",
  147. type: "error"
  148. });
  149. }
  150. });
  151. };
  152. function convertListToTree(data, treeMap) {
  153. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  154. var root = null; //Initially set our loop to null
  155. //loop over data
  156. for (var i = 0; i < data.length; i++) {
  157. var datum = data[i];
  158. //each node will have children, so let's give it a "children" poperty
  159. datum.children = [];
  160. //add an entry for this node to the map so that any future children can
  161. //lookup the parent
  162. idToNodeMap[datum.id] = datum;
  163. //Does this node have a parent?
  164. // console.log("datum="+JSON.stringify(datum))
  165. if (typeof datum.parent === "undefined" || datum.parent === null) {
  166. //Doesn't look like it, so this node is the root of the tree
  167. root = datum;
  168. treeMap[datum.id] = root;
  169. } else {
  170. //This node has a parent, so let's look it up using the id
  171. parentNode = idToNodeMap[datum.parent.id];
  172. //We don't need this property, so let's delete it.
  173. // delete datum.parent;
  174. //Let's add the current node as a child of the parent node.
  175. parentNode.children.push(datum);
  176. }
  177. }
  178. return root;
  179. }
  180. function convertParentToChildList(data) {
  181. var treeMap = {};
  182. var list = [];
  183. convertListToTree(data, treeMap);
  184. angular.forEach(treeMap, function(item) {
  185. list.push(item);
  186. });
  187. return list;
  188. }
  189. $scope.try_async_load();
  190. $scope.getDutyDeptList();
  191. //end power
  192. //普通用户菜单权限
  193. $scope.try_async_powerload = function(items) {
  194. if (items) {
  195. $scope.getbranchs = items.menu;
  196. }
  197. // $scope.my_power = [];
  198. var objects = [];
  199. var selected = [];
  200. api_user_data.roleMenu(items.id).then(function(response) {
  201. console.log(response);
  202. // api_configure_data.fetchDataList('menu', { "idx": 0, "sum": 1000 }).then(function(response) {
  203. if (response.status == 200) {
  204. // //旧的树
  205. // var data = response.data;
  206. // var objects = [];
  207. // for (var i = 0; i < data.length; i++) {
  208. // var object = {};
  209. // object.id = data[i].id;
  210. // if (data[i].parent && data[i].parent.id != 0) {
  211. // object.parent = data[i].parent.id;
  212. // }
  213. // angular.extend(object, data[i]);
  214. // object.label = object.title;
  215. // objects.push(object);
  216. // }
  217. // selected = angular.copy($scope.tile);
  218. // $scope.my_power = angular.copy($scope.tree_power);
  219. // if (data.length > 0) {
  220. // angular.forEach(selected, function(index, i) {
  221. // angular.forEach(objects, function(item) {
  222. // if (index.id == item.id) {
  223. // selected[i].checks = true;
  224. // }
  225. // })
  226. // })
  227. // $scope.my_power = convertParentToChildList(selected);
  228. // } else {
  229. // $scope.my_power = convertParentToChildList($scope.tile);
  230. // }
  231. // if ($scope.my_power.length > 0) {
  232. // $scope.doing_asyncpower = false;
  233. // }
  234. // 新的树
  235. $scope.allPower_select=[];
  236. var data=response.data;
  237. for(var i=0;i<$scope.allPower.length;i++){
  238. $scope.allPower[i].biaoshi=false
  239. }
  240. $scope.allPower_select=$scope.allPower;
  241. for(var i=0;i<$scope.allPower_select.length;i++){
  242. for(var j=0;j<data.length;j++){
  243. if($scope.allPower_select[i].id==data[j].id){
  244. $scope.allPower_select[i].biaoshi=true
  245. }
  246. }
  247. }
  248. var objects = [];
  249. for (var i = 0; i < $scope.allPower_select.length; i++) {
  250. var object = {};
  251. object.id = $scope.allPower_select[i].id;
  252. if ($scope.allPower_select[i].parent && $scope.allPower_select[i].parent.id != 0) {
  253. object.parent = $scope.allPower_select[i].parent.id;
  254. }
  255. angular.extend(object, $scope.allPower_select[i]);
  256. object.label = object.title;
  257. objects.push(object);
  258. }
  259. $scope.tile = objects;
  260. $scope.my_power = convertParentToChildList(objects);
  261. $scope.tree_power = angular.copy($scope.my_power);
  262. if ($scope.my_data.length > 0) {
  263. $scope.doing_asyncpower = false;
  264. }
  265. } else {
  266. SweetAlert.swal({
  267. title: "系统错误!",
  268. text: "请刷新重试!",
  269. type: "error"
  270. });
  271. }
  272. });
  273. };
  274. $scope.dianjiceshi=function(){
  275. console.log($scope.my_power);
  276. console.log($scope.allPower_select);
  277. }
  278. //普通用户底菜单权限
  279. $scope.allPower=[];
  280. $scope.my_power = [];
  281. $scope.tile = [];
  282. $scope.try_async_powerloadlow = function() {
  283. var objects = [];
  284. api_user_data.pageMenuByCode("system_menus").then(function(response) {
  285. if (response.status == 200) {
  286. var data = response.data;
  287. $scope.allPower= response.data;
  288. var objects = [];
  289. for (var i = 0; i < data.length; i++) {
  290. data[i]["biaoshi"]=false;
  291. var object = {};
  292. object.id = data[i].id;
  293. if (data[i].parent && data[i].parent.id != 0) {
  294. object.parent = data[i].parent.id;
  295. }
  296. angular.extend(object, data[i]);
  297. object.label = object.title;
  298. objects.push(object);
  299. }
  300. $scope.tile = objects;
  301. $scope.my_power = convertParentToChildList(objects);
  302. $scope.tree_power = angular.copy($scope.my_power);
  303. if ($scope.my_data.length > 0) {
  304. $scope.doing_asyncpower = false;
  305. }
  306. console.log($scope.my_power)
  307. } else {
  308. SweetAlert.swal({
  309. title: "系统错误!",
  310. text: "请刷新重试!",
  311. type: "error"
  312. });
  313. }
  314. });
  315. };
  316. // $scope.jry_AllPower=[];
  317. // $scope.getJry_AllPower=function(){
  318. // api_user_data.pageMenuByCode("system_menus").then(function(res) {
  319. // console.log(res.data);
  320. // $scope.jry_AllPower=res.data
  321. // })
  322. // }
  323. // $scope.getJry_AllPower()
  324. //管理员 底菜单
  325. $scope.try_async_powerloadadmin = function() {
  326. var objects = [];
  327. // api_conversation.pageMenuByCode("system_menus").then(function(response) {
  328. api_user_data.getMenu({}).then(function(response) {
  329. if (response.status == 200) {
  330. var data = response.data;
  331. var objects = [];
  332. for (var i = 0; i < data.length; i++) {
  333. var object = {};
  334. object.id = data[i].id;
  335. if (data[i].parent && data[i].parent.id != 0) {
  336. object.parent = data[i].parent.id;
  337. }
  338. angular.extend(object, data[i]);
  339. object.label = object.title;
  340. objects.push(object);
  341. }
  342. $scope.tile = objects;
  343. $scope.my_power = convertParentToChildList(objects);
  344. $scope.tree_power = angular.copy($scope.my_power);
  345. if ($scope.tree_power.length > 0) {
  346. $scope.doing_asyncpower = false;
  347. }
  348. } else {
  349. SweetAlert.swal({
  350. title: "系统错误!",
  351. text: "请刷新重试!",
  352. type: "error"
  353. });
  354. }
  355. });
  356. };
  357. //点击角色
  358. $scope.role = {};
  359. // $scope.role.flag=1;
  360. $scope.chaoguan=true;//超级管理员禁止修改判断
  361. $scope.flagSwitch=true;
  362. $scope.change = true;
  363. $scope.my_tree_handler = function(branch) {
  364. console.log(branch);
  365. if(branch.flag==0){
  366. $scope.flagSwitch=true
  367. }else{
  368. $scope.flagSwitch=false
  369. }
  370. if(branch.label=="超级管理员"){
  371. $scope.chaoguan=false
  372. }else{
  373. $scope.chaoguan=true
  374. }
  375. $scope.role = branch;
  376. for (var i = 0; i < $scope.roledetail.length; i++) {
  377. if ($scope.role.model == $scope.roledetail[i].name) {
  378. $scope.role.model = { 'id': $scope.roledetail[i].id, 'name': $scope.roledetail[i].name }
  379. }
  380. }
  381. $scope.formlist = branch.dashboard;
  382. dashboardaborad($scope.role);
  383. $scope.try_async_powerload(branch);
  384. $scope.compareDutydept(branch);
  385. $scope.change = false;
  386. }
  387. $scope.compareDutydept = function(roleObj){
  388. // $scope.dutyDeptList.forEach(v=>{
  389. // v.flag = false;
  390. // })
  391. // dutyDepts.forEach(v=>{
  392. // $scope.dutyDeptList.forEach(vv=>{
  393. // if(v.id == vv.id){
  394. // vv.flag = true;
  395. // }
  396. // })
  397. // })
  398. $scope.getDutyDeptList(roleObj);
  399. }
  400. // if (loginUser.id == 1) {
  401. // $scope.try_async_powerloadadmin();
  402. // } else {
  403. $scope.try_async_powerloadlow();
  404. // }
  405. // $scope.try_async_powerloadadmin();
  406. // console.log(loginUser);
  407. //start remove
  408. $scope.getbranchs = {};
  409. $scope.formbranch = function(branchData) {
  410. $scope.getbranchs = branchData;
  411. }
  412. //change right
  413. $scope.selectAllBiaoshi=true;
  414. // 全选/反选
  415. $scope.allSelect=function(){
  416. if($scope.selectAllBiaoshi){
  417. for(var i=0;i<$scope.my_power.length;i++){
  418. $scope.my_power[i].biaoshi=true;
  419. if($scope.my_power[i].children){
  420. for(var j=0;j<$scope.my_power[i].children.length;j++){
  421. $scope.my_power[i].children[j].biaoshi=true
  422. if($scope.my_power[i].children[j].children){
  423. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  424. $scope.my_power[i].children[j].children[k].biaoshi=true
  425. if($scope.my_power[i].children[j].children[k].children){
  426. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  427. $scope.my_power[i].children[j].children[k].children[l].biaoshi=true
  428. }
  429. }
  430. }
  431. }
  432. }
  433. }
  434. }
  435. $scope.selectAllBiaoshi=false;
  436. }else{
  437. for(var i=0;i<$scope.my_power.length;i++){
  438. $scope.my_power[i].biaoshi=false;
  439. if($scope.my_power[i].children){
  440. for(var j=0;j<$scope.my_power[i].children.length;j++){
  441. $scope.my_power[i].children[j].biaoshi=false
  442. if($scope.my_power[i].children[j].children){
  443. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  444. $scope.my_power[i].children[j].children[k].biaoshi=false
  445. if($scope.my_power[i].children[j].children[k].children){
  446. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  447. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  448. }
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }
  455. $scope.selectAllBiaoshi=true;
  456. }
  457. }
  458. // 点击选项
  459. $scope.changeCheckBox1=function(data){
  460. console.log($scope.my_power);
  461. for(var i=0;i<$scope.my_power.length;i++){
  462. if(data.id === $scope.my_power[i].id){
  463. if(!$scope.my_power[i].biaoshi){
  464. if($scope.my_power[i].children){
  465. for(var j=0;j<$scope.my_power[i].children.length;j++){
  466. $scope.my_power[i].children[j].biaoshi=false
  467. if($scope.my_power[i].children[j].children){
  468. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  469. $scope.my_power[i].children[j].children[k].biaoshi=false
  470. if($scope.my_power[i].children[j].children[k].children){
  471. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  472. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  473. }
  474. }
  475. }
  476. }
  477. }
  478. }
  479. }else{
  480. if($scope.my_power[i].children){
  481. for(var j=0;j<$scope.my_power[i].children.length;j++){
  482. $scope.my_power[i].children[j].biaoshi=true
  483. if($scope.my_power[i].children[j].children){
  484. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  485. $scope.my_power[i].children[j].children[k].biaoshi=true
  486. if($scope.my_power[i].children[j].children[k].children){
  487. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  488. $scope.my_power[i].children[j].children[k].children[l].biaoshi=true
  489. }
  490. }
  491. }
  492. }
  493. }
  494. }
  495. }
  496. }
  497. }
  498. }
  499. $scope.changeCheckBox2=function(){
  500. for(var i=0;i<$scope.my_power.length;i++){
  501. if($scope.my_power[i].children){
  502. for(var j=0;j<$scope.my_power[i].children.length;j++){
  503. if(!$scope.my_power[i].children[j].biaoshi){
  504. if($scope.my_power[i].children[j].children){
  505. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  506. $scope.my_power[i].children[j].children[k].biaoshi=false
  507. if($scope.my_power[i].children[j].children[k].children){
  508. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  509. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  510. }
  511. }
  512. }
  513. }
  514. }else{
  515. $scope.my_power[i].biaoshi=true
  516. }
  517. }
  518. }
  519. }
  520. }
  521. $scope.changeCheckBox3=function(){
  522. for(var i=0;i<$scope.my_power.length;i++){
  523. if($scope.my_power[i].children){
  524. for(var j=0;j<$scope.my_power[i].children.length;j++){
  525. if($scope.my_power[i].children[j].children){
  526. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  527. if(!$scope.my_power[i].children[j].children[k].biaoshi){
  528. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  529. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  530. }
  531. }else{
  532. $scope.my_power[i].biaoshi=true;
  533. $scope.my_power[i].children[j].biaoshi=true;
  534. }
  535. }
  536. }
  537. }
  538. }
  539. }
  540. }
  541. $scope.changeCheckBox4=function(){
  542. for(var i=0;i<$scope.my_power.length;i++){
  543. if($scope.my_power[i].children){
  544. for(var j=0;j<$scope.my_power[i].children.length;j++){
  545. if($scope.my_power[i].children[j].children){
  546. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  547. if($scope.my_power[i].children[j].children[k].children){
  548. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  549. if($scope.my_power[i].children[j].children[k].children[l].biaoshi){
  550. $scope.my_power[i].biaoshi=true;
  551. $scope.my_power[i].children[j].biaoshi=true;
  552. $scope.my_power[i].children[j].children[k].biaoshi=true;
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. }
  560. }
  561. }
  562. //修改权限
  563. $scope.changeData = function() {
  564. if($scope.role.id){
  565. var menu = [];
  566. $rootScope.isMask = true;
  567. // 旧的树
  568. // angular.forEach($scope.getbranchs, function(it) {
  569. // menu.push({ "id": it.id });
  570. // })
  571. // 新的树
  572. for(var i=0;i<$scope.my_power.length;i++){
  573. if($scope.my_power[i].biaoshi){
  574. menu.push({ "id": $scope.my_power[i].id });
  575. }
  576. if($scope.my_power[i].children){
  577. for(var j=0;j<$scope.my_power[i].children.length;j++){
  578. if($scope.my_power[i].children[j].biaoshi){
  579. menu.push({ "id": $scope.my_power[i].children[j].id });
  580. }
  581. if($scope.my_power[i].children[j].children){
  582. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  583. if($scope.my_power[i].children[j].children[k].biaoshi){
  584. menu.push({ "id": $scope.my_power[i].children[j].children[k].id });
  585. }
  586. if($scope.my_power[i].children[j].children[k].children){
  587. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  588. if($scope.my_power[i].children[j].children[k].children[l].biaoshi){
  589. menu.push({ "id": $scope.my_power[i].children[j].children[k].children[l].id });
  590. }
  591. }
  592. }
  593. }
  594. }
  595. }
  596. }
  597. }
  598. var branch = { 'menu': menu };
  599. // 院区和责任科室
  600. var dutyDepts = $scope.dutyDeptList.filter(v=>v.flag).map(v=>({id:v.id}));
  601. var branchs = [];
  602. if($scope.branchObj.flag){
  603. branchs.push($scope.branchObj);
  604. }
  605. var branchs_lin = $scope.branchObj.children.filter(v=>v.flag);
  606. branchs = branchs.concat(branchs_lin);
  607. 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 })
  608. // var modelData = {role: branch};
  609. api_user_data.addData('role', { 'role': branch }).then(function(response) {
  610. if (response && response.status == 200) {
  611. $scope.role={};
  612. SweetAlert.swal({
  613. title: "提交成功!",
  614. type: "success",
  615. confirmButtonColor: "#007AFF"
  616. }, function() {
  617. $rootScope.isMask = false;
  618. $scope.try_async_load();
  619. $scope.getDutyDeptList();
  620. });
  621. } else {
  622. SweetAlert.swal({
  623. title: "系统错误",
  624. text: "系统错误,请稍后重试!",
  625. type: "error",
  626. confirmButtonColor: "#DD6B55"
  627. }, function() {
  628. $rootScope.isMask = false;
  629. });
  630. }
  631. })
  632. }else{
  633. SweetAlert.swal({
  634. title: "操作失败",
  635. text: "请选择需要修改的角色!",
  636. type: "error",
  637. })
  638. }
  639. // $state.go('app.system.form',{formKey:'system_add_menu', service:'api_configure_data', model : JSON.stringify(modelData)});
  640. }
  641. //新增角色
  642. // $scope.addData = function() {
  643. // $state.go('app.system.form', { formKey: 'system_add_menu', service: 'api_configure_data' });
  644. // }
  645. //change menu
  646. // $scope.choiceMenu = [];
  647. // $scope.showHandler = function(branch) {
  648. // $scope.choiceMenu = branch;
  649. // }
  650. // $scope.changeMenu = function() {
  651. // // if ($scope.choiceMenu && $scope.choiceMenu != null) {
  652. // // }
  653. // api_configure_data.fetchDataById('menu', $scope.choiceMenu.id).then(function(response) {
  654. // if (response.status == 200) {
  655. // if (response.data.link != null) {
  656. // response.data.type = "link";
  657. // } else if (response.data.service) {
  658. // response.data.type = "service";
  659. // } else if (response.data.event) {
  660. // response.data.type = "event";
  661. // }
  662. // response.data['menu'] = { parent: response.data.parent };
  663. // var modelData = { model: response.data }
  664. // $state.go('app.system.form', { formKey: 'system_add_menu', service: 'api_configure_data', model: JSON.stringify(modelData) });
  665. // }
  666. // })
  667. // }
  668. //remove menu
  669. $scope.removeData = function() {
  670. var modalInstance = $modal.open({
  671. templateUrl: 'assets/views/delete.html',
  672. controller: function($scope, scope, $modalInstance) {
  673. $scope.rmvList = [];
  674. angular.forEach(scope.getbranchs, function(item) {
  675. $scope.rmvList.push(item.id);
  676. })
  677. $scope.ok = function() {
  678. $modalInstance.close($scope.rmvList);
  679. };
  680. $scope.cancel = function() {
  681. $modalInstance.dismiss('cancel');
  682. };
  683. },
  684. size: 'sm',
  685. resolve: {
  686. scope: function() {
  687. return $scope;
  688. }
  689. }
  690. });
  691. modalInstance.result.then(function(selectedItem) {
  692. if (selectedItem) {
  693. if (selectedItem.length > 0) {
  694. api_configure_data.rmvData('menu', selectedItem).then(function(response) {
  695. if (response.data) {
  696. SweetAlert.swal({
  697. title: "删除成功!",
  698. type: "success",
  699. confirmButtonColor: "#007AFF"
  700. }, function() {
  701. if (loginUser.id == 1) {
  702. $scope.try_async_powerloadadmin();
  703. } else {
  704. $scope.try_async_powerload();
  705. }
  706. });
  707. } else {
  708. SweetAlert.swal({
  709. title: "操作异常!",
  710. text: "系统异常,请稍后重试,或者联系管理员!",
  711. type: "error"
  712. });
  713. }
  714. })
  715. }
  716. }
  717. })
  718. }
  719. //add role
  720. $scope.addRole = function() {
  721. var modalInstance = $modal.open({
  722. templateUrl: 'assets/views/system/tpl/addpower.html',
  723. controller: function($scope, scope, $modalInstance, api_user_data) {
  724. $scope.role={
  725. "role":"",
  726. "remark":"",
  727. "flag":0
  728. }
  729. $scope.addSwitch=true;
  730. $scope.addSwitchChange=function(data){
  731. console.log(data);
  732. if(data==true){
  733. $scope.role.flag=0
  734. }else{
  735. $scope.role.flag=1
  736. }
  737. }
  738. $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }, { 'id': 4, 'name': '发布流程' }, { 'id': 5, 'name': '知识库模块' }, { 'id': 6, 'name': '资产模块' }, { 'id': 7, 'name': '系统管理模块' }]
  739. $scope.cancel = function() {
  740. $modalInstance.dismiss('cancel');
  741. };
  742. $scope.ok = function(role) {
  743. if(role.role&&role.remark){
  744. if (role.role) {
  745. var roledisable = false;
  746. for (var i = 0; i < scope.my_data.length; i++) {
  747. if (scope.my_data[i].role == role.role) {
  748. roledisable = true;
  749. break;
  750. }
  751. }
  752. if (!roledisable) {
  753. angular.extend(role, { 'roletype': '0' });
  754. if (role.model) {
  755. role.model = role.model.name;
  756. }
  757. var fildata = { loginUser: loginUser, role };
  758. $modalInstance.close(fildata);
  759. } else {
  760. SweetAlert.swal({
  761. title: "新增失败!",
  762. text: "该角色已存在",
  763. type: "error"
  764. })
  765. }
  766. } else {
  767. SweetAlert.swal({
  768. title: "新增失败!",
  769. text: "请填写角色名",
  770. type: "error"
  771. })
  772. }
  773. }else{
  774. SweetAlert.swal({
  775. title: "新增失败!",
  776. text: "请填写必填项",
  777. type: "error"
  778. })
  779. }
  780. }
  781. },
  782. resolve: {
  783. scope: function() {
  784. return $scope;
  785. }
  786. }
  787. });
  788. modalInstance.result.then(function(selectedItem) {
  789. if (selectedItem) {
  790. api_user_data.addData('role', selectedItem).then(function(response) {
  791. if (response) {
  792. if (response.status == 200) {
  793. SweetAlert.swal({
  794. title: "新增成功!",
  795. type: "success"
  796. }, function() {
  797. $scope.try_async_load();
  798. $scope.getDutyDeptList();
  799. })
  800. } else {
  801. SweetAlert.swal({
  802. title: "新增失败!",
  803. type: "error"
  804. })
  805. }
  806. // $modalInstance.close();
  807. }
  808. })
  809. }
  810. })
  811. }
  812. // $scope.addRole = function(role) {
  813. // // $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }]
  814. // angular.extend(role, { 'roletype': '0' });
  815. // if (role.model) {
  816. // role.model = role.model.name;
  817. // }
  818. // var fildata = { loginUser: loginUser, role };
  819. // // var fildata = { loginUser: loginUser, 'role': { 'id': $scope.role.id, 'role': $scope.role.role, 'roletype': $scope.role.roletype, 'model': model, 'remark': $scope.role.remark } };
  820. // api_user_data.addData('role', fildata).then(function(response) {
  821. // if (response) {
  822. // if (response.status == 200) {
  823. // SweetAlert.swal({
  824. // title: "新增成功!",
  825. // type: "success"
  826. // }, function() {
  827. // $scope.try_async_load();
  828. // // $scope.refreshData('expand-right', defaultFilterData);
  829. // })
  830. // } else {
  831. // SweetAlert.swal({
  832. // title: "新增失败!",
  833. // type: "error"
  834. // })
  835. // }
  836. // // $modalInstance.close();
  837. // }
  838. // })
  839. // }
  840. //角色详情
  841. $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }]
  842. //change role
  843. $scope.changeIfEnableEdit=function(data){
  844. console.log(data);
  845. if(data){
  846. $scope.role.flag=0;
  847. $scope.flagSwitch=true
  848. }else{
  849. $scope.role.flag=1;
  850. $scope.flagSwitch=false
  851. }
  852. }
  853. $scope.changerole = function(role) {
  854. if($scope.role.id){
  855. if($scope.role.role&&$scope.role.remark){
  856. var model = "";
  857. if ($scope.role.model) {
  858. model = $scope.role.model.name
  859. }
  860. var dutyDepts = $scope.dutyDeptList.filter(v=>v.flag).map(v=>({id:v.id}));
  861. var branchs = [];
  862. if($scope.branchObj.flag){
  863. branchs.push($scope.branchObj);
  864. }
  865. var branchs_lin = $scope.branchObj.children.filter(v=>v.flag);
  866. branchs = branchs.concat(branchs_lin);
  867. 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 } };
  868. api_user_data.addData('role', fildata).then(function(response) {
  869. if (response) {
  870. if (response.status == 200) {
  871. $scope.role={};
  872. SweetAlert.swal({
  873. title: "修改成功!",
  874. type: "success"
  875. }, function() {
  876. $scope.try_async_load();
  877. $scope.getDutyDeptList();
  878. // $scope.refreshData('expand-right', defaultFilterData);
  879. })
  880. } else {
  881. SweetAlert.swal({
  882. title: "修改失败!",
  883. type: "error"
  884. })
  885. }
  886. // $modalInstance.close();
  887. }
  888. })
  889. }else{
  890. SweetAlert.swal({
  891. title: "修改失败!",
  892. text:"请填写必填项",
  893. type: "error"
  894. })
  895. }
  896. }else{
  897. SweetAlert.swal({
  898. title: "操作失败!",
  899. text:"请选择需要修改的角色",
  900. type: "error"
  901. })
  902. }
  903. }
  904. // })
  905. // }
  906. //change role
  907. $scope.changeRole = function() {
  908. var modalInstance = $modal.open({
  909. templateUrl: 'assets/views/system/tpl/addpower.html',
  910. controller: function($scope, scope, $modalInstance, api_user_data) {
  911. $scope.role = scope.role;
  912. $scope.cancel = function() {
  913. $modalInstance.dismiss('cancel');
  914. };
  915. $scope.ok = function(item) {
  916. var fildata = { loginUser: loginUser, 'role': { 'id': item.id, 'role': item.role, 'roletype': item.roletype } };
  917. $modalInstance.close(fildata);
  918. }
  919. },
  920. resolve: {
  921. scope: function() {
  922. return $scope;
  923. }
  924. }
  925. });
  926. modalInstance.result.then(function(selectedItem) {
  927. if (selectedItem) {
  928. api_user_data.addData('role', selectedItem).then(function(response) {
  929. if (response) {
  930. if (response.status == 200) {
  931. SweetAlert.swal({
  932. title: "修改成功!",
  933. type: "success"
  934. }, function() {
  935. $scope.try_async_load();
  936. $scope.getDutyDeptList();
  937. // $scope.refreshData('expand-right', defaultFilterData);
  938. })
  939. } else {
  940. SweetAlert.swal({
  941. title: "修改失败!",
  942. type: "error"
  943. })
  944. }
  945. // $modalInstance.close();
  946. }
  947. })
  948. }
  949. })
  950. }
  951. //remove role
  952. $scope.removeRole = function() {
  953. if ($scope.role && $scope.role.roletype == 0) {
  954. var modalInstance = $modal.open({
  955. templateUrl: 'assets/views/delete.html',
  956. controller: function($scope, scope, $modalInstance) {
  957. var rmvList = [];
  958. // angular.forEach(scope.getbranchs, function(item) {
  959. // $scope.rmvList.push(item.id);
  960. // })
  961. rmvList.push(scope.role.id);
  962. $scope.ok = function() {
  963. $modalInstance.close(rmvList);
  964. };
  965. $scope.cancel = function() {
  966. $modalInstance.dismiss('cancel');
  967. };
  968. $scope.title = '角色删除';
  969. $scope.connect = '是否删除该角色'
  970. },
  971. size: 'sm',
  972. resolve: {
  973. scope: function() {
  974. return $scope;
  975. }
  976. }
  977. });
  978. modalInstance.result.then(function(selectedItem) {
  979. if (selectedItem) {
  980. if (selectedItem.length > 0) {
  981. api_user_data.rmvData('role', selectedItem).then(function(response) {
  982. if (response.data) {
  983. $scope.role={};
  984. SweetAlert.swal({
  985. title: "删除成功!",
  986. type: "success",
  987. confirmButtonColor: "#007AFF"
  988. }, function() {
  989. $scope.try_async_load();
  990. $scope.getDutyDeptList();
  991. });
  992. } else {
  993. SweetAlert.swal({
  994. title: "操作异常!",
  995. text: "系统异常,请稍后重试,或者联系管理员!",
  996. type: "error"
  997. });
  998. }
  999. })
  1000. }
  1001. }
  1002. })
  1003. } else {
  1004. SweetAlert.swal({
  1005. title: "操作错误!",
  1006. text: "该角色不能删除!",
  1007. type: "error"
  1008. });
  1009. }
  1010. }
  1011. //仪表盘
  1012. //查看仪表盘权限
  1013. $scope.doing_asyncdash = true;
  1014. $scope.dashboard_tree = [];
  1015. // $scope.try_async_dashboard = function() {
  1016. // api_user_data.fetchDataList("dashboard", { "idx": 0, "sum": 1000 }).then(function(response) {
  1017. // if (response.status == 200) {
  1018. // var data = response.list;
  1019. // var objects = [];
  1020. // for (var i = 0; i < data.length; i++) {
  1021. // var object = {};
  1022. // object.id = data[i].id;
  1023. // object.label = data[i].name;
  1024. // objects.push(object);
  1025. // }
  1026. // $scope.dashboard_tree = objects;
  1027. // $scope.dashboard_data = angular.copy($scope.dashboard_tree);
  1028. // if ($scope.dashboard_data.length > 0) {
  1029. // $scope.doing_asyncdash = false;
  1030. // }
  1031. // } else {
  1032. // SweetAlert.swal({
  1033. // title: "系统错误!",
  1034. // text: "请刷新重试!",
  1035. // type: "error"
  1036. // });
  1037. // }
  1038. // });
  1039. // }
  1040. // $scope.try_async_dashboard();
  1041. $scope.formlist = {};
  1042. $scope.formdashboard = function(branchData) {
  1043. // $scope.formlist = {};
  1044. $scope.formlist = branchData;
  1045. }
  1046. //修改仪表盘权限
  1047. // var dashboard = [];
  1048. $scope.changeDashboard = function() {
  1049. var firldata = {};
  1050. var dashboard = [];
  1051. $rootScope.isMask = true;
  1052. angular.forEach($scope.formlist, function(item) {
  1053. dashboard.push({ 'id': item.id, 'name': item.label });
  1054. })
  1055. firldata = { 'dashboard': dashboard, 'id': $scope.role.id, 'role': $scope.role.role, 'rolecode': $scope.role.rolecode, 'roletype': $scope.role.roletype, 'menu': $scope.role.menu }
  1056. api_user_data.addData('role', { 'role': firldata }).then(function(response) {
  1057. if (response && response.status == 200) {
  1058. $scope.getDutyDeptList();
  1059. $scope.try_async_load();
  1060. SweetAlert.swal({
  1061. title: "提交成功!",
  1062. type: "success",
  1063. confirmButtonColor: "#007AFF"
  1064. }, function() {
  1065. $rootScope.isMask = false;
  1066. // $scope.formlist = {}
  1067. });
  1068. } else {
  1069. SweetAlert.swal({
  1070. title: "系统错误",
  1071. text: "系统错误,请稍后重试!",
  1072. type: "error",
  1073. confirmButtonColor: "#DD6B55"
  1074. }, function() {
  1075. $rootScope.isMask = false;
  1076. });
  1077. }
  1078. })
  1079. }
  1080. }]);