adminUserCtrl.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('adminUserListCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_login", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_login) {
  6. $scope.langs = i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser = $rootScope.user;
  10. //$scope.allright=false;
  11. //$scope.allrightnot=true;
  12. $scope.gridOptions = {};
  13. $scope.gridOptions.data = 'myData';
  14. $scope.gridOptions.enableColumnResizing = true;
  15. $scope.gridOptions.enableFiltering = true;
  16. $scope.gridOptions.enableGridMenu = false;
  17. $scope.gridOptions.enableRowSelection = true;
  18. $scope.gridOptions.showGridFooter = true;
  19. $scope.gridOptions.showColumnFooter = false;
  20. $scope.gridOptions.fastWatch = true;
  21. $scope.gridOptions.useExternalFiltering = true;
  22. $scope.gridOptions.useExternalPagination = true;
  23. $scope.gridOptions.paginationPageSizes = [10];
  24. $scope.gridOptions.paginationPageSize = 10;
  25. $scope.gridOptions.multiSelect = false;
  26. //$scope.gridOptions.rowTemplate= "<div ng-dblclick=\"grid.appScope.onDblClick(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
  27. $scope.gridOptions.rowIdentity = function(row) {
  28. return row.id;
  29. };
  30. $scope.gridOptions.getRowIdentity = function(row) {
  31. return row.id;
  32. };
  33. $scope.transferRole = function(roles) {
  34. var tempValue = "";
  35. angular.forEach(roles, function(item) {
  36. if (tempValue != "") {
  37. tempValue = tempValue + "/";
  38. }
  39. tempValue = tempValue + item.role;
  40. })
  41. return tempValue;
  42. }
  43. $scope.transferStatus = function(flag) {
  44. return (flag == 0) ? "有效" : "无效";
  45. }
  46. $scope.transfergroup = function(group) {
  47. var groupData = '';
  48. angular.forEach(group, function(item) {
  49. if (groupData == '') {
  50. groupData = item.groupName;
  51. } else {
  52. groupData = groupData + "/" + item.groupName;
  53. }
  54. })
  55. return groupData;
  56. }
  57. //remote data
  58. $scope.gridOptions.columnDefs = [{
  59. name: 'item',
  60. displayName: '序号',
  61. width: 50,
  62. enableFiltering: false,
  63. cellTemplate: '<div>' +
  64. '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
  65. '</div>'
  66. },
  67. { name: 'account', displayName: '工号', width: '10%', enableFiltering: false },
  68. { name: 'name', displayName: '姓名', width: '8%', enableFiltering: false },
  69. { name: 'gender.name', displayName: '性别', width: '6%', enableFiltering: false },
  70. { name: 'phone', displayName: '联系电话', width: '10%', enableFiltering: false },
  71. { name: 'email', displayName: '邮箱', width: '10%', enableFiltering: false },
  72. { name: 'dept.dept', displayName: '科室', width: '10%', enableFiltering: false },
  73. { name: 'group', displayName: '所属组', width: '10%', cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.transfergroup(row.entity.group)}}</div>', enableFiltering: false },
  74. { name: 'flag', displayName: '状态', cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.transferStatus(row.entity.flag)}}</div>', width: '6%', enableFiltering: false },
  75. {
  76. name: '编辑',
  77. cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  78. // '<a ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑" tooltip-placement="right">' +
  79. // '<i class="fa fa-pencil-square-o"/></a>' +
  80. '<a ng-click="grid.appScope.saveData(row.entity)" class="bianjifont">编辑</a>' +
  81. // '<a ng-click="grid.appScope.resetpassword(row.entity.id)" tooltip="重置密码" tooltip-placement="right">' +
  82. // '<i class="ti-back-right"/></a>' +
  83. // '<a ng-click="grid.appScope.resetpassword(row.entity.id)" class="printfont" >重置密码</a>' +
  84. // '<a ng-show="row.entity.isRegis&&row.entity.isRegis==1" ng-click="grid.appScope.registerfunction(row.entity.id)" tooltip="消息中心注册" tooltip-placement="right">' +
  85. // '<i class="ti-write"/></a>' +
  86. // '<a ng-show="row.entity.isRegis&&row.entity.isRegis==1" ng-click="grid.appScope.registerfunction(row.entity.id)" class="handlefont" tooltip="消息中心注册" tooltip-placement="left">注册</a>' +
  87. '</div></div>',
  88. enableFiltering: false
  89. }
  90. ];
  91. $scope.groupdata = {};
  92. var apple_selected, tree, treedata_avm, treedata_geography;
  93. $scope.onFilterCallback = function(branch) {
  94. var filedata = $scope.memoryfilterData;
  95. if (filedata.user) {
  96. filedata.user.groupdata = { id: branch.id };
  97. } else {
  98. filedata.user = { groupdata: { id: branch.id } };
  99. }
  100. // filedata.user.group = branch.groupName;
  101. $scope.refreshData('expand-right', filedata);
  102. };
  103. $scope.my_data = [];
  104. $scope.deselectItem = function(item) {
  105. console.log(item)
  106. console.log($scope)
  107. }
  108. function convertListToTree(data, treeMap) {
  109. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  110. var root = null; //Initially set our loop to null
  111. var parentNode = null;
  112. //loop over data
  113. for (var i = 0; i < data.length; i++) {
  114. var datum = data[i];
  115. //each node will have children, so let's give it a "children" poperty
  116. datum.children = [];
  117. //add an entry for this node to the map so that any future children can
  118. //lookup the parent
  119. idToNodeMap[datum.id] = datum;
  120. //Does this node have a parent?
  121. if (typeof datum.parent === "undefined" || datum.parent == null) {
  122. //Doesn't look like it, so this node is the root of the tree
  123. root = datum;
  124. treeMap[datum.id] = root;
  125. } else {
  126. //This node has a parent, so let's look it up using the id
  127. parentNode = idToNodeMap[datum.parent.id];
  128. //We don't need this property, so let's delete it.
  129. delete datum.parent;
  130. //Let's add the current node as a child of the parent node.
  131. parentNode.children.push(datum);
  132. }
  133. }
  134. return root;
  135. }
  136. function convertParentToChildList(data) {
  137. var treeMap = {};
  138. var list = [];
  139. convertListToTree(data, treeMap);
  140. angular.forEach(treeMap, function(item) {
  141. list.push(item);
  142. });
  143. return list;
  144. }
  145. $scope.my_tree = tree = {};
  146. $scope.try_async_load = function() {
  147. $scope.my_data = [];
  148. $scope.select_treedata = [];
  149. $scope.doing_async = true;
  150. api_user_data.fetchDataList('group', { "idx": 0, "sum": 1000 }).then(function(data) {
  151. $scope.select_treedata = $scope.my_data = convertParentToChildList(data['list']);
  152. $scope.doing_async = false;
  153. // tree.expand_all();
  154. //console.log(treelist);
  155. });
  156. };
  157. $scope.select_treedata = [];
  158. $scope.propTypeOptions = [];
  159. $scope.try_async_load();
  160. //注册
  161. $scope.registerfunction = function(id) {
  162. var modalInstance = $modal.open({
  163. templateUrl: 'assets/views/system/tpl/register.html',
  164. controller: function($scope, scope, $modalInstance) {
  165. $scope.ok = function(key) {
  166. var filedata = { 'id': id, 'email': key };
  167. $modalInstance.dismiss('cancel');
  168. api_user_data.register(filedata).then(function(response) {
  169. var myData = Restangular.stripRestangular(response);
  170. if (response.status == 200) {
  171. SweetAlert.swal({
  172. title: "注册成功!",
  173. type: "success",
  174. confirmButtonColor: "#007AFF"
  175. }, function() {
  176. scope.refreshData('expand-right', scope.memoryfilterData);
  177. });
  178. } else {
  179. SweetAlert.swal({
  180. title: "注册失败!",
  181. text: response.msg,
  182. type: "error"
  183. });
  184. }
  185. })
  186. };
  187. $scope.cancel = function() {
  188. $modalInstance.dismiss('cancel');
  189. };
  190. },
  191. resolve: {
  192. scope: function() {
  193. return $scope;
  194. }
  195. }
  196. })
  197. }
  198. $scope.resetpassword = function(id) {
  199. var modalInstance = $modal.open({
  200. templateUrl: 'assets/views/delete.html',
  201. controller: function($scope, $modalInstance) {
  202. var data;
  203. $scope.title = '重置密码';
  204. $scope.connect = '确定要重置密码?';
  205. $scope.ok = function() {
  206. $modalInstance.dismiss('cancel');
  207. api_login.resetpwd(id).then(function(response) {
  208. var myData = Restangular.stripRestangular(response);
  209. // console.log("myData=" + JSON.stringify(myData));
  210. if (response.status == 200) {
  211. SweetAlert.swal({
  212. title: "重置成功!",
  213. type: "success",
  214. confirmButtonColor: "#007AFF"
  215. });
  216. } else {
  217. SweetAlert.swal({
  218. title: "操作异常!",
  219. text: "系统异常,请稍后重试,或者联系管理员!",
  220. type: "error"
  221. });
  222. }
  223. })
  224. };
  225. $scope.cancel = function() {
  226. $modalInstance.dismiss('cancel');
  227. };
  228. },
  229. size: 'sm'
  230. })
  231. }
  232. $scope.saveData = function(data) {
  233. var modelData = { model: { user: data } };
  234. if (modelData.model.user && modelData.model.user.item) {
  235. delete modelData.model.user.item;
  236. }
  237. $state.go('app.system.form', { formKey: 'system_edit', service: 'api_user_data', model: JSON.stringify(modelData) });
  238. };
  239. $scope.addData = function() {
  240. var modelData={model:{user:{flag:"0"}}};
  241. $state.go('app.system.form', { formKey: 'system_edit', service: 'api_user_data',model: JSON.stringify(modelData) });
  242. }
  243. $scope.removeData = function() {
  244. var modalInstance = $modal.open({
  245. templateUrl: 'assets/views/delete.html',
  246. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  247. var rmvList = [];
  248. $scope.title = '人员删除';
  249. $scope.connect = '确定要删除此人员?';
  250. angular.forEach(scope.selected.items, function(item) {
  251. rmvList.push(item.id);
  252. });
  253. $scope.ok = function() {
  254. $modalInstance.close(rmvList);
  255. };
  256. $scope.cancel = function() {
  257. $modalInstance.dismiss('cancel');
  258. };
  259. },
  260. size: 'sm',
  261. resolve: {
  262. scope: function() {
  263. return $scope;
  264. }
  265. }
  266. });
  267. modalInstance.result.then(function(selectedItem) {
  268. if (selectedItem) {
  269. if (selectedItem.length > 0) {
  270. api_user_data.rmvData('user', selectedItem).then(function(response) {
  271. if (response.data) {
  272. SweetAlert.swal({
  273. title: "删除成功!",
  274. type: "success",
  275. confirmButtonColor: "#007AFF"
  276. }, function() {
  277. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id); });
  278. $scope.selected = {
  279. items: []
  280. };
  281. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length;
  282. $scope.gridApi.grid.selection.selectedCount = 0;
  283. });
  284. } else {
  285. SweetAlert.swal({
  286. title: "操作异常!",
  287. text: "系统异常,请稍后重试,或者联系管理员!",
  288. type: "error"
  289. });
  290. }
  291. })
  292. }
  293. }
  294. })
  295. }
  296. $scope.selected = {
  297. items: []
  298. }
  299. $scope.editted = {
  300. items: []
  301. }
  302. $scope.gridOptions.onRegisterApi = function(gridApi) {
  303. $scope.gridApi = gridApi;
  304. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  305. // // console.log(rowEntity);
  306. // });
  307. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  308. var filtersData = $scope.memoryfilterData;
  309. filtersData.idx = newPage - 1;
  310. filtersData.sum = pageSize;
  311. defaultFilterData = filtersData;
  312. $scope.refreshData('expand-right', filtersData);
  313. });
  314. gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
  315. var j = 0;
  316. for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
  317. if (scope.grid.appScope.selected.items[i] == scope.entity) {
  318. j++;
  319. break;
  320. }
  321. }
  322. // console.log("j="+j)
  323. if (j == 1) {
  324. scope.grid.appScope.selected.items.splice(i, 1);
  325. } else {
  326. scope.grid.appScope.selected.items.push(scope.entity)
  327. }
  328. });
  329. // gridApi.core.on.filterChanged($scope, function() {
  330. // var grid = this.grid;
  331. // var filtersData = {
  332. // idx: 0,
  333. // sum: 10
  334. // };
  335. // angular.forEach(grid.columns, function(item) {
  336. // if (item.enableFiltering) {
  337. // if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  338. // if (angular.isUndefined(filtersData['requester'])) {
  339. // filtersData['requester'] = {};
  340. // }
  341. // filtersData['requester'][item.field] = item.filters[0].term;
  342. // }
  343. // }
  344. // });
  345. // $scope.memoryfilterData = filtersData;
  346. // $scope.refreshData('expand-right', filtersData);
  347. // });
  348. gridApi.core.on.filterChanged($scope, function() {
  349. var grid = this.grid;
  350. // var filtersData = {
  351. // idx: 0,
  352. // sum: 10
  353. // };
  354. var filtersData = $scope.memoryfilterData;
  355. angular.forEach(grid.columns, function(item) {
  356. if (item.enableFiltering) {
  357. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  358. if (angular.isUndefined(filtersData['user'])) {
  359. filtersData['user'] = {};
  360. filtersData['user']['flag'] = -1;
  361. filtersData['user'][item.field] = item.filters[0].term;
  362. } else {
  363. filtersData.user.flag = -1;
  364. filtersData.user[item.field] = item.filters[0].term;
  365. }
  366. // filtersData['user']['flag'] = -1;
  367. // filtersData['user'][item.field] = item.filters[0].term;
  368. }
  369. }
  370. });
  371. $scope.memoryfilterData = filtersData;
  372. $scope.refreshData('expand-right', filtersData);
  373. });
  374. };
  375. var defaultFilterData = {
  376. "idx": 0,
  377. "sum": 10
  378. };
  379. $scope.memoryfilterData = {
  380. "idx": 0,
  381. "sum": 10
  382. }
  383. $scope.ldloading = {};
  384. //刷新
  385. $scope.refresh = function(style, filterData) {
  386. $scope.selected = { items: [] };
  387. if ($scope.gridApi) {
  388. // $scope.gridApi.grid.options.paginationCurrentPage = 0;
  389. $scope.gridApi.grid.selection.selectedCount = 0;
  390. }
  391. $scope.refreshData('expand-right', defaultFilterData);
  392. }
  393. //获取列表数据
  394. $scope.refreshData = function(style, filterData) {
  395. $scope.ldloading[style.replace('-', '_')] = true;
  396. if (angular.isUndefined(filterData)) {
  397. filterData = defaultFilterData;
  398. }
  399. if (angular.isDefined($scope.searchTypes)) {
  400. filterData['searchType'] = $scope.searchTypes;
  401. }
  402. $scope.myData = [];
  403. filterData['flag'] = -1;
  404. // if ($scope.gridApi) {
  405. // $scope.gridApi.grid.selection.selectedCount = 0;
  406. // $scope.selected = { items: [] };
  407. // }
  408. console.log("filterData=" + JSON.stringify(filterData))
  409. api_user_data.fetchDataList('user', filterData).then(function(data) {
  410. var myData = Restangular.stripRestangular(data);
  411. $scope.gridOptions.totalItems = myData.totalNum;
  412. $scope.myData = myData.list;
  413. for (var i = 0; i < $scope.myData.length; i++) {
  414. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  415. }
  416. $scope.ldloading[style.replace('-', '_')] = false;
  417. // console.log("$scope.myData="+JSON.stringify($scope.myData))
  418. }, function() {
  419. $scope.ldloading[style.replace('-', '_')] = false;
  420. });
  421. };
  422. $scope.refreshData('expand-right', defaultFilterData);
  423. }]);