deptCtrl.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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.gridOptions = {};
  11. $scope.gridOptions.data = 'myData';
  12. $scope.gridOptions.enableColumnResizing = true;
  13. $scope.gridOptions.enableFiltering = true;
  14. $scope.gridOptions.enableGridMenu = false;
  15. $scope.gridOptions.enableRowSelection = true;
  16. $scope.gridOptions.showGridFooter = true;
  17. $scope.gridOptions.showColumnFooter = false;
  18. $scope.gridOptions.fastWatch = true;
  19. $scope.gridOptions.useExternalFiltering = true;
  20. $scope.gridOptions.useExternalPagination = true;
  21. $scope.gridOptions.paginationPageSizes = [10];
  22. $scope.gridOptions.paginationPageSize = 10;
  23. $scope.gridOptions.multiSelect = false;
  24. //$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>";
  25. $scope.gridOptions.rowIdentity = function(row) {
  26. return row.id;
  27. };
  28. $scope.gridOptions.getRowIdentity = function(row) {
  29. return row.id;
  30. };
  31. $scope.gridOptions.columnDefs = [{
  32. name: 'item',
  33. displayName: '序号',
  34. width: 50,
  35. enableFiltering: false
  36. },
  37. { name: 'dept', displayName: '部门', width: '20%', enableFiltering: false },
  38. { name: 'pcode', displayName: '部门编码', width: '20%', enableFiltering: false },
  39. { name: 'parent.dept', displayName: '上级部门', width: '20%', enableFiltering: false },
  40. { name: 'email', displayName: '邮箱', width: '20%', enableFiltering: false },
  41. {
  42. name: '编辑',
  43. cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left" >' +
  44. // '<a ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑" tooltip-placement="right">' +
  45. // '<i class="fa fa-pencil-square-o"></i></a>'+
  46. '<a ng-click="grid.appScope.saveData(row.entity)" class="bianjifont">编辑</a>' +
  47. '</div></div>',
  48. enableFiltering: false
  49. },
  50. ];
  51. $scope.saveData = function(selectdata) {
  52. var modalInstance = $modal.open({
  53. templateUrl: 'assets/views/system/tpl/deptchange.html',
  54. controller: function($scope, scope, $modalInstance, api_user_data) {
  55. $scope.deptdata = {};
  56. $scope.deptdata = selectdata;
  57. $scope.deptchoice = {};
  58. $scope.title = '部门修改';
  59. var filterData = { "idx": 0, "sum": 100 };
  60. api_user_data.fetchDataList('department', filterData).then(function(data) {
  61. $scope.deptchoice = Restangular.stripRestangular(data).list;
  62. })
  63. $scope.cancel = function() {
  64. $modalInstance.dismiss('cancel');
  65. };
  66. $scope.savercode = function(deptdata) {
  67. // var fildata={"department":{"id":deptdata.id,"pcode":deptdata.pcode,"dept":deptdata.dept,"parent":{"id":deptdata.parent.id}}}
  68. if (deptdata.parent) {
  69. var fildata = { "department": { "id": deptdata.id, "pcode": deptdata.pcode,"deleteFlag":0,"email":deptdata.email, "dept": deptdata.dept, "parent": { "id": deptdata.parent.id } } }
  70. } else {
  71. var fildata = { "department": { "id": deptdata.id, "pcode": deptdata.pcode,"deleteFlag":0,"email":deptdata.email, "dept": deptdata.dept } }
  72. }
  73. api_user_data.updData('department', fildata).then(function(response) {
  74. if (response) {
  75. if (response.status == 200) {
  76. SweetAlert.swal({
  77. title: "修改成功!",
  78. type: "success"
  79. }, function() {
  80. scope.refreshData('expand-right', scope.memoryfilterData);
  81. })
  82. } else if (response.status == 500) {
  83. SweetAlert.swal({
  84. title: "新增失败!",
  85. text: "该部门已存在",
  86. type: "error"
  87. }, function() {
  88. scope.refreshData('expand-right', scope.memoryfilterData);
  89. })
  90. } else {
  91. SweetAlert.swal({
  92. title: "修改失败!",
  93. type: "error"
  94. }, function() {
  95. scope.refreshData('expand-right', scope.memoryfilterData);
  96. })
  97. }
  98. $modalInstance.close();
  99. }else{
  100. SweetAlert.swal({
  101. title: "修改失败!",
  102. type: "error"
  103. }, function() {
  104. scope.refreshData('expand-right', scope.memoryfilterData);
  105. })
  106. }
  107. })
  108. }
  109. },
  110. resolve: {
  111. scope: function() {
  112. return $scope;
  113. }
  114. }
  115. });
  116. }
  117. $scope.addData = function() {
  118. var modalInstance = $modal.open({
  119. templateUrl: 'assets/views/system/tpl/deptchange.html',
  120. controller: function($scope, $modalInstance, api_user_data,api_wechatfile) {
  121. var filterData = { "idx": 0, "sum": 100 };
  122. $scope.title = '部门新增';
  123. api_user_data.fetchDataList('department', filterData).then(function(data) {
  124. $scope.deptchoice = Restangular.stripRestangular(data).list;
  125. })
  126. // api_wechatfile.getDictionary('department').then(function(data) {
  127. // $scope.deptchoice = Restangular.stripRestangular(data).list;
  128. // })
  129. $scope.cancel = function() {
  130. $modalInstance.dismiss('cancel');
  131. };
  132. $scope.savercode = function(deptdata) {
  133. $modalInstance.close(deptdata);
  134. };
  135. }
  136. });
  137. modalInstance.result.then(function(selectedItem) {
  138. if (selectedItem) {
  139. // angular.forEach($scope.myData,function(item){
  140. // if(item.dept==selectedItem.parent.dept){
  141. // selectedItem.parent.id=item.id;
  142. // }
  143. // })
  144. if (selectedItem.parent) {
  145. var fildata = { "department": { "pcode": selectedItem.pcode,"email":selectedItem.email, "dept": selectedItem.dept, "parent": { "id": selectedItem.parent.id } } }
  146. } else {
  147. var fildata = { "department": { "pcode": selectedItem.pcode,"email":selectedItem.email, "dept": selectedItem.dept } }
  148. }
  149. api_user_data.addData('department', fildata).then(function(response) {
  150. if (response) {
  151. if (response.status == 200) {
  152. SweetAlert.swal({
  153. title: "新增成功!",
  154. type: "success"
  155. }, function() {
  156. $scope.refreshData('expand-right', defaultFilterData);
  157. })
  158. } else if (response.status == 408) {
  159. SweetAlert.swal({
  160. title: "新增失败!",
  161. text: "该部门已存在",
  162. type: "error"
  163. })
  164. } else {
  165. SweetAlert.swal({
  166. title: "新增失败!",
  167. type: "error"
  168. })
  169. }
  170. }
  171. })
  172. }
  173. });
  174. }
  175. $scope.removeData = function() {
  176. var modalInstance = $modal.open({
  177. // templateUrl: 'assets/views/delete.html',
  178. templateUrl: 'assets/views/incident/tpl/acceptTask.tpl.html',
  179. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  180. var rmvList = [];
  181. $scope.title = '部门删除';
  182. $scope.connect = '确定要删除此部门?';
  183. rmvList.push(scope.selected.items.id);
  184. $scope.ok = function() {
  185. $modalInstance.close(rmvList);
  186. // }
  187. };
  188. $scope.cancel = function() {
  189. $modalInstance.dismiss('cancel');
  190. };
  191. },
  192. size: 'sm',
  193. resolve: {
  194. scope: function() {
  195. return $scope;
  196. }
  197. }
  198. });
  199. modalInstance.result.then(function(selectedItem) {
  200. if (selectedItem) {
  201. if (selectedItem.length > 0) {
  202. // if (selectedItem.child) {
  203. // SweetAlert.swal({
  204. // title: "该部门存在子类部门",
  205. // text: "请先删除该部门子类部门!",
  206. // type: "error"
  207. // });
  208. // } else {
  209. api_user_data.rmvData('department', selectedItem).then(function(response) {
  210. if (response.status == 200) {
  211. SweetAlert.swal({
  212. title: "删除成功!",
  213. type: "success",
  214. confirmButtonColor: "#007AFF"
  215. }, function() {
  216. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id); });
  217. $scope.selected = {
  218. items: []
  219. };
  220. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length
  221. $scope.gridApi.grid.selection.selectedCount = 0;
  222. });
  223. } else {
  224. SweetAlert.swal({
  225. title: "操作异常!",
  226. text: "系统异常,请稍后重试,或者联系管理员!",
  227. type: "error"
  228. });
  229. }
  230. })
  231. }
  232. // }
  233. }
  234. })
  235. }
  236. // $scope.removeData = function() {
  237. // var rmvList = [$scope.selected.items.id]
  238. // if (rmvList.length > 0) {
  239. // api_user_data.rmvData('department', rmvList).then(function(response) {
  240. // if (response.status == 200) {
  241. // SweetAlert.swal({
  242. // title: "删除成功!",
  243. // type: "success",
  244. // confirmButtonColor: "#007AFF"
  245. // }, function() {
  246. // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); });
  247. // $scope.selected = {
  248. // items: []
  249. // };
  250. // });
  251. // } else {
  252. // SweetAlert.swal({
  253. // title: "操作异常!",
  254. // text: "系统异常,请稍后重试,或者联系管理员!",
  255. // type: "error"
  256. // });
  257. // }
  258. // })
  259. // }
  260. // }
  261. $scope.selected = {
  262. items: []
  263. }
  264. $scope.editted = {
  265. items: []
  266. }
  267. $scope.gridOptions.onRegisterApi = function(gridApi) {
  268. $scope.gridApi = gridApi;
  269. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  270. // // console.log(rowEntity);
  271. // });
  272. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  273. var filtersData = $scope.memoryfilterData;
  274. filtersData.idx = newPage - 1;
  275. filtersData.sum = pageSize;
  276. defaultFilterData = filtersData;
  277. $scope.refreshData('expand-right', filtersData);
  278. });
  279. gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
  280. scope.grid.appScope.selected.items = scope.entity
  281. });
  282. };
  283. var defaultFilterData = {
  284. "idx": 0,
  285. "sum": 10
  286. };
  287. $scope.memoryfilterData = {
  288. "idx": 0,
  289. "sum": 10
  290. }
  291. $scope.ldloading = {};
  292. $scope.refreshData = function(style, filterData) {
  293. $scope.selected.items = {};
  294. $scope.ldloading[style.replace('-', '_')] = true;
  295. if (angular.isUndefined(filterData)) {
  296. filterData = defaultFilterData;
  297. }
  298. $scope.myData = [];
  299. $scope.selected = { items: [] };
  300. if ($scope.gridApi) {
  301. $scope.gridApi.grid.selection.selectedCount = 0;
  302. }
  303. api_user_data.fetchDataList('department', filterData).then(function(data) {
  304. var myData = Restangular.stripRestangular(data);
  305. $scope.gridOptions.totalItems = myData.totalNum;
  306. $scope.myData = myData.list;
  307. for (var i = 0; i < $scope.myData.length; i++) {
  308. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  309. }
  310. $scope.ldloading[style.replace('-', '_')] = false;
  311. }, function() {
  312. $scope.ldloading[style.replace('-', '_')] = false;
  313. });
  314. };
  315. $scope.refreshData('expand-right', defaultFilterData);
  316. }]);