groupCtrl.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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.group = {};
  44. $scope.my_user = [];
  45. $scope.my_data = [];
  46. $scope.doing_async = true;
  47. var postData = { "idx": 0, "sum": 1000, group: {} };
  48. if($rootScope.user.duty){
  49. // 当前的所属责任科室
  50. postData.group.duty = $rootScope.user.duty;
  51. }else if($rootScope.user.branch){
  52. // 当前的所属院区
  53. postData.group.branch = $rootScope.user.branch.id;
  54. }
  55. api_user_data.fetchDataList('group', postData).then(function(response) {
  56. $scope.doing_async = false;
  57. if (response.status == 200) {
  58. var data = response.list;
  59. var objects = [];
  60. for (var i = 0; i < data.length; i++) {
  61. var object = {};
  62. // object.id = data[i].id;
  63. // if (data[i].parent && data[i].parent.id != 0) {
  64. // object.parent = data[i].parent.id;
  65. // }
  66. angular.extend(object, data[i]);
  67. object.label = object.branchName + '-' + (object.duty ? object.duty.dept : '') + '-' + object.groupName;
  68. // if (loginUser.id == 1) {
  69. // objects.push(object);
  70. // } else {
  71. // if (object.roletype == 0) {
  72. // objects.push(object);
  73. // }
  74. // }
  75. objects.push(object);
  76. }
  77. $scope.my_data = convertParentToChildList(objects);
  78. $scope.tree_data = angular.copy($scope.my_data);
  79. } else {
  80. SweetAlert.swal({
  81. title: "系统错误!",
  82. text: "请刷新重试!",
  83. type: "error"
  84. });
  85. }
  86. });
  87. };
  88. function convertListToTree(data, treeMap) {
  89. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  90. var root = null; //Initially set our loop to null
  91. //loop over data
  92. for (var i = 0; i < data.length; i++) {
  93. var datum = data[i];
  94. //each node will have children, so let's give it a "children" poperty
  95. datum.children = [];
  96. //add an entry for this node to the map so that any future children can
  97. //lookup the parent
  98. idToNodeMap[datum.id] = datum;
  99. //Does this node have a parent?
  100. // console.log("datum="+JSON.stringify(datum))
  101. if (typeof datum.parent === "undefined" || datum.parent === null) {
  102. //Doesn't look like it, so this node is the root of the tree
  103. root = datum;
  104. treeMap[datum.id] = root;
  105. } else {
  106. //This node has a parent, so let's look it up using the id
  107. parentNode = idToNodeMap[datum.parent.id];
  108. //We don't need this property, so let's delete it.
  109. // delete datum.parent;
  110. //Let's add the current node as a child of the parent node.
  111. parentNode.children.push(datum);
  112. }
  113. }
  114. return root;
  115. }
  116. function convertParentToChildList(data) {
  117. var treeMap = {};
  118. var list = [];
  119. convertListToTree(data, treeMap);
  120. angular.forEach(treeMap, function(item) {
  121. list.push(item);
  122. });
  123. return list;
  124. }
  125. $scope.try_async_load();
  126. //end power
  127. //tree user
  128. $scope.try_async_powerload = function(items) {
  129. if (items) {
  130. $scope.getbranchs = items.users;
  131. }
  132. // $scope.my_power = [];
  133. var objects = [];
  134. var selected = [];
  135. for (var i = 0; i < $scope.getbranchs.length; i++) {
  136. var object = {};
  137. angular.extend(object, $scope.getbranchs[i]);
  138. object.label = object.name;
  139. objects.push(object);
  140. }
  141. selected = angular.copy($scope.tree_user);
  142. // if (data.length > 0) {
  143. angular.forEach(selected, function(index, i) {
  144. angular.forEach(objects, function(item) {
  145. if (index.id == item.id) {
  146. selected[i].checks = true;
  147. }
  148. })
  149. })
  150. $scope.my_user = selected;
  151. // if ($scope.my_user.length > 0) {
  152. // $scope.doing_asyncuser = false;
  153. // }
  154. };
  155. //tree admin
  156. $scope.my_user = [];
  157. $scope.tile = [];
  158. $scope.try_async_user = function() {
  159. var postData = { "idx": 0, "sum": 9999, user: {engineer: 1,} };
  160. if($rootScope.user.duty){
  161. // 当前的所属责任科室
  162. postData.user.duty = $rootScope.user.duty;
  163. }else if($rootScope.user.branch){
  164. // 当前的所属院区
  165. postData.user.branch = $rootScope.user.branch;
  166. }
  167. api_user_data.fetchDataList("user", postData).then(function(response) {
  168. if (response.status == 200) {
  169. var data = response.list;
  170. var objects = [];
  171. for (var i = 0; i < data.length; i++) {
  172. var object = {};
  173. // object.id = data[i].id;
  174. // if (data[i].parent && data[i].parent.id != 0) {
  175. // object.parent = data[i].parent.id;
  176. // }
  177. angular.extend(object, data[i]);
  178. object.label = object.name;
  179. objects.push(object);
  180. }
  181. $scope.tile = objects;
  182. $scope.my_user = convertParentToChildList(objects);
  183. $scope.tree_user = angular.copy($scope.my_user);
  184. if ($scope.my_user.length > 0) {
  185. $scope.doing_asyncuser = false;
  186. }
  187. } else {
  188. SweetAlert.swal({
  189. title: "系统错误!",
  190. text: "请刷新重试!",
  191. type: "error"
  192. });
  193. }
  194. });
  195. };
  196. $scope.try_async_user();
  197. //点击角色
  198. $scope.group = {};
  199. $scope.change = true;
  200. $scope.my_tree_handler = function(branch) {
  201. $scope.group = branch;
  202. $scope.try_async_powerload(branch);
  203. $scope.change = false;
  204. }
  205. //start remove
  206. $scope.getbranchs = {};
  207. $scope.formbranch = function(branchData) {
  208. $scope.getbranchs = branchData;
  209. }
  210. //change right
  211. $scope.changeData = function() {
  212. if(!$scope.group.id){
  213. SweetAlert.swal({
  214. title: "操作失败",
  215. text: "请选择需要修改的项!",
  216. type: "error",
  217. confirmButtonColor: "#DD6B55"
  218. });
  219. return;
  220. }
  221. var users = [];
  222. $rootScope.isMask = true;
  223. angular.forEach($scope.getbranchs, function(it) {
  224. users.push({ "id": it.id });
  225. })
  226. // var branch = { 'menu': menu };
  227. // angular.extend(branch, { 'id': $scope.role.id, 'role': $scope.role.role, 'rolecode': $scope.role.rolecode, 'roletype': $scope.role.roletype, 'dashboard': $scope.role.dashboard })
  228. var fildata = { "group": { "id": $scope.group.id, "groupName": $scope.group.groupName, "users": users, "duty":$scope.group.duty, "branch": $scope.group.branch } }
  229. // api_user_data.updData('group', fildata).then(function(response) {
  230. // if (response) {
  231. // if (response.status == 200) {
  232. api_user_data.updData('group', fildata).then(function(response) {
  233. if (response && response.status == 200) {
  234. $scope.try_async_load();
  235. SweetAlert.swal({
  236. title: "提交成功!",
  237. type: "success",
  238. confirmButtonColor: "#007AFF"
  239. }, function() {
  240. $rootScope.isMask = false;
  241. });
  242. } else {
  243. SweetAlert.swal({
  244. title: "系统错误",
  245. text: "系统错误,请稍后重试!",
  246. type: "error",
  247. confirmButtonColor: "#DD6B55"
  248. }, function() {
  249. $rootScope.isMask = false;
  250. });
  251. }
  252. })
  253. // $state.go('app.system.form',{formKey:'system_add_menu', service:'api_configure_data', model : JSON.stringify(modelData)});
  254. }
  255. // //change menu
  256. // $scope.choiceMenu = [];
  257. // $scope.showHandler = function(branch) {
  258. // $scope.choiceMenu = branch;
  259. // }
  260. //add role
  261. $scope.addRole = function() {
  262. var modalInstance = $modal.open({
  263. templateUrl: 'assets/views/system/tpl/group.html',
  264. controller: function($rootScope, $scope, scope, $modalInstance, api_user_data, api_category) {
  265. $scope.disableBranch = false;
  266. $scope.disableDuty = false;
  267. if($rootScope.user.duty){
  268. $scope.disableBranch = true;
  269. $scope.disableDuty = true;
  270. }else if($rootScope.user.branch){
  271. $scope.disableBranch = true;
  272. $scope.disableDuty = false;
  273. }
  274. $scope.group = {};
  275. $scope.hospitalList = [];
  276. $scope.dutyDeptList = [];
  277. // 获取院区
  278. $scope.getHospitals = function(){
  279. //跨科室转派
  280. api_category.getOwnBranch({}).then(function (data) {
  281. if(data.status == 200){
  282. $scope.hospitalList = data.data || [];
  283. if($rootScope.user.duty){
  284. // 当前的所属责任科室
  285. $scope.group.branch = $scope.hospitalList.find(v=>v.id == $rootScope.user.duty.branch);
  286. }else if($rootScope.user.branch){
  287. // 当前的所属院区
  288. $scope.group.branch = $scope.hospitalList.find(v=>v.id == $rootScope.user.branch.id);
  289. }
  290. }else{
  291. SweetAlert.swal({
  292. title: "系统错误!",
  293. text: "请刷新重试!",
  294. type: "error"
  295. });
  296. }
  297. })
  298. }
  299. $scope.getHospitals();
  300. // 修改院区
  301. $scope.changeBranch = function(keyword=''){
  302. $scope.group.duty = undefined;
  303. $scope.dutyDeptList = [];
  304. api_category.getOwnDuty({branchId: $scope.group.branch.id}).then(function (data) {
  305. if(data.status == 200){
  306. $scope.dutyDeptList = data.data || [];
  307. if($rootScope.user.duty){
  308. // 当前的所属责任科室
  309. $scope.group.duty = $rootScope.user.duty;
  310. }else if($rootScope.user.branch){
  311. // 当前的所属院区
  312. $scope.group.duty = undefined;
  313. }
  314. }else{
  315. SweetAlert.swal({
  316. title: "系统错误!",
  317. text: "请刷新重试!",
  318. type: "error"
  319. });
  320. }
  321. })
  322. }
  323. $scope.cancel = function() {
  324. $modalInstance.dismiss('cancel');
  325. };
  326. $scope.ok = function(group) {
  327. var close = true;
  328. for (var i = 0; i < scope.my_data.length; i++) {
  329. if (scope.my_data[i].groupName == group.groupName) {
  330. close = false;
  331. $modalInstance.dismiss('cancel');
  332. SweetAlert.swal({
  333. title: "修改失败!",
  334. text: "该组已存在",
  335. type: "error"
  336. })
  337. break;
  338. } else {}
  339. }
  340. if (close) {
  341. $modalInstance.close(group);
  342. }
  343. }
  344. },
  345. resolve: {
  346. scope: function() {
  347. return $scope;
  348. }
  349. }
  350. });
  351. modalInstance.result.then(function(selectedItem) {
  352. if (selectedItem) {
  353. if(!selectedItem.duty || !selectedItem.branch || !selectedItem.groupName){
  354. SweetAlert.swal({
  355. title: "操作失败!",
  356. text: "请填写必填项!",
  357. type: "error"
  358. })
  359. return;
  360. }
  361. var fildata = { "group": { "groupName": selectedItem.groupName,duty:selectedItem.duty } }
  362. api_user_data.addData('group', fildata).then(function(response) {
  363. if (response) {
  364. if (response.status == 200) {
  365. SweetAlert.swal({
  366. title: "新增成功!",
  367. type: "success"
  368. }, function() {
  369. $scope.try_async_load();
  370. })
  371. } else {
  372. SweetAlert.swal({
  373. title: "修改失败!",
  374. type: "error"
  375. })
  376. }
  377. // $modalInstance.close();
  378. }
  379. })
  380. }
  381. })
  382. }
  383. //change role
  384. $scope.changeRole = function() {
  385. if($scope.group.id){
  386. var modalInstance = $modal.open({
  387. templateUrl: 'assets/views/system/tpl/group.html',
  388. controller: function($rootScope, $scope, scope, $modalInstance, api_user_data, api_category) {
  389. $scope.disableBranch = true;
  390. $scope.disableDuty = true;
  391. $scope.group = angular.copy(scope.group);
  392. $scope.hospitalList = [];
  393. $scope.dutyDeptList = [];
  394. // 获取院区
  395. $scope.getHospitals = function(){
  396. //跨科室转派
  397. api_category.getOwnBranch({}).then(function (data) {
  398. if(data.status == 200){
  399. $scope.hospitalList = data.data || [];
  400. $scope.group.branch = $scope.hospitalList.find(v=>v.id == scope.group.branch);
  401. }else{
  402. SweetAlert.swal({
  403. title: "系统错误!",
  404. text: "请刷新重试!",
  405. type: "error"
  406. });
  407. }
  408. })
  409. }
  410. $scope.getHospitals();
  411. // 修改院区
  412. $scope.changeBranch = function(keyword){
  413. if(keyword === undefined){
  414. $scope.group.duty = undefined;
  415. $scope.dutyDeptList = [];
  416. }
  417. api_category.getOwnDuty({branchId: scope.group.branch}).then(function (data) {
  418. if(data.status == 200){
  419. $scope.dutyDeptList = data.data || [];
  420. $scope.group.duty = scope.group.duty;
  421. }else{
  422. SweetAlert.swal({
  423. title: "系统错误!",
  424. text: "请刷新重试!",
  425. type: "error"
  426. });
  427. }
  428. })
  429. }
  430. $scope.cancel = function() {
  431. $modalInstance.dismiss('cancel');
  432. };
  433. $scope.ok = function(item) {
  434. $modalInstance.close(item);
  435. }
  436. },
  437. resolve: {
  438. scope: function() {
  439. return $scope;
  440. }
  441. }
  442. });
  443. modalInstance.result.then(function(selectedItem) {
  444. if (selectedItem) {
  445. if(!selectedItem.duty || !selectedItem.branch || !selectedItem.groupName){
  446. SweetAlert.swal({
  447. title: "操作失败!",
  448. text: "请填写必填项!",
  449. type: "error"
  450. })
  451. return;
  452. }
  453. var fildata = { "group": { "id": selectedItem.id, "groupName": selectedItem.groupName, "users": selectedItem.users,duty:selectedItem.duty, "branch": selectedItem.branch.id } }
  454. api_user_data.updData('group', fildata).then(function(response) {
  455. if (response) {
  456. if (response.status == 200) {
  457. SweetAlert.swal({
  458. title: "修改成功!",
  459. type: "success"
  460. }, function() {
  461. $scope.try_async_load();
  462. // $scope.refreshData('expand-right', defaultFilterData);
  463. })
  464. } else {
  465. SweetAlert.swal({
  466. title: "修改失败!",
  467. type: "error"
  468. })
  469. }
  470. // $modalInstance.close();
  471. }
  472. })
  473. }
  474. })
  475. }else{
  476. SweetAlert.swal({
  477. title: "操作失败",
  478. text: "请选择需要修改的项!",
  479. type: "error",
  480. confirmButtonColor: "#DD6B55"
  481. });
  482. }
  483. }
  484. //remove role
  485. $scope.removeRole = function() {
  486. if(!$scope.group.id){
  487. SweetAlert.swal({
  488. title: "操作失败",
  489. text: "请选择需要修改的项!",
  490. type: "error",
  491. confirmButtonColor: "#DD6B55"
  492. });
  493. return;
  494. }
  495. var modalInstance = $modal.open({
  496. templateUrl: 'assets/views/delete.html',
  497. controller: function($scope, scope, $modalInstance) {
  498. var rmvList = [];
  499. $scope.title = '工作组删除';
  500. $scope.connect = '确定要删除此工作组?';
  501. rmvList.push(scope.group.id);
  502. $scope.ok = function() {
  503. $modalInstance.close(rmvList);
  504. };
  505. $scope.cancel = function() {
  506. $modalInstance.dismiss('cancel');
  507. };
  508. },
  509. size: 'sm',
  510. resolve: {
  511. scope: function() {
  512. return $scope;
  513. }
  514. }
  515. });
  516. modalInstance.result.then(function(selectedItem) {
  517. if (selectedItem) {
  518. if (selectedItem.length > 0) {
  519. api_user_data.rmvData('group', selectedItem).then(function(response) {
  520. if (response.data) {
  521. SweetAlert.swal({
  522. title: "删除成功!",
  523. type: "success",
  524. confirmButtonColor: "#007AFF"
  525. }, function() {
  526. $scope.try_async_load();
  527. });
  528. } else {
  529. SweetAlert.swal({
  530. title: "操作异常!",
  531. text: "系统异常,请稍后重试,或者联系管理员!",
  532. type: "error"
  533. });
  534. }
  535. })
  536. }
  537. }
  538. })
  539. }
  540. }]);