adminUserCtrl.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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", "api_category", function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_login, api_category) {
  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. if (loginUser.menu[i].link == "renyuanguanli_qiehuan") {
  28. $scope.qiehuan = true
  29. }
  30. }
  31. //$scope.allright=false;
  32. //$scope.allrightnot=true;
  33. $scope.gridOptions = {};
  34. $scope.gridOptions.data = 'myData';
  35. $scope.gridOptions.enableColumnResizing = true;
  36. $scope.gridOptions.enableFiltering = true;
  37. $scope.gridOptions.enableGridMenu = true;
  38. $scope.gridOptions.enableRowSelection = true;
  39. $scope.gridOptions.showGridFooter = true;
  40. $scope.gridOptions.showColumnFooter = false;
  41. $scope.gridOptions.fastWatch = true;
  42. $scope.gridOptions.useExternalFiltering = true;
  43. $scope.gridOptions.useExternalPagination = true;
  44. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  45. $scope.gridOptions.paginationPageSize = 10;
  46. $scope.gridOptions.multiSelect = false;
  47. $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>";
  48. $scope.gridOptions.rowIdentity = function (row) {
  49. return row.id;
  50. };
  51. $scope.gridOptions.getRowIdentity = function (row) {
  52. return row.id;
  53. };
  54. $scope.transferRole = function (roles) {
  55. var tempValue = "";
  56. angular.forEach(roles, function (item) {
  57. if (tempValue != "") {
  58. tempValue = tempValue + "/";
  59. }
  60. tempValue = tempValue + item.role;
  61. })
  62. return tempValue;
  63. }
  64. $scope.transferStatus = function (flag) {
  65. return (flag == 0) ? "有效" : "无效";
  66. }
  67. $scope.transfergroup = function (group) {
  68. var groupData = '';
  69. angular.forEach(group, function (item) {
  70. if (groupData == '') {
  71. groupData = item.groupName;
  72. } else {
  73. groupData = groupData + "/" + item.groupName;
  74. }
  75. })
  76. return groupData;
  77. }
  78. //remote data
  79. $scope.gridOptions.columnDefs = [{
  80. name: 'item',
  81. displayName: '序号',
  82. width: 50,
  83. enableFiltering: false,
  84. cellTemplate: '<div>' +
  85. '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
  86. '</div>'
  87. },
  88. {
  89. name: 'account',
  90. displayName: '账号',
  91. width: '8%',
  92. minWidth: '105',
  93. enableFiltering: false
  94. },
  95. {
  96. name: 'name',
  97. displayName: '姓名',
  98. width: '6%',
  99. minWidth: '100',
  100. enableFiltering: false
  101. },
  102. {
  103. name: 'weixin',
  104. displayName: '微信',
  105. width: '6%',
  106. minWidth: '120',
  107. enableFiltering: false
  108. },
  109. {
  110. name: 'userType',
  111. displayName: '人员类别',
  112. width: '6%',
  113. minWidth: '120',
  114. enableFiltering: false,
  115. cellTemplate: '<div>' +
  116. '<div class="ui-grid-cell-contents">{{row.entity.userType.value == 2 ?row.entity.company.name:row.entity.userType.name}}</div>' +
  117. '</div>'
  118. },
  119. // {
  120. // name: 'gender.name',
  121. // displayName: '性别',
  122. // width: '5%',
  123. // enableFiltering: false
  124. // },
  125. {
  126. name: 'phone',
  127. displayName: '联系电话',
  128. width: '8%',
  129. minWidth: '115',
  130. enableFiltering: false
  131. },
  132. // {
  133. // name: 'email',
  134. // displayName: '邮箱',
  135. // width: '14%',
  136. // minWidth: '150',
  137. // enableFiltering: false
  138. // },
  139. {
  140. name: 'duty.dept',
  141. displayName: '责任科室',
  142. width: '20%',
  143. enableFiltering: false,
  144. cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.branch.hosName}}-{{row.entity.duty.dept}}</div>',
  145. },
  146. // {
  147. // name: 'dept.phone',
  148. // displayName: '科室电话',
  149. // width: '11%',
  150. // enableFiltering: false
  151. // },
  152. // {
  153. // name: 'extensionNo',
  154. // displayName: '分机号码',
  155. // width: '11%',
  156. // enableFiltering: false
  157. // },
  158. {
  159. name: 'group',
  160. displayName: '所属工作组',
  161. width: '15%',
  162. minWidth: '150',
  163. cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.transfergroup(row.entity.group)}}</div>',
  164. enableFiltering: false
  165. },
  166. {
  167. name: 'flag',
  168. displayName: '状态',
  169. cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.transferStatus(row.entity.flag)}}</div>',
  170. width: '5%',
  171. enableFiltering: false
  172. },
  173. {
  174. name: '操作',
  175. minWidth: '150',
  176. cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  177. // '<a ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑" tooltip-placement="right">' +
  178. // '<i class="fa fa-pencil-square-o"/></a>' +
  179. '<a ng-click="grid.appScope.saveData(row.entity)" ng-show="grid.appScope.bianji" class="bianjifont">编辑</a>' +
  180. // '<a ng-click="grid.appScope.resetpassword(row.entity.id)" tooltip="重置密码" tooltip-placement="right">' +
  181. // '<i class="ti-back-right"/></a>' +
  182. '<a ng-click="grid.appScope.resetpassword(row.entity.id)" ng-show="grid.appScope.chongzhimima" class="bianjifont" >重置密码</a>' +
  183. '<a ng-click="grid.appScope.changeUserHospitalDept(row.entity)" ng-show="grid.appScope.qiehuan" class="bianjifont" >切换院区科室</a>' +
  184. // '<a ng-show="row.entity.isRegis&&row.entity.isRegis==1" ng-click="grid.appScope.registerfunction(row.entity.id)" tooltip="消息中心注册" tooltip-placement="right">' +
  185. // '<i class="ti-write"/></a>' +
  186. // '<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>' +
  187. '</div></div>',
  188. enableFiltering: false
  189. }
  190. ];
  191. $scope.groupdata = {};
  192. var apple_selected, tree, treedata_avm, treedata_geography;
  193. // $scope.onFilterCallback = function(branch) {
  194. // var filedata = $scope.memoryfilterData;
  195. // if (filedata.user) {
  196. // filedata.user.groupdata = { id: branch.id };
  197. // } else {
  198. // filedata.user = { groupdata: { id: branch.id } };
  199. // }
  200. // // filedata.user.group = branch.groupName;
  201. // $scope.refreshData('expand-right', $scope.fileData);
  202. // };
  203. $scope.my_data = [];
  204. $scope.deselectItem = function (item) {
  205. console.log(item)
  206. console.log($scope)
  207. }
  208. function convertListToTree(data, treeMap) {
  209. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  210. var root = null; //Initially set our loop to null
  211. var parentNode = null;
  212. //loop over data
  213. for (var i = 0; i < data.length; i++) {
  214. var datum = data[i];
  215. //each node will have children, so let's give it a "children" poperty
  216. datum.children = [];
  217. //add an entry for this node to the map so that any future children can
  218. //lookup the parent
  219. idToNodeMap[datum.id] = datum;
  220. //Does this node have a parent?
  221. if (typeof datum.parent === "undefined" || datum.parent == null) {
  222. //Doesn't look like it, so this node is the root of the tree
  223. root = datum;
  224. treeMap[datum.id] = root;
  225. } else {
  226. //This node has a parent, so let's look it up using the id
  227. parentNode = idToNodeMap[datum.parent.id];
  228. //We don't need this property, so let's delete it.
  229. delete datum.parent;
  230. //Let's add the current node as a child of the parent node.
  231. parentNode.children.push(datum);
  232. }
  233. }
  234. return root;
  235. }
  236. function convertParentToChildList(data) {
  237. var treeMap = {};
  238. var list = [];
  239. convertListToTree(data, treeMap);
  240. angular.forEach(treeMap, function (item) {
  241. list.push(item);
  242. });
  243. return list;
  244. }
  245. $scope.my_tree = tree = {};
  246. $scope.try_async_load = function () {
  247. $scope.my_data = [];
  248. $scope.select_treedata = [];
  249. $scope.doing_async = true;
  250. var postData = { "idx": 0, "sum": 1000, group: {'selectType':'nouser'} };
  251. if($rootScope.user.duty){
  252. // 当前的所属责任科室
  253. postData.group.duty = $rootScope.user.duty;
  254. }else if($rootScope.user.branch){
  255. // 当前的所属院区
  256. postData.group.branch = $rootScope.user.branch.id;
  257. }
  258. api_user_data.fetchDataList('group', postData).then(function (data) {
  259. $scope.select_treedata = $scope.my_data = convertParentToChildList(data['list']);
  260. $scope.doing_async = false;
  261. // tree.expand_all();
  262. //console.log(treelist);
  263. });
  264. };
  265. $scope.select_treedata = [];
  266. $scope.propTypeOptions = [];
  267. $scope.try_async_load();
  268. //注册
  269. $scope.registerfunction = function (id) {
  270. var modalInstance = $modal.open({
  271. templateUrl: 'assets/views/system/tpl/register.html',
  272. controller: function ($scope, scope, $modalInstance) {
  273. $scope.ok = function (key) {
  274. var filedata = {
  275. 'id': id,
  276. 'email': key
  277. };
  278. $modalInstance.dismiss('cancel');
  279. api_user_data.register(filedata).then(function (response) {
  280. var myData = Restangular.stripRestangular(response);
  281. if (response.status == 200) {
  282. SweetAlert.swal({
  283. title: "注册成功!",
  284. type: "success",
  285. confirmButtonColor: "#007AFF"
  286. }, function () {
  287. scope.refreshData('expand-right', scope.fileData);
  288. });
  289. } else {
  290. SweetAlert.swal({
  291. title: "注册失败!",
  292. text: response.msg,
  293. type: "error"
  294. });
  295. }
  296. })
  297. };
  298. $scope.cancel = function () {
  299. $modalInstance.dismiss('cancel');
  300. };
  301. },
  302. resolve: {
  303. scope: function () {
  304. return $scope;
  305. }
  306. }
  307. })
  308. }
  309. $scope.resetpassword = function (id) {
  310. var modalInstance = $modal.open({
  311. templateUrl: 'assets/views/delete.html',
  312. controller: function ($scope, $modalInstance) {
  313. var data;
  314. $scope.title = '重置密码';
  315. $scope.connect = '确定要重置密码?';
  316. $scope.ok = function () {
  317. $modalInstance.dismiss('cancel');
  318. api_login.resetpwd(id).then(function (response) {
  319. var myData = Restangular.stripRestangular(response);
  320. // console.log("myData=" + JSON.stringify(myData));
  321. if (response.status == 200) {
  322. SweetAlert.swal({
  323. title: "重置成功!",
  324. text: "默认密码在【系统配置】中查看",
  325. type: "success",
  326. confirmButtonColor: "#007AFF"
  327. });
  328. } else {
  329. SweetAlert.swal({
  330. title: "操作异常!",
  331. text: "系统异常,请稍后重试,或者联系管理员!",
  332. type: "error"
  333. });
  334. }
  335. })
  336. };
  337. $scope.cancel = function () {
  338. $modalInstance.dismiss('cancel');
  339. };
  340. },
  341. size: 'sm'
  342. })
  343. }
  344. // 切换用户院区科室
  345. $scope.changeUserHospitalDept = function (user) {
  346. var modalInstance = $modal.open({
  347. templateUrl: 'assets/views/changeHospitalDept.html',
  348. controller: function (scope, $scope, $modalInstance, items, Restangular, SweetAlert) {
  349. $scope.f = {
  350. uuid:''
  351. };
  352. $scope.dataList = {};
  353. $scope.hospitalAndDutyDept = {};
  354. $scope.dutyDeptList = [];
  355. $scope.branchObj = {};
  356. api_category.branchDutyList({ "userId": user.id }).then(function(response1) {
  357. if(response1.status == 200){
  358. $scope.dataList = angular.copy(response1.data);
  359. if(!$scope.dataList.branchs){
  360. $scope.dataList.branchs = [];
  361. }
  362. if(!$scope.dataList.dutys){
  363. $scope.dataList.dutys = [];
  364. }
  365. var roleObj = response1.data;
  366. api_user_data.fetchDataList('branch', { "idx": 0, "sum": 1000 }).then(function(res) {
  367. if (res.status == 200) {
  368. api_user_data.fetchDataList('dutyDepartment', { "idx": 0, "sum": 1000 }).then(function(response) {
  369. if (response.status == 200) {
  370. // 院区数据处理
  371. $scope.branchObj = angular.copy(res.list).find(v=>v.children.length>0);
  372. $scope.branchObj.children.sort((a,b)=>a.id-b.id);
  373. // 清空
  374. response.list.forEach(v=>{
  375. v.flag = false
  376. });
  377. $scope.dutyDeptList = response.list;
  378. $scope.branchObj.flag = false;
  379. $scope.branchObj.children.forEach(v=>{
  380. v.flag = false;
  381. })
  382. // 回显数据接口数据
  383. if(roleObj){
  384. roleObj.dutys.forEach(v=>{
  385. $scope.dutyDeptList.forEach(vv=>{
  386. if(v.id == vv.id){
  387. vv.flag = true;
  388. }
  389. })
  390. })
  391. roleObj.branchs.forEach(v=>{
  392. if(v.id == $scope.branchObj.id){
  393. $scope.branchObj.flag = true;
  394. }
  395. $scope.branchObj.children.forEach(vv=>{
  396. if(v.id == vv.id){
  397. vv.flag = true;
  398. }
  399. })
  400. })
  401. }
  402. // 回显当前所属院区或责任科室
  403. if(user.duty){
  404. $scope.f.uuid = user.duty.uuid;
  405. }else if(user.branch){
  406. $scope.f.uuid = user.branch.uuid;
  407. }
  408. // 处理责任科室数据
  409. $scope.hospitalAndDutyDept = {};
  410. $scope.dutyDeptList.forEach(v=>{
  411. if($scope.hospitalAndDutyDept[v.branch]){
  412. $scope.hospitalAndDutyDept[v.branch].push(v);
  413. }else{
  414. $scope.hospitalAndDutyDept[v.branch] = [v];
  415. }
  416. })
  417. console.log($scope.branchObj,$scope.hospitalAndDutyDept)
  418. } else {
  419. SweetAlert.swal({
  420. title: "系统错误!",
  421. text: "请刷新重试!",
  422. type: "error"
  423. });
  424. }
  425. });
  426. } else {
  427. SweetAlert.swal({
  428. title: "系统错误!",
  429. text: "请刷新重试!",
  430. type: "error"
  431. });
  432. }
  433. });
  434. }else{
  435. SweetAlert.swal({
  436. title: "系统错误!",
  437. text: "请刷新重试!",
  438. type: "error"
  439. });
  440. }
  441. })
  442. // -----------------------------------
  443. $scope.saveDept = function () {
  444. if(!$scope.f.uuid){
  445. SweetAlert.swal({
  446. title: "保存失败!",
  447. text: "请选择院区科室!",
  448. type: "error"
  449. });
  450. return;
  451. }
  452. $modalInstance.dismiss('cancel');
  453. var data2 = {userId: user.id};
  454. var branchObj = $scope.dataList.branchs.find(v=>v.uuid == $scope.f.uuid);//查找院区的uuid
  455. if(branchObj){
  456. data2.branchId = branchObj.id;
  457. }else{
  458. var dutyObj = $scope.dataList.dutys.find(v=>v.uuid == $scope.f.uuid);//查询责任科室的uuid
  459. if(dutyObj){
  460. data2.dutyId = dutyObj.id;
  461. }
  462. }
  463. if(user.id == $rootScope.user.id){
  464. // 当前所属院区或责任科室
  465. if($rootScope.user.duty){
  466. if(data2.dutyId && data2.dutyId == $rootScope.user.duty.id){
  467. return;
  468. }
  469. }else if($rootScope.user.branch){
  470. if(data2.branchId && data2.branchId == $rootScope.user.branch.id){
  471. return;
  472. }
  473. }
  474. }
  475. $rootScope.isMask = true;
  476. api_login.changeBranch(data2).then(function (response) {
  477. $rootScope.isMask = false;
  478. var myData = Restangular.stripRestangular(response);
  479. if (myData.status == 200) {
  480. if(user.id == $rootScope.user.id){
  481. var jry_user = JSON.parse(localStorage.getItem('jry_user'));
  482. myData.user.user.menu = jry_user.menu;
  483. localStorage.setItem('jry_user',JSON.stringify(myData.user.user));
  484. localStorage.removeItem('phones');
  485. localStorage.removeItem('box_phones');
  486. SweetAlert.swal({
  487. title: "切换成功!",
  488. type: "success",
  489. confirmButtonColor: "#007AFF"
  490. },function(){
  491. location.reload(true);
  492. });
  493. }else{
  494. SweetAlert.swal({
  495. title: "切换成功!",
  496. type: "success",
  497. confirmButtonColor: "#007AFF"
  498. },function(){
  499. scope.refreshData('expand-right', scope.fileData);
  500. });
  501. }
  502. } else {
  503. SweetAlert.swal({
  504. title: "切换失败!",
  505. type: "error"
  506. });
  507. }
  508. }).catch(function(err){
  509. $rootScope.isMask = false;
  510. SweetAlert.swal({
  511. title: "切换失败!",
  512. type: "error"
  513. });
  514. })
  515. }
  516. $scope.cancel = function() {
  517. $modalInstance.dismiss('cancel');
  518. };
  519. },
  520. resolve: {
  521. items: function () {
  522. return {
  523. fetchItems: function (filterData, APIService) { }
  524. };
  525. },
  526. scope: function(){
  527. return $scope;
  528. }
  529. }
  530. });
  531. }
  532. $scope.saveData = function (data) {
  533. var modelData = {
  534. model: {
  535. user: data
  536. }
  537. };
  538. if (modelData.model.user && modelData.model.user.item) {
  539. delete modelData.model.user.item;
  540. }
  541. modelData.model.user.deptPhone=data.duty?data.duty.phone:''
  542. $state.go('app.system.form', {
  543. formKey: 'system_edit',
  544. service: 'api_user_data',
  545. model: JSON.stringify(modelData)
  546. });
  547. };
  548. $scope.addData = function () {
  549. var modelData = {
  550. model: {
  551. user: {
  552. flag: "0"
  553. }
  554. }
  555. };
  556. $state.go('app.system.form', {
  557. formKey: 'system_edit',
  558. service: 'api_user_data',
  559. model: JSON.stringify(modelData)
  560. });
  561. }
  562. $scope.removeData = function () {
  563. var modalInstance = $modal.open({
  564. templateUrl: 'assets/views/delete.html',
  565. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  566. var rmvList = [];
  567. $scope.title = '人员删除';
  568. $scope.connect = '确定要删除此人员?';
  569. angular.forEach(scope.selected.items, function (item) {
  570. rmvList.push(item.id);
  571. });
  572. $scope.ok = function () {
  573. $modalInstance.close(rmvList);
  574. };
  575. $scope.cancel = function () {
  576. $modalInstance.dismiss('cancel');
  577. };
  578. },
  579. size: 'sm',
  580. resolve: {
  581. scope: function () {
  582. return $scope;
  583. }
  584. }
  585. });
  586. modalInstance.result.then(function (selectedItem) {
  587. if (selectedItem) {
  588. if (selectedItem.length > 0) {
  589. api_user_data.rmvData('user', selectedItem).then(function (response) {
  590. if (response.data) {
  591. SweetAlert.swal({
  592. title: "删除成功!",
  593. type: "success",
  594. confirmButtonColor: "#007AFF"
  595. }, function () {
  596. $scope.myData = _.reject($scope.myData, function (o) {
  597. return _.includes(selectedItem, o.id);
  598. });
  599. $scope.selected = {
  600. items: []
  601. };
  602. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length;
  603. $scope.gridApi.grid.selection.selectedCount = 0;
  604. });
  605. } else {
  606. SweetAlert.swal({
  607. title: "操作异常!",
  608. text: "系统异常,请稍后重试,或者联系管理员!",
  609. type: "error"
  610. });
  611. }
  612. })
  613. }
  614. }
  615. })
  616. }
  617. $scope.selected = {
  618. items: []
  619. }
  620. $scope.editted = {
  621. items: []
  622. }
  623. $scope.gridOptions.onRegisterApi = function (gridApi) {
  624. $scope.gridApi = gridApi;
  625. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  626. // // console.log(rowEntity);
  627. // });
  628. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  629. var filtersData = $scope.memoryfilterData;
  630. filtersData.idx = newPage - 1;
  631. filtersData.sum = pageSize;
  632. $scope.fileData.idx = newPage - 1;
  633. $scope.fileData.sum = pageSize;
  634. defaultFilterData = filtersData;
  635. $scope.refreshData('expand-right', $scope.fileData);
  636. });
  637. gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  638. var j = 0;
  639. for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
  640. if (scope.grid.appScope.selected.items[i] == scope.entity) {
  641. j++;
  642. break;
  643. }
  644. }
  645. // console.log("j="+j)
  646. if (j == 1) {
  647. scope.grid.appScope.selected.items.splice(i, 1);
  648. } else {
  649. scope.grid.appScope.selected.items.push(scope.entity)
  650. }
  651. });
  652. // gridApi.core.on.filterChanged($scope, function() {
  653. // var grid = this.grid;
  654. // var filtersData = {
  655. // idx: 0,
  656. // sum: 10
  657. // };
  658. // angular.forEach(grid.columns, function(item) {
  659. // if (item.enableFiltering) {
  660. // if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  661. // if (angular.isUndefined(filtersData['requester'])) {
  662. // filtersData['requester'] = {};
  663. // }
  664. // filtersData['requester'][item.field] = item.filters[0].term;
  665. // }
  666. // }
  667. // });
  668. // $scope.memoryfilterData = filtersData;
  669. // $scope.refreshData('expand-right', filtersData);
  670. // });
  671. gridApi.core.on.filterChanged($scope, function () {
  672. var grid = this.grid;
  673. // var filtersData = {
  674. // idx: 0,
  675. // sum: 10
  676. // };
  677. var filtersData = $scope.memoryfilterData;
  678. angular.forEach(grid.columns, function (item) {
  679. if (item.enableFiltering) {
  680. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  681. if (angular.isUndefined(filtersData['user'])) {
  682. filtersData['user'] = {};
  683. filtersData['user']['flag'] = -1;
  684. filtersData['user'][item.field] = item.filters[0].term;
  685. } else {
  686. filtersData.user.flag = -1;
  687. filtersData.user[item.field] = item.filters[0].term;
  688. }
  689. // filtersData['user']['flag'] = -1;
  690. // filtersData['user'][item.field] = item.filters[0].term;
  691. }
  692. }
  693. });
  694. $scope.memoryfilterData = filtersData;
  695. $scope.refreshData('expand-right', $scope.fileData);
  696. });
  697. };
  698. var defaultFilterData = {
  699. "idx": 0,
  700. "sum": 10
  701. };
  702. $scope.memoryfilterData = {
  703. "idx": 0,
  704. "sum": 10
  705. }
  706. $scope.ldloading = {};
  707. $scope.fileData = {
  708. "idx": 0,
  709. "sum": 10,
  710. "user": {}
  711. }
  712. $scope.treeItem = "";
  713. $scope.onFilterCallback = function (item) {
  714. $scope.treeItem = item
  715. }
  716. // 搜索
  717. $scope.searchData = function () {
  718. if ($scope.treeItem) {
  719. $scope.fileData.user.groupdata = $scope.treeItem
  720. }
  721. if($scope.fileData.user.name){
  722. $scope.fileData.user.selectType= "pinyin_qs"
  723. }
  724. $scope.refreshData('expand-right', $scope.fileData);
  725. }
  726. // 清空
  727. $scope.clean = function () {
  728. delete $scope.fileData.user.account;
  729. delete $scope.fileData.user.name;
  730. delete $scope.fileData.user.groupdata;
  731. $scope.treeItem = "";
  732. $scope.try_async_load();
  733. $scope.refreshData('expand-right', $scope.fileData);
  734. }
  735. //刷新
  736. $scope.refresh = function (style, filterData) {
  737. $scope.selected = {
  738. items: []
  739. };
  740. if ($scope.gridApi) {
  741. // $scope.gridApi.grid.options.paginationCurrentPage = 0;
  742. $scope.gridApi.grid.selection.selectedCount = 0;
  743. }
  744. $scope.refreshData('expand-right', $scope.fileData);
  745. }
  746. //获取列表数据
  747. $scope.refreshData = function (style, filterData) {
  748. $scope.ldloading[style.replace('-', '_')] = true;
  749. if (angular.isUndefined(filterData)) {
  750. filterData = defaultFilterData;
  751. }
  752. if (angular.isDefined($scope.searchTypes)) {
  753. filterData['searchType'] = $scope.searchTypes;
  754. }
  755. $scope.myData = [];
  756. filterData['flag'] = -1;
  757. // if ($scope.gridApi) {
  758. // $scope.gridApi.grid.selection.selectedCount = 0;
  759. // $scope.selected = { items: [] };
  760. // }
  761. console.log("filterData=" + JSON.stringify(filterData))
  762. if($rootScope.user.duty){
  763. // 当前的所属责任科室
  764. filterData.user.duty = $rootScope.user.duty;
  765. }else if($rootScope.user.branch){
  766. // 当前的所属院区
  767. filterData.user.branch = $rootScope.user.branch;
  768. }
  769. filterData.user.engineer = 1;
  770. api_user_data.fetchDataList('user', filterData).then(function (data) {
  771. var myData = Restangular.stripRestangular(data);
  772. $scope.gridOptions.totalItems = myData.totalNum;
  773. $scope.myData = myData.list;
  774. for (var i = 0; i < $scope.myData.length; i++) {
  775. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  776. }
  777. $scope.ldloading[style.replace('-', '_')] = false;
  778. // console.log("$scope.myData="+JSON.stringify($scope.myData))
  779. }, function () {
  780. $scope.ldloading[style.replace('-', '_')] = false;
  781. });
  782. };
  783. $scope.refreshData2 = function (style, filterData) {
  784. $scope.ldloading[style.replace('-', '_')] = true;
  785. if (angular.isUndefined(filterData)) {
  786. filterData = defaultFilterData;
  787. }
  788. if (angular.isDefined($scope.searchTypes)) {
  789. filterData['searchType'] = $scope.searchTypes;
  790. }
  791. // $scope.myData = [];
  792. filterData['flag'] = -1;
  793. // if ($scope.gridApi) {
  794. // $scope.gridApi.grid.selection.selectedCount = 0;
  795. // $scope.selected = { items: [] };
  796. // }
  797. console.log("filterData=" + JSON.stringify(filterData))
  798. if($rootScope.user.duty){
  799. // 当前的所属责任科室
  800. filterData.user.duty = $rootScope.user.duty;
  801. }else if($rootScope.user.branch){
  802. // 当前的所属院区
  803. filterData.user.branch = $rootScope.user.branch;
  804. }
  805. filterData.user.engineer = 1;
  806. api_user_data.fetchDataList('user', filterData).then(function (data) {
  807. var myData = Restangular.stripRestangular(data);
  808. $scope.gridOptions.totalItems = myData.totalNum;
  809. $scope.myData = myData.list;
  810. for (var i = 0; i < $scope.myData.length; i++) {
  811. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  812. }
  813. $scope.ldloading[style.replace('-', '_')] = false;
  814. // console.log("$scope.myData="+JSON.stringify($scope.myData))
  815. }, function () {
  816. $scope.ldloading[style.replace('-', '_')] = false;
  817. });
  818. };
  819. $scope.refreshData('expand-right', $scope.fileData);
  820. $scope.timer = $interval(function () {
  821. $scope.refreshData2('expand-right', $scope.fileData);
  822. }, $rootScope.refreshTime);
  823. $scope.$on('$destroy', function () {
  824. $interval.cancel($scope.timer)
  825. });
  826. }]);