groupCtrl.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. 'use strict';
  2. app.controller('grouplistCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "Restangular", "api_user_data", "api_configure_data", function($rootScope, $scope, $state, $timeout, $interval, SweetAlert, $modal, Restangular, api_user_data, api_configure_data) {
  3. var loginUser = $rootScope.user;
  4. $scope.xinzeng=false;
  5. $scope.shanchu=false;
  6. $scope.bianji=false;
  7. for(var i=0;i<loginUser.menu.length;i++){
  8. if(loginUser.menu[i].link=="gongzuozuguanli_xinzeng"){
  9. $scope.xinzeng=true
  10. }
  11. if(loginUser.menu[i].link=="gongzuozuguanli_shanchu"){
  12. $scope.shanchu=true
  13. }
  14. if(loginUser.menu[i].link=="gongzuozuguanli_bianji"){
  15. $scope.bianji=true
  16. }
  17. }
  18. //user tree
  19. var apple_selected, tree, treedata_avm, treedata_geography;
  20. var i = 0;
  21. $scope.bodyHeight = Math.max((window.innerHeight - 290), 500);
  22. // $(window).resize(function() {
  23. // $scope.bodyHeight = Math.max((window.innerHeight - 290), 500);
  24. // });
  25. $rootScope.isMask = false;
  26. // //角色仪表权限
  27. // function dashboardaborad(branch) {
  28. // $scope.dashboard_tree = angular.copy($scope.dashboard_data);
  29. // angular.forEach($scope.dashboard_tree, function(index, i) {
  30. // if (branch.dashboard && branch.dashboard.length > 0) {
  31. // angular.forEach(branch.dashboard, function(item) {
  32. // if (index.id == item.id) {
  33. // $scope.dashboard_tree[i].checks = true;
  34. // }
  35. // })
  36. // }
  37. // })
  38. // }
  39. //组树
  40. $scope.my_tree = {};
  41. $scope.my_user = {};
  42. $scope.try_async_load = function() {
  43. $scope.my_data = [];
  44. $scope.doing_async = true;
  45. api_user_data.fetchDataList('group', { "idx": 0, "sum": 1000 }).then(function(response) {
  46. if (response.status == 200) {
  47. var data = response.list;
  48. var objects = [];
  49. for (var i = 0; i < data.length; i++) {
  50. var object = {};
  51. // object.id = data[i].id;
  52. // if (data[i].parent && data[i].parent.id != 0) {
  53. // object.parent = data[i].parent.id;
  54. // }
  55. angular.extend(object, data[i]);
  56. object.label = object.groupName;
  57. // if (loginUser.id == 1) {
  58. // objects.push(object);
  59. // } else {
  60. // if (object.roletype == 0) {
  61. // objects.push(object);
  62. // }
  63. // }
  64. objects.push(object);
  65. }
  66. $scope.my_data = convertParentToChildList(objects);
  67. $scope.tree_data = angular.copy($scope.my_data);
  68. if ($scope.my_data.length > 0) {
  69. $scope.doing_async = false;
  70. }
  71. } else {
  72. SweetAlert.swal({
  73. title: "系统错误!",
  74. text: "请刷新重试!",
  75. type: "error"
  76. });
  77. }
  78. });
  79. };
  80. function convertListToTree(data, treeMap) {
  81. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  82. var root = null; //Initially set our loop to null
  83. //loop over data
  84. for (var i = 0; i < data.length; i++) {
  85. var datum = data[i];
  86. //each node will have children, so let's give it a "children" poperty
  87. datum.children = [];
  88. //add an entry for this node to the map so that any future children can
  89. //lookup the parent
  90. idToNodeMap[datum.id] = datum;
  91. //Does this node have a parent?
  92. // console.log("datum="+JSON.stringify(datum))
  93. if (typeof datum.parent === "undefined" || datum.parent === null) {
  94. //Doesn't look like it, so this node is the root of the tree
  95. root = datum;
  96. treeMap[datum.id] = root;
  97. } else {
  98. //This node has a parent, so let's look it up using the id
  99. parentNode = idToNodeMap[datum.parent.id];
  100. //We don't need this property, so let's delete it.
  101. // delete datum.parent;
  102. //Let's add the current node as a child of the parent node.
  103. parentNode.children.push(datum);
  104. }
  105. }
  106. return root;
  107. }
  108. function convertParentToChildList(data) {
  109. var treeMap = {};
  110. var list = [];
  111. convertListToTree(data, treeMap);
  112. angular.forEach(treeMap, function(item) {
  113. list.push(item);
  114. });
  115. return list;
  116. }
  117. $scope.try_async_load();
  118. //end power
  119. //tree user
  120. $scope.try_async_powerload = function(items) {
  121. if (items) {
  122. $scope.getbranchs = items.users;
  123. }
  124. // $scope.my_power = [];
  125. var objects = [];
  126. var selected = [];
  127. for (var i = 0; i < $scope.getbranchs.length; i++) {
  128. var object = {};
  129. angular.extend(object, $scope.getbranchs[i]);
  130. object.label = object.name;
  131. objects.push(object);
  132. }
  133. selected = angular.copy($scope.tree_user);
  134. // if (data.length > 0) {
  135. angular.forEach(selected, function(index, i) {
  136. angular.forEach(objects, function(item) {
  137. if (index.id == item.id) {
  138. selected[i].checks = true;
  139. }
  140. })
  141. })
  142. $scope.my_user = selected;
  143. // if ($scope.my_user.length > 0) {
  144. // $scope.doing_asyncuser = false;
  145. // }
  146. };
  147. //tree admin
  148. $scope.my_user = [];
  149. $scope.tile = [];
  150. $scope.try_async_user = function() {
  151. var objects = [];
  152. api_user_data.fetchDataList("user", { "idx": 0, "sum": 1000000 }).then(function(response) {
  153. if (response.status == 200) {
  154. var data = response.list;
  155. var objects = [];
  156. for (var i = 0; i < data.length; i++) {
  157. var object = {};
  158. // object.id = data[i].id;
  159. // if (data[i].parent && data[i].parent.id != 0) {
  160. // object.parent = data[i].parent.id;
  161. // }
  162. angular.extend(object, data[i]);
  163. object.label = object.name;
  164. objects.push(object);
  165. }
  166. $scope.tile = objects;
  167. $scope.my_user = convertParentToChildList(objects);
  168. $scope.tree_user = angular.copy($scope.my_user);
  169. if ($scope.my_user.length > 0) {
  170. $scope.doing_asyncuser = false;
  171. }
  172. } else {
  173. SweetAlert.swal({
  174. title: "系统错误!",
  175. text: "请刷新重试!",
  176. type: "error"
  177. });
  178. }
  179. });
  180. };
  181. $scope.try_async_user();
  182. //点击角色
  183. $scope.group = {};
  184. $scope.change = true;
  185. $scope.my_tree_handler = function(branch) {
  186. $scope.group = branch;
  187. $scope.try_async_powerload(branch);
  188. $scope.change = false;
  189. }
  190. //start remove
  191. $scope.getbranchs = {};
  192. $scope.formbranch = function(branchData) {
  193. $scope.getbranchs = branchData;
  194. }
  195. //change right
  196. $scope.changeData = function() {
  197. var users = [];
  198. $rootScope.isMask = true;
  199. angular.forEach($scope.getbranchs, function(it) {
  200. users.push({ "id": it.id });
  201. })
  202. // var branch = { 'menu': menu };
  203. // angular.extend(branch, { 'id': $scope.role.id, 'role': $scope.role.role, 'rolecode': $scope.role.rolecode, 'roletype': $scope.role.roletype, 'dashboard': $scope.role.dashboard })
  204. var fildata = { "group": { "id": $scope.group.id, "groupName": $scope.group.groupName, "users": users } }
  205. // api_user_data.updData('group', fildata).then(function(response) {
  206. // if (response) {
  207. // if (response.status == 200) {
  208. api_user_data.updData('group', fildata).then(function(response) {
  209. if (response && response.status == 200) {
  210. $scope.try_async_load();
  211. SweetAlert.swal({
  212. title: "提交成功!",
  213. confirmButtonColor: "#007AFF"
  214. }, function() {
  215. $rootScope.isMask = false;
  216. });
  217. } else {
  218. SweetAlert.swal({
  219. title: "系统错误",
  220. text: "系统错误,请稍后重试!",
  221. type: "error",
  222. confirmButtonColor: "#DD6B55"
  223. }, function() {
  224. $rootScope.isMask = false;
  225. });
  226. }
  227. })
  228. // $state.go('app.system.form',{formKey:'system_add_menu', service:'api_configure_data', model : JSON.stringify(modelData)});
  229. }
  230. // //change menu
  231. // $scope.choiceMenu = [];
  232. // $scope.showHandler = function(branch) {
  233. // $scope.choiceMenu = branch;
  234. // }
  235. //add role
  236. $scope.addRole = function() {
  237. var modalInstance = $modal.open({
  238. templateUrl: 'assets/views/system/tpl/group.html',
  239. controller: function($scope, scope, $modalInstance, api_user_data) {
  240. $scope.cancel = function() {
  241. $modalInstance.dismiss('cancel');
  242. };
  243. $scope.ok = function(group) {
  244. var close = true;
  245. for (var i = 0; i < scope.my_data.length; i++) {
  246. if (scope.my_data[i].groupName == group.groupName) {
  247. close = false;
  248. $modalInstance.dismiss('cancel');
  249. SweetAlert.swal({
  250. title: "修改失败!",
  251. text: "该组已存在",
  252. type: "error"
  253. })
  254. break;
  255. } else {}
  256. }
  257. if (close) {
  258. $modalInstance.close(group);
  259. }
  260. }
  261. },
  262. resolve: {
  263. scope: function() {
  264. return $scope;
  265. }
  266. }
  267. });
  268. modalInstance.result.then(function(selectedItem) {
  269. if (selectedItem) {
  270. var fildata = { "group": { "groupName": selectedItem.groupName } }
  271. api_user_data.addData('group', fildata).then(function(response) {
  272. if (response) {
  273. if (response.status == 200) {
  274. SweetAlert.swal({
  275. title: "新增成功!",
  276. type: "success"
  277. }, function() {
  278. $scope.try_async_load();
  279. })
  280. } else {
  281. SweetAlert.swal({
  282. title: "修改失败!",
  283. type: "error"
  284. })
  285. }
  286. // $modalInstance.close();
  287. }
  288. })
  289. }
  290. })
  291. }
  292. //change role
  293. $scope.changeRole = function() {
  294. if($scope.group.id){
  295. var modalInstance = $modal.open({
  296. templateUrl: 'assets/views/system/tpl/group.html',
  297. controller: function($scope, scope, $modalInstance, api_user_data) {
  298. $scope.group = scope.group;
  299. $scope.cancel = function() {
  300. $modalInstance.dismiss('cancel');
  301. };
  302. $scope.ok = function(item) {
  303. $modalInstance.close(item);
  304. }
  305. },
  306. resolve: {
  307. scope: function() {
  308. return $scope;
  309. }
  310. }
  311. });
  312. modalInstance.result.then(function(selectedItem) {
  313. if (selectedItem) {
  314. var fildata = { "group": { "id": selectedItem.id, "groupName": selectedItem.groupName, "users": selectedItem.users } }
  315. api_user_data.updData('group', fildata).then(function(response) {
  316. if (response) {
  317. if (response.status == 200) {
  318. SweetAlert.swal({
  319. title: "修改成功!",
  320. type: "success"
  321. }, function() {
  322. $scope.try_async_load();
  323. // $scope.refreshData('expand-right', defaultFilterData);
  324. })
  325. } else {
  326. SweetAlert.swal({
  327. title: "修改失败!",
  328. type: "error"
  329. })
  330. }
  331. // $modalInstance.close();
  332. }
  333. })
  334. }
  335. })
  336. }else{
  337. SweetAlert.swal({
  338. title: "操作失败",
  339. text: "请选择需要修改的项!",
  340. type: "error",
  341. confirmButtonColor: "#DD6B55"
  342. });
  343. }
  344. }
  345. //remove role
  346. $scope.removeRole = function() {
  347. var modalInstance = $modal.open({
  348. templateUrl: 'assets/views/delete.html',
  349. controller: function($scope, scope, $modalInstance) {
  350. var rmvList = [];
  351. $scope.title = '工作组删除';
  352. $scope.connect = '确定要删除此工作组?';
  353. rmvList.push(scope.group.id);
  354. $scope.ok = function() {
  355. $modalInstance.close(rmvList);
  356. };
  357. $scope.cancel = function() {
  358. $modalInstance.dismiss('cancel');
  359. };
  360. },
  361. size: 'sm',
  362. resolve: {
  363. scope: function() {
  364. return $scope;
  365. }
  366. }
  367. });
  368. modalInstance.result.then(function(selectedItem) {
  369. if (selectedItem) {
  370. if (selectedItem.length > 0) {
  371. api_user_data.rmvData('group', selectedItem).then(function(response) {
  372. if (response.data) {
  373. SweetAlert.swal({
  374. title: "删除成功!",
  375. type: "success",
  376. confirmButtonColor: "#007AFF"
  377. }, function() {
  378. $scope.try_async_load();
  379. });
  380. } else {
  381. SweetAlert.swal({
  382. title: "操作异常!",
  383. text: "系统异常,请稍后重试,或者联系管理员!",
  384. type: "error"
  385. });
  386. }
  387. })
  388. }
  389. }
  390. })
  391. }
  392. }]);