deptCtrl.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('deptlistCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data) {
  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. for(var i=0;i<loginUser.menu.length;i++){
  14. if(loginUser.menu[i].link=="bumenguanli_xinzeng"){
  15. $scope.xinzeng=true
  16. }
  17. if(loginUser.menu[i].link=="bumenguanli_shanchu"){
  18. $scope.shanchu=true
  19. }
  20. if(loginUser.menu[i].link=="bumenguanli_bianji"){
  21. $scope.bianji=true
  22. }
  23. }
  24. $scope.gridOptions = {};
  25. $scope.gridOptions.data = 'myData';
  26. $scope.gridOptions.enableColumnResizing = true;
  27. $scope.gridOptions.enableFiltering = true;
  28. $scope.gridOptions.enableGridMenu = true;
  29. $scope.gridOptions.enableRowSelection = true;
  30. $scope.gridOptions.showGridFooter = true;
  31. $scope.gridOptions.showColumnFooter = false;
  32. $scope.gridOptions.fastWatch = true;
  33. $scope.gridOptions.useExternalFiltering = true;
  34. $scope.gridOptions.useExternalPagination = true;
  35. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  36. $scope.gridOptions.paginationPageSize = 10;
  37. $scope.gridOptions.multiSelect = true;
  38. $scope.gridOptions.enableSelectionBatchEvent = true; //使用批量使用事件
  39. //$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>";
  40. $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>";
  41. $scope.gridOptions.rowIdentity = function(row) {
  42. return row.id;
  43. };
  44. $scope.gridOptions.getRowIdentity = function(row) {
  45. return row.id;
  46. };
  47. $scope.gridOptions.columnDefs = [{
  48. name: 'item',
  49. displayName: '序号',
  50. width: 50,
  51. enableFiltering: false
  52. },
  53. { name: 'dept', displayName: '部门', width: '20%', enableFiltering: false },
  54. {
  55. name: 'parent.dept',
  56. displayName: '单位',
  57. width: '20%',
  58. enableFiltering: false,
  59. cellTemplate: '<div>' +
  60. '<div class="ui-grid-cell-contents" style="cursor:pointer;text-align:center">{{grid.appScope.transferDept(row.entity.parent.dept)}}</div>' +
  61. '</div>'
  62. },
  63. { name: 'phone', displayName: '部门电话', width: '20%', enableFiltering: false },
  64. {
  65. name: 'area', displayName: '区域地点', width: '20%', enableFiltering: false,
  66. cellTemplate: '<div>' +
  67. '<div class="ui-grid-cell-contents" style="cursor:pointer;text-align:center">{{row.entity.place.area.area+""+row.entity.place.place}}</div>' +
  68. '</div>'
  69. },
  70. {
  71. name: '操作',
  72. cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left" >' +
  73. // '<a ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑" tooltip-placement="right">' +
  74. // '<i class="fa fa-pencil-square-o"></i></a>'+
  75. '<a ng-click="grid.appScope.saveData(row.entity)" ng-show="grid.appScope.bianji" class="bianjifont">编辑</a>' +
  76. '</div></div>',
  77. enableFiltering: false
  78. },
  79. ];
  80. $scope.transferDept=function(data){
  81. if(data){
  82. return data
  83. }else{
  84. return "无"
  85. }
  86. }
  87. // 区域
  88. $scope.getArea = function () {
  89. var fildata = {
  90. "idx": 0,
  91. "sum": 1000
  92. };
  93. api_user_data.fetchDataList('area', fildata).then(function (res) {
  94. $scope.areaData=res.list;
  95. })
  96. }
  97. $scope.getArea();
  98. // 选择区域带出地点
  99. $scope.changeArea=function(item){
  100. $scope.getPlace(item.id)
  101. }
  102. // 地点
  103. $scope.getPlace = function (areaId) {
  104. var fildata = {
  105. "idx": 0,
  106. "sum": 1000,
  107. place: {area: {id: areaId}},
  108. };
  109. api_user_data.fetchDataList('place', fildata).then(function (res) {
  110. $scope.placeData=res.list;
  111. })
  112. }
  113. $scope.saveData = function(selectdata) {
  114. console.log(selectdata)
  115. var modalInstance = $modal.open({
  116. templateUrl: 'assets/views/system/tpl/deptchange.html',
  117. controller: function($scope, scope, $modalInstance, api_user_data) {
  118. $scope.deptdata = {};
  119. $scope.deptdata = selectdata;
  120. $scope.areaData=scope.areaData
  121. $scope.deptchoice = {};
  122. $scope.title = '部门修改';
  123. var filterData = { "idx": 0, "sum": 100 };
  124. api_user_data.fetchDataList('department', filterData).then(function(data) {
  125. $scope.deptchoice = Restangular.stripRestangular(data).list;
  126. })
  127. $scope.cancel = function() {
  128. $modalInstance.dismiss('cancel');
  129. };
  130. $scope.changeArea=function(item){
  131. var postData={
  132. idx: 0,
  133. sum: 1000
  134. }
  135. if(item){
  136. postData.place={area: {id: item.id}}
  137. }
  138. api_user_data.fetchDataList('place', postData).then(function(data) {
  139. $scope.placeData = Restangular.stripRestangular(data).list;
  140. })
  141. }
  142. $scope.changeArea(selectdata.area)
  143. $scope.savercode = function(deptdata) {
  144. if (deptdata&&deptdata.dept&&deptdata.phone&&deptdata.area&&deptdata.place){
  145. var fildata = { "department": { "id": deptdata.id, area:{id:deptdata.area.id},place:{id:deptdata.place.id,area:{id:deptdata.area.id}},"deleteFlag":0,"phone":deptdata.phone, "dept": deptdata.dept } }
  146. if (deptdata.parent) {
  147. fildata.department.parent= { id: deptdata.parent.id }
  148. }
  149. // console.log(fildata)
  150. api_user_data.updData('department', fildata).then(function(response) {
  151. if (response) {
  152. if (response.status == 200) {
  153. SweetAlert.swal({
  154. title: "修改成功!",
  155. type: "success"
  156. }, function() {
  157. scope.refreshData('expand-right', scope.fileData);
  158. })
  159. } else if (response.status == 500) {
  160. SweetAlert.swal({
  161. title: "修改失败!",
  162. text: "该部门已存在",
  163. type: "error"
  164. }, function() {
  165. scope.refreshData('expand-right', scope.fileData);
  166. })
  167. } else {
  168. SweetAlert.swal({
  169. title: "修改失败!",
  170. type: "error"
  171. }, function() {
  172. scope.refreshData('expand-right', scope.fileData);
  173. })
  174. }
  175. $modalInstance.close();
  176. }else{
  177. SweetAlert.swal({
  178. title: "修改失败!",
  179. type: "error"
  180. }, function() {
  181. scope.refreshData('expand-right', scope.fileData);
  182. })
  183. }
  184. })
  185. }else{
  186. SweetAlert.swal({
  187. title: "修改失败!",
  188. text: "请填写必填项!",
  189. type: "error",
  190. confirmButtonColor: "#DD6B55"
  191. }, function () {
  192. });
  193. }
  194. }
  195. },
  196. resolve: {
  197. scope: function() {
  198. return $scope;
  199. }
  200. }
  201. });
  202. }
  203. $scope.addData = function() {
  204. var modalInstance = $modal.open({
  205. templateUrl: 'assets/views/system/tpl/deptchange.html',
  206. controller: function($scope, $modalInstance, api_user_data) {
  207. var filterData = { "idx": 0, "sum": 100 };
  208. $scope.title = '部门新增';
  209. api_user_data.fetchDataList('department', filterData).then(function(data) {
  210. $scope.deptchoice = Restangular.stripRestangular(data).list;
  211. })
  212. api_user_data.fetchDataList('area', filterData).then(function(data) {
  213. $scope.areaData = Restangular.stripRestangular(data).list;
  214. })
  215. // api_wechatfile.getDictionary('department').then(function(data) {
  216. // $scope.deptchoice = Restangular.stripRestangular(data).list;
  217. // })
  218. $scope.cancel = function() {
  219. $modalInstance.dismiss('cancel');
  220. };
  221. $scope.savercode = function(deptdata) {
  222. if (deptdata&&deptdata.dept&&deptdata.phone&&deptdata.area&&deptdata.place){
  223. $modalInstance.close(deptdata);
  224. }else{
  225. SweetAlert.swal({
  226. title: "新增失败!",
  227. text: "请填写必填项!",
  228. type: "error",
  229. confirmButtonColor: "#DD6B55"
  230. }, function () {
  231. });
  232. }
  233. };
  234. $scope.changeArea=function(item){
  235. var postData={
  236. idx: 0,
  237. place: {area: {id: item.id}},
  238. sum: 1000
  239. }
  240. api_user_data.fetchDataList('place', postData).then(function(data) {
  241. $scope.placeData = Restangular.stripRestangular(data).list;
  242. })
  243. }
  244. }
  245. });
  246. modalInstance.result.then(function(selectedItem) {
  247. if (selectedItem.dept&&selectedItem.phone&&selectedItem.area&&selectedItem.place) {
  248. // angular.forEach($scope.myData,function(item){
  249. // if(item.dept==selectedItem.parent.dept){
  250. // selectedItem.parent.id=item.id;
  251. // }
  252. // })
  253. var fildata = { "department": { "phone": selectedItem.phone,"area":{id:selectedItem.area.id},"place":{id:selectedItem.place.id,"area":{id:selectedItem.area.id}}, "dept": selectedItem.dept } }
  254. if (selectedItem.parent) {
  255. fildata.department.parent= { "id": selectedItem.parent.id }
  256. }
  257. // console.log(fildata)
  258. api_user_data.addData('department', fildata).then(function(response) {
  259. if (response) {
  260. if (response.status == 200) {
  261. SweetAlert.swal({
  262. title: "新增成功!",
  263. type: "success"
  264. }, function() {
  265. $scope.refreshData('expand-right', $scope.fileData);
  266. })
  267. } else {
  268. SweetAlert.swal({
  269. title: "新增失败!",
  270. text: response.msg,
  271. type: "error"
  272. })
  273. }
  274. }
  275. })
  276. } else{
  277. SweetAlert.swal({
  278. title: "新增失败!",
  279. text: "请填写必填项!",
  280. type: "error",
  281. confirmButtonColor: "#DD6B55"
  282. }, function () {
  283. });
  284. }
  285. });
  286. }
  287. $scope.removeData = function() {
  288. var modalInstance = $modal.open({
  289. // templateUrl: 'assets/views/delete.html',
  290. templateUrl: 'assets/views/incident/tpl/acceptTask.tpl.html',
  291. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  292. var rmvList = [];
  293. $scope.title = '部门删除';
  294. $scope.connect = '确定要删除此部门?';
  295. rmvList.push(scope.selected.items);
  296. $scope.ok = function() {
  297. $modalInstance.close(rmvList);
  298. // }
  299. };
  300. $scope.cancel = function() {
  301. $modalInstance.dismiss('cancel');
  302. };
  303. },
  304. size: 'sm',
  305. resolve: {
  306. scope: function() {
  307. return $scope;
  308. }
  309. }
  310. });
  311. modalInstance.result.then(function(selectedItem) {
  312. if (selectedItem) {
  313. if (selectedItem.length > 0) {
  314. console.log(selectedItem);
  315. if (selectedItem[0].children.length>0) {
  316. SweetAlert.swal({
  317. title: "该部门存在子类部门",
  318. text: "请先删除该部门子类部门!",
  319. type: "error"
  320. });
  321. } else {
  322. api_user_data.rmvData('department', [selectedItem[0].id]).then(function(response) {
  323. if (response.status == 200) {
  324. SweetAlert.swal({
  325. title: "删除成功!",
  326. type: "success",
  327. confirmButtonColor: "#007AFF"
  328. }, function() {
  329. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id); });
  330. $scope.selected = {
  331. items: []
  332. };
  333. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length
  334. $scope.gridApi.grid.selection.selectedCount = 0;
  335. $scope.refreshData('expand-right', $scope.fileData);
  336. });
  337. } else {
  338. SweetAlert.swal({
  339. title: "操作异常!",
  340. text: "系统异常,请稍后重试,或者联系管理员!",
  341. type: "error"
  342. });
  343. }
  344. })
  345. }
  346. }
  347. }
  348. })
  349. }
  350. // $scope.removeData = function() {
  351. // var rmvList = [$scope.selected.items.id]
  352. // if (rmvList.length > 0) {
  353. // api_user_data.rmvData('department', rmvList).then(function(response) {
  354. // if (response.status == 200) {
  355. // SweetAlert.swal({
  356. // title: "删除成功!",
  357. // type: "success",
  358. // confirmButtonColor: "#007AFF"
  359. // }, function() {
  360. // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); });
  361. // $scope.selected = {
  362. // items: []
  363. // };
  364. // });
  365. // } else {
  366. // SweetAlert.swal({
  367. // title: "操作异常!",
  368. // text: "系统异常,请稍后重试,或者联系管理员!",
  369. // type: "error"
  370. // });
  371. // }
  372. // })
  373. // }
  374. // }
  375. $scope.selected = {
  376. items: []
  377. }
  378. $scope.editted = {
  379. items: []
  380. }
  381. $scope.gridOptions.onRegisterApi = function(gridApi) {
  382. $scope.gridApi = gridApi;
  383. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  384. // // console.log(rowEntity);
  385. // });
  386. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  387. var filtersData = $scope.memoryfilterData;
  388. filtersData.idx = newPage - 1;
  389. filtersData.sum = pageSize;
  390. $scope.fileData.idx=newPage - 1;
  391. $scope.fileData.sum=pageSize;
  392. defaultFilterData = filtersData;
  393. $scope.refreshData('expand-right', $scope.fileData);
  394. });
  395. gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
  396. scope.grid.appScope.selected.items = scope.entity
  397. });
  398. };
  399. var defaultFilterData = {
  400. "idx": 0,
  401. "sum": 10
  402. };
  403. $scope.memoryfilterData = {
  404. "idx": 0,
  405. "sum": 10
  406. }
  407. $scope.fileData={
  408. "idx":0,
  409. "sum":10,
  410. "department":{}
  411. }
  412. $scope.ldloading = {};
  413. $scope.refreshData = function(style, filterData) {
  414. $scope.selected.items = {};
  415. $scope.ldloading[style.replace('-', '_')] = true;
  416. if (angular.isUndefined(filterData)) {
  417. filterData = defaultFilterData;
  418. }
  419. $scope.myData = [];
  420. $scope.selected = { items: [] };
  421. if ($scope.gridApi) {
  422. $scope.gridApi.grid.selection.selectedCount = 0;
  423. }
  424. api_user_data.fetchDataList('department', filterData).then(function(data) {
  425. var myData = Restangular.stripRestangular(data);
  426. $scope.gridOptions.totalItems = myData.totalNum;
  427. $scope.myData = myData.list;
  428. for (var i = 0; i < $scope.myData.length; i++) {
  429. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  430. }
  431. $scope.ldloading[style.replace('-', '_')] = false;
  432. }, function() {
  433. $scope.ldloading[style.replace('-', '_')] = false;
  434. });
  435. };
  436. $scope.refreshData2 = function(style, filterData) {
  437. $scope.selected.items = {};
  438. $scope.ldloading[style.replace('-', '_')] = true;
  439. if (angular.isUndefined(filterData)) {
  440. filterData = defaultFilterData;
  441. }
  442. // $scope.myData = [];
  443. $scope.selected = { items: [] };
  444. if ($scope.gridApi) {
  445. $scope.gridApi.grid.selection.selectedCount = 0;
  446. }
  447. api_user_data.fetchDataList('department', filterData).then(function(data) {
  448. var myData = Restangular.stripRestangular(data);
  449. $scope.gridOptions.totalItems = myData.totalNum;
  450. $scope.myData = myData.list;
  451. for (var i = 0; i < $scope.myData.length; i++) {
  452. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  453. }
  454. $scope.ldloading[style.replace('-', '_')] = false;
  455. }, function() {
  456. $scope.ldloading[style.replace('-', '_')] = false;
  457. });
  458. };
  459. // 搜索
  460. $scope.searchData=function(){
  461. $scope.refreshData('expand-right', $scope.fileData);
  462. }
  463. // 清空
  464. $scope.clean=function(){
  465. delete $scope.fileData.department.dept;
  466. delete $scope.fileData.department.address;
  467. delete $scope.fileData.department.phone;
  468. delete $scope.fileData.department.parent;
  469. delete $scope.fileData.department.area;
  470. delete $scope.fileData.department.place;
  471. $scope.refreshData('expand-right', $scope.fileData);
  472. }
  473. // 获取单位下拉
  474. $scope.model={};
  475. $scope.deptData={};
  476. $scope.getDeptData=function(){
  477. var data={
  478. "idx":0,
  479. "sum":1000
  480. }
  481. api_user_data.fetchDataList('department',data).then(function(res){
  482. $scope.deptData=res.list;
  483. // console.log($scope.deptData)
  484. })
  485. }
  486. $scope.getDeptData();
  487. $scope.refreshData('expand-right', $scope.fileData);
  488. $scope.timer=$interval(function(){
  489. $scope.refreshData2('expand-right', $scope.fileData);
  490. },$rootScope.refreshTime);
  491. $scope.$on('$destroy',function(){
  492. $interval.cancel($scope.timer)
  493. });
  494. }]);