deptCtrl.js 21 KB

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