adminUserCtrl.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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.xinzeng = false;
  11. $scope.shanchu = false;
  12. $scope.bianji = false;
  13. $scope.chongzhimima = false;
  14. for (var i = 0; i < loginUser.menu.length; i++) {
  15. if (loginUser.menu[i].link == "renyuanguanli_xinzeng") {
  16. $scope.xinzeng = true
  17. }
  18. if (loginUser.menu[i].link == "renyuanguanli_shanchu") {
  19. $scope.shanchu = true
  20. }
  21. if (loginUser.menu[i].link == "renyuanguanli_bianji") {
  22. $scope.bianji = true
  23. }
  24. if (loginUser.menu[i].link == "renyuanguanli_chongzhimima") {
  25. $scope.chongzhimima = true
  26. }
  27. }
  28. //$scope.allright=false;
  29. //$scope.allrightnot=true;
  30. $scope.gridOptions = {};
  31. $scope.gridOptions.data = 'myData';
  32. $scope.gridOptions.enableColumnResizing = true;
  33. $scope.gridOptions.enableFiltering = true;
  34. $scope.gridOptions.enableGridMenu = true;
  35. $scope.gridOptions.enableRowSelection = true;
  36. $scope.gridOptions.showGridFooter = true;
  37. $scope.gridOptions.showColumnFooter = false;
  38. $scope.gridOptions.fastWatch = true;
  39. $scope.gridOptions.useExternalFiltering = true;
  40. $scope.gridOptions.useExternalPagination = true;
  41. $scope.gridOptions.paginationPageSizes = [10];
  42. $scope.gridOptions.paginationPageSize = 10;
  43. $scope.gridOptions.multiSelect = false;
  44. //$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>";
  45. $scope.gridOptions.rowIdentity = function (row) {
  46. return row.id;
  47. };
  48. $scope.gridOptions.getRowIdentity = function (row) {
  49. return row.id;
  50. };
  51. $scope.transferRole = function (roles) {
  52. var tempValue = "";
  53. angular.forEach(roles, function (item) {
  54. if (tempValue != "") {
  55. tempValue = tempValue + "/";
  56. }
  57. tempValue = tempValue + item.role;
  58. })
  59. return tempValue;
  60. }
  61. $scope.transferStatus = function (flag) {
  62. return (flag == 0) ? "有效" : "无效";
  63. }
  64. $scope.transfergroup = function (group) {
  65. var groupData = '';
  66. angular.forEach(group, function (item) {
  67. if (groupData == '') {
  68. groupData = item.groupName;
  69. } else {
  70. groupData = groupData + "/" + item.groupName;
  71. }
  72. })
  73. return groupData;
  74. }
  75. //remote data
  76. $scope.gridOptions.columnDefs = [{
  77. name: 'item',
  78. displayName: '序号',
  79. width: 50,
  80. enableFiltering: false,
  81. cellTemplate: '<div>' +
  82. '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
  83. '</div>'
  84. },
  85. {
  86. name: 'account',
  87. displayName: '账号',
  88. width: '8%',
  89. minWidth: '105',
  90. enableFiltering: false
  91. },
  92. {
  93. name: 'name',
  94. displayName: '姓名',
  95. width: '6%',
  96. minWidth: '100',
  97. enableFiltering: false
  98. },
  99. {
  100. name: 'weixin',
  101. displayName: '微信',
  102. width: '6%',
  103. minWidth: '120',
  104. enableFiltering: false
  105. },
  106. // {
  107. // name: 'gender.name',
  108. // displayName: '性别',
  109. // width: '5%',
  110. // enableFiltering: false
  111. // },
  112. {
  113. name: 'phone',
  114. displayName: '联系电话',
  115. width: '8%',
  116. minWidth: '115',
  117. enableFiltering: false
  118. },
  119. {
  120. name: 'email',
  121. displayName: '邮箱',
  122. width: '14%',
  123. minWidth: '150',
  124. enableFiltering: false
  125. },
  126. {
  127. name: 'dept.dept',
  128. displayName: '科室',
  129. width: '12%',
  130. enableFiltering: false
  131. },
  132. {
  133. name: 'dept.phone',
  134. displayName: '科室电话',
  135. width: '11%',
  136. enableFiltering: false
  137. },
  138. {
  139. name: 'extensionNo',
  140. displayName: '分机号码',
  141. width: '11%',
  142. enableFiltering: false
  143. },
  144. {
  145. name: 'group',
  146. displayName: '所属工作组',
  147. width: '15%',
  148. minWidth: '150',
  149. cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.transfergroup(row.entity.group)}}</div>',
  150. enableFiltering: false
  151. },
  152. {
  153. name: 'flag',
  154. displayName: '状态',
  155. cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.transferStatus(row.entity.flag)}}</div>',
  156. width: '5%',
  157. enableFiltering: false
  158. },
  159. {
  160. name: '操作',
  161. minWidth: '150',
  162. cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  163. // '<a ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑" tooltip-placement="right">' +
  164. // '<i class="fa fa-pencil-square-o"/></a>' +
  165. '<a ng-click="grid.appScope.saveData(row.entity)" ng-show="grid.appScope.bianji" class="bianjifont">编辑</a>' +
  166. // '<a ng-click="grid.appScope.resetpassword(row.entity.id)" tooltip="重置密码" tooltip-placement="right">' +
  167. // '<i class="ti-back-right"/></a>' +
  168. '<a ng-click="grid.appScope.resetpassword(row.entity.id)" ng-show="grid.appScope.chongzhimima" class="bianjifont" >重置密码</a>' +
  169. // '<a ng-show="row.entity.isRegis&&row.entity.isRegis==1" ng-click="grid.appScope.registerfunction(row.entity.id)" tooltip="消息中心注册" tooltip-placement="right">' +
  170. // '<i class="ti-write"/></a>' +
  171. // '<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>' +
  172. '</div></div>',
  173. enableFiltering: false
  174. }
  175. ];
  176. $scope.groupdata = {};
  177. var apple_selected, tree, treedata_avm, treedata_geography;
  178. // $scope.onFilterCallback = function(branch) {
  179. // var filedata = $scope.memoryfilterData;
  180. // if (filedata.user) {
  181. // filedata.user.groupdata = { id: branch.id };
  182. // } else {
  183. // filedata.user = { groupdata: { id: branch.id } };
  184. // }
  185. // // filedata.user.group = branch.groupName;
  186. // $scope.refreshData('expand-right', $scope.fileData);
  187. // };
  188. $scope.my_data = [];
  189. $scope.deselectItem = function (item) {
  190. console.log(item)
  191. console.log($scope)
  192. }
  193. function convertListToTree(data, treeMap) {
  194. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  195. var root = null; //Initially set our loop to null
  196. var parentNode = null;
  197. //loop over data
  198. for (var i = 0; i < data.length; i++) {
  199. var datum = data[i];
  200. //each node will have children, so let's give it a "children" poperty
  201. datum.children = [];
  202. //add an entry for this node to the map so that any future children can
  203. //lookup the parent
  204. idToNodeMap[datum.id] = datum;
  205. //Does this node have a parent?
  206. if (typeof datum.parent === "undefined" || datum.parent == null) {
  207. //Doesn't look like it, so this node is the root of the tree
  208. root = datum;
  209. treeMap[datum.id] = root;
  210. } else {
  211. //This node has a parent, so let's look it up using the id
  212. parentNode = idToNodeMap[datum.parent.id];
  213. //We don't need this property, so let's delete it.
  214. delete datum.parent;
  215. //Let's add the current node as a child of the parent node.
  216. parentNode.children.push(datum);
  217. }
  218. }
  219. return root;
  220. }
  221. function convertParentToChildList(data) {
  222. var treeMap = {};
  223. var list = [];
  224. convertListToTree(data, treeMap);
  225. angular.forEach(treeMap, function (item) {
  226. list.push(item);
  227. });
  228. return list;
  229. }
  230. $scope.my_tree = tree = {};
  231. $scope.try_async_load = function () {
  232. $scope.my_data = [];
  233. $scope.select_treedata = [];
  234. $scope.doing_async = true;
  235. api_user_data.fetchDataList('group', {
  236. "idx": 0,
  237. "sum": 1000
  238. }).then(function (data) {
  239. $scope.select_treedata = $scope.my_data = convertParentToChildList(data['list']);
  240. $scope.doing_async = false;
  241. // tree.expand_all();
  242. //console.log(treelist);
  243. });
  244. };
  245. $scope.select_treedata = [];
  246. $scope.propTypeOptions = [];
  247. $scope.try_async_load();
  248. //注册
  249. $scope.registerfunction = function (id) {
  250. var modalInstance = $modal.open({
  251. templateUrl: 'assets/views/system/tpl/register.html',
  252. controller: function ($scope, scope, $modalInstance) {
  253. $scope.ok = function (key) {
  254. var filedata = {
  255. 'id': id,
  256. 'email': key
  257. };
  258. $modalInstance.dismiss('cancel');
  259. api_user_data.register(filedata).then(function (response) {
  260. var myData = Restangular.stripRestangular(response);
  261. if (response.status == 200) {
  262. SweetAlert.swal({
  263. title: "注册成功!",
  264. type: "success",
  265. confirmButtonColor: "#007AFF"
  266. }, function () {
  267. scope.refreshData('expand-right', scope.fileData);
  268. });
  269. } else {
  270. SweetAlert.swal({
  271. title: "注册失败!",
  272. text: response.msg,
  273. type: "error"
  274. });
  275. }
  276. })
  277. };
  278. $scope.cancel = function () {
  279. $modalInstance.dismiss('cancel');
  280. };
  281. },
  282. resolve: {
  283. scope: function () {
  284. return $scope;
  285. }
  286. }
  287. })
  288. }
  289. $scope.resetpassword = function (id) {
  290. var modalInstance = $modal.open({
  291. templateUrl: 'assets/views/delete.html',
  292. controller: function ($scope, $modalInstance) {
  293. var data;
  294. $scope.title = '重置密码';
  295. $scope.connect = '确定要重置密码?';
  296. $scope.ok = function () {
  297. $modalInstance.dismiss('cancel');
  298. api_login.resetpwd(id).then(function (response) {
  299. var myData = Restangular.stripRestangular(response);
  300. // console.log("myData=" + JSON.stringify(myData));
  301. if (response.status == 200) {
  302. SweetAlert.swal({
  303. title: "重置成功!重置后密码 888888",
  304. type: "success",
  305. confirmButtonColor: "#007AFF"
  306. });
  307. } else {
  308. SweetAlert.swal({
  309. title: "操作异常!",
  310. text: "系统异常,请稍后重试,或者联系管理员!",
  311. type: "error"
  312. });
  313. }
  314. })
  315. };
  316. $scope.cancel = function () {
  317. $modalInstance.dismiss('cancel');
  318. };
  319. },
  320. size: 'sm'
  321. })
  322. }
  323. $scope.saveData = function (data) {
  324. var modelData = {
  325. model: {
  326. user: data
  327. }
  328. };
  329. if (modelData.model.user && modelData.model.user.item) {
  330. delete modelData.model.user.item;
  331. }
  332. modelData.model.user.deptPhone=data.dept?data.dept.phone:''
  333. $state.go('app.system.form', {
  334. formKey: 'system_edit',
  335. service: 'api_user_data',
  336. model: JSON.stringify(modelData)
  337. });
  338. };
  339. $scope.addData = function () {
  340. var modelData = {
  341. model: {
  342. user: {
  343. flag: "0"
  344. }
  345. }
  346. };
  347. $state.go('app.system.form', {
  348. formKey: 'system_edit',
  349. service: 'api_user_data',
  350. model: JSON.stringify(modelData)
  351. });
  352. }
  353. $scope.removeData = function () {
  354. var modalInstance = $modal.open({
  355. templateUrl: 'assets/views/delete.html',
  356. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  357. var rmvList = [];
  358. $scope.title = '人员删除';
  359. $scope.connect = '确定要删除此人员?';
  360. angular.forEach(scope.selected.items, function (item) {
  361. rmvList.push(item.id);
  362. });
  363. $scope.ok = function () {
  364. $modalInstance.close(rmvList);
  365. };
  366. $scope.cancel = function () {
  367. $modalInstance.dismiss('cancel');
  368. };
  369. },
  370. size: 'sm',
  371. resolve: {
  372. scope: function () {
  373. return $scope;
  374. }
  375. }
  376. });
  377. modalInstance.result.then(function (selectedItem) {
  378. if (selectedItem) {
  379. if (selectedItem.length > 0) {
  380. api_user_data.rmvData('user', selectedItem).then(function (response) {
  381. if (response.data) {
  382. SweetAlert.swal({
  383. title: "删除成功!",
  384. type: "success",
  385. confirmButtonColor: "#007AFF"
  386. }, function () {
  387. $scope.myData = _.reject($scope.myData, function (o) {
  388. return _.includes(selectedItem, o.id);
  389. });
  390. $scope.selected = {
  391. items: []
  392. };
  393. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length;
  394. $scope.gridApi.grid.selection.selectedCount = 0;
  395. });
  396. } else {
  397. SweetAlert.swal({
  398. title: "操作异常!",
  399. text: "系统异常,请稍后重试,或者联系管理员!",
  400. type: "error"
  401. });
  402. }
  403. })
  404. }
  405. }
  406. })
  407. }
  408. $scope.selected = {
  409. items: []
  410. }
  411. $scope.editted = {
  412. items: []
  413. }
  414. $scope.gridOptions.onRegisterApi = function (gridApi) {
  415. $scope.gridApi = gridApi;
  416. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  417. // // console.log(rowEntity);
  418. // });
  419. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  420. var filtersData = $scope.memoryfilterData;
  421. filtersData.idx = newPage - 1;
  422. filtersData.sum = pageSize;
  423. $scope.fileData.idx = newPage - 1;
  424. $scope.fileData.sum = pageSize;
  425. defaultFilterData = filtersData;
  426. $scope.refreshData('expand-right', $scope.fileData);
  427. });
  428. gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  429. var j = 0;
  430. for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
  431. if (scope.grid.appScope.selected.items[i] == scope.entity) {
  432. j++;
  433. break;
  434. }
  435. }
  436. // console.log("j="+j)
  437. if (j == 1) {
  438. scope.grid.appScope.selected.items.splice(i, 1);
  439. } else {
  440. scope.grid.appScope.selected.items.push(scope.entity)
  441. }
  442. });
  443. // gridApi.core.on.filterChanged($scope, function() {
  444. // var grid = this.grid;
  445. // var filtersData = {
  446. // idx: 0,
  447. // sum: 10
  448. // };
  449. // angular.forEach(grid.columns, function(item) {
  450. // if (item.enableFiltering) {
  451. // if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  452. // if (angular.isUndefined(filtersData['requester'])) {
  453. // filtersData['requester'] = {};
  454. // }
  455. // filtersData['requester'][item.field] = item.filters[0].term;
  456. // }
  457. // }
  458. // });
  459. // $scope.memoryfilterData = filtersData;
  460. // $scope.refreshData('expand-right', filtersData);
  461. // });
  462. gridApi.core.on.filterChanged($scope, function () {
  463. var grid = this.grid;
  464. // var filtersData = {
  465. // idx: 0,
  466. // sum: 10
  467. // };
  468. var filtersData = $scope.memoryfilterData;
  469. angular.forEach(grid.columns, function (item) {
  470. if (item.enableFiltering) {
  471. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  472. if (angular.isUndefined(filtersData['user'])) {
  473. filtersData['user'] = {};
  474. filtersData['user']['flag'] = -1;
  475. filtersData['user'][item.field] = item.filters[0].term;
  476. } else {
  477. filtersData.user.flag = -1;
  478. filtersData.user[item.field] = item.filters[0].term;
  479. }
  480. // filtersData['user']['flag'] = -1;
  481. // filtersData['user'][item.field] = item.filters[0].term;
  482. }
  483. }
  484. });
  485. $scope.memoryfilterData = filtersData;
  486. $scope.refreshData('expand-right', $scope.fileData);
  487. });
  488. };
  489. var defaultFilterData = {
  490. "idx": 0,
  491. "sum": 10
  492. };
  493. $scope.memoryfilterData = {
  494. "idx": 0,
  495. "sum": 10
  496. }
  497. $scope.ldloading = {};
  498. $scope.fileData = {
  499. "idx": 0,
  500. "sum": 10,
  501. "user": {}
  502. }
  503. $scope.treeItem = "";
  504. $scope.onFilterCallback = function (item) {
  505. $scope.treeItem = item
  506. }
  507. // 搜索
  508. $scope.searchData = function () {
  509. if ($scope.treeItem) {
  510. $scope.fileData.user.groupdata = $scope.treeItem
  511. }
  512. if($scope.fileData.user.name){
  513. $scope.fileData.user.selectType= "pinyin_qs"
  514. }
  515. $scope.refreshData('expand-right', $scope.fileData);
  516. }
  517. // 清空
  518. $scope.clean = function () {
  519. delete $scope.fileData.user.account;
  520. delete $scope.fileData.user.name;
  521. delete $scope.fileData.user.groupdata;
  522. $scope.treeItem = "";
  523. $scope.try_async_load();
  524. $scope.refreshData('expand-right', $scope.fileData);
  525. }
  526. //刷新
  527. $scope.refresh = function (style, filterData) {
  528. $scope.selected = {
  529. items: []
  530. };
  531. if ($scope.gridApi) {
  532. // $scope.gridApi.grid.options.paginationCurrentPage = 0;
  533. $scope.gridApi.grid.selection.selectedCount = 0;
  534. }
  535. $scope.refreshData('expand-right', $scope.fileData);
  536. }
  537. //获取列表数据
  538. $scope.refreshData = function (style, filterData) {
  539. $scope.ldloading[style.replace('-', '_')] = true;
  540. if (angular.isUndefined(filterData)) {
  541. filterData = defaultFilterData;
  542. }
  543. if (angular.isDefined($scope.searchTypes)) {
  544. filterData['searchType'] = $scope.searchTypes;
  545. }
  546. $scope.myData = [];
  547. filterData['flag'] = -1;
  548. // if ($scope.gridApi) {
  549. // $scope.gridApi.grid.selection.selectedCount = 0;
  550. // $scope.selected = { items: [] };
  551. // }
  552. console.log("filterData=" + JSON.stringify(filterData))
  553. api_user_data.fetchDataList('user', filterData).then(function (data) {
  554. var myData = Restangular.stripRestangular(data);
  555. $scope.gridOptions.totalItems = myData.totalNum;
  556. $scope.myData = myData.list;
  557. for (var i = 0; i < $scope.myData.length; i++) {
  558. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  559. }
  560. $scope.ldloading[style.replace('-', '_')] = false;
  561. // console.log("$scope.myData="+JSON.stringify($scope.myData))
  562. }, function () {
  563. $scope.ldloading[style.replace('-', '_')] = false;
  564. });
  565. };
  566. $scope.refreshData2 = function (style, filterData) {
  567. $scope.ldloading[style.replace('-', '_')] = true;
  568. if (angular.isUndefined(filterData)) {
  569. filterData = defaultFilterData;
  570. }
  571. if (angular.isDefined($scope.searchTypes)) {
  572. filterData['searchType'] = $scope.searchTypes;
  573. }
  574. // $scope.myData = [];
  575. filterData['flag'] = -1;
  576. // if ($scope.gridApi) {
  577. // $scope.gridApi.grid.selection.selectedCount = 0;
  578. // $scope.selected = { items: [] };
  579. // }
  580. console.log("filterData=" + JSON.stringify(filterData))
  581. api_user_data.fetchDataList('user', filterData).then(function (data) {
  582. var myData = Restangular.stripRestangular(data);
  583. $scope.gridOptions.totalItems = myData.totalNum;
  584. $scope.myData = myData.list;
  585. for (var i = 0; i < $scope.myData.length; i++) {
  586. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  587. }
  588. $scope.ldloading[style.replace('-', '_')] = false;
  589. // console.log("$scope.myData="+JSON.stringify($scope.myData))
  590. }, function () {
  591. $scope.ldloading[style.replace('-', '_')] = false;
  592. });
  593. };
  594. $scope.refreshData('expand-right', $scope.fileData);
  595. $scope.timer = $interval(function () {
  596. $scope.refreshData2('expand-right', $scope.fileData);
  597. }, $rootScope.refreshTime);
  598. $scope.$on('$destroy', function () {
  599. $interval.cancel($scope.timer)
  600. });
  601. }]);