deptCtrl.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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:'id', displayName:'编号', width:100, enableFiltering:false},
  33. { name:'pcode', displayName:'部门标识', width:100, enableFiltering:false},
  34. { name:'dept', displayName:'部门', width:300, enableFiltering:false},
  35. { name:'parent.dept', displayName:'上级部门', width:200, enableFiltering:false},
  36. { name:'修改', cellTemplate:'<a class="btn btn-sm btn-info" ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑">' +
  37. '<i class="fa fa-pencil-square-o"/></a>' , width:100,enableFiltering:false}
  38. ];
  39. $scope.saveData = function(selectdata){
  40. var modalInstance = $modal.open({
  41. templateUrl: 'assets/views/system/tpl/deptchange.html',
  42. controller: function($scope, $modalInstance, api_user_data){
  43. $scope.deptdata={};
  44. $scope.deptdata=selectdata;
  45. $scope.deptchoice={};
  46. var filterData = {"idx":0,"sum":100};
  47. api_user_data.fetchDataList('department',filterData).then(function(data){
  48. $scope.deptchoice = Restangular.stripRestangular(data).list;
  49. })
  50. $scope.cancel = function() {
  51. $modalInstance.dismiss('cancel');
  52. };
  53. $scope.savercode = function(deptdata){
  54. var fildata={"department":{"id":deptdata.id,"pcode":deptdata.pcode,"dept":deptdata.dept,"parent":{"id":deptdata.parent.id}}}
  55. api_user_data.updData('department',fildata).then(function(response){
  56. if(response){
  57. if(response.status==200){
  58. SweetAlert.swal({
  59. title:"修改成功!",
  60. type:"success"
  61. },function(){
  62. // console.log($scope.serverdata)
  63. })
  64. }else{
  65. SweetAlert.swal({
  66. title:"修改失败!",
  67. type:"error"
  68. })
  69. }
  70. $modalInstance.close();
  71. }
  72. })
  73. }
  74. }
  75. });
  76. }
  77. $scope.addData = function(){
  78. var modalInstance = $modal.open({
  79. templateUrl: 'assets/views/system/tpl/deptchange.html',
  80. controller: function($scope, $modalInstance, api_user_data){
  81. var filterData = {"idx":0,"sum":100};
  82. api_user_data.fetchDataList('department',filterData).then(function(data){
  83. $scope.deptchoice = Restangular.stripRestangular(data).list;
  84. })
  85. $scope.cancel = function() {
  86. $modalInstance.dismiss('cancel');
  87. };
  88. $scope.savercode = function(deptdata) {
  89. $modalInstance.close(deptdata);
  90. };
  91. }
  92. });
  93. modalInstance.result.then(function(selectedItem) {
  94. if(selectedItem){
  95. // angular.forEach($scope.myData,function(item){
  96. // if(item.dept==selectedItem.parent.dept){
  97. // selectedItem.parent.id=item.id;
  98. // }
  99. // })
  100. var fildata={"department":{"pcode":selectedItem.pcode,"dept":selectedItem.dept,"parent":{"id":selectedItem.parent.id}}}
  101. api_user_data.addData('department',fildata).then(function(response){
  102. if(response){
  103. if(response.status==200){
  104. SweetAlert.swal({
  105. title:"新增成功!",
  106. type:"success"
  107. },function(){
  108. $scope.refreshData('expand-right', defaultFilterData);
  109. })
  110. }else{
  111. SweetAlert.swal({
  112. title:"新增失败!",
  113. type:"error"
  114. })
  115. }
  116. }
  117. })
  118. }
  119. });
  120. }
  121. $scope.removeData = function(){
  122. var rmvList = [$scope.selected.items.id]
  123. if(rmvList.length>0){
  124. api_user_data.rmvData('department',rmvList).then(function(response){
  125. if(response.status==200){
  126. SweetAlert.swal({
  127. title: "删除成功!",
  128. type: "success",
  129. confirmButtonColor: "#007AFF"
  130. },function(){
  131. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList,o.id); });
  132. $scope.selected = {
  133. items:[]
  134. };
  135. });
  136. }else{
  137. SweetAlert.swal({
  138. title: "操作异常!",
  139. text: "系统异常,请稍后重试,或者联系管理员!",
  140. type: "error"
  141. });
  142. }
  143. })
  144. }
  145. }
  146. $scope.selected = {
  147. items:[]
  148. }
  149. $scope.editted = {
  150. items:[]
  151. }
  152. $scope.gridOptions.onRegisterApi = function(gridApi){
  153. $scope.gridApi = gridApi;
  154. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  155. // // console.log(rowEntity);
  156. // });
  157. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  158. var filtersData = $scope.memoryfilterData;
  159. filtersData.idx=newPage-1;
  160. filtersData.sum=pageSize;
  161. $scope.refreshData('expand-right',filtersData);
  162. });
  163. gridApi.selection.on.rowSelectionChanged($scope, function(scope){
  164. scope.grid.appScope.selected.items=scope.entity
  165. });
  166. };
  167. var defaultFilterData = {
  168. "idx":0,
  169. "sum":10
  170. };
  171. $scope.memoryfilterData = {
  172. "idx":0,
  173. "sum":10
  174. }
  175. $scope.ldloading = {};
  176. $scope.refreshData = function(style,filterData){
  177. $scope.ldloading[style.replace('-', '_')] = true;
  178. if(angular.isUndefined(filterData)){
  179. filterData = defaultFilterData;
  180. }
  181. $scope.myData = [];
  182. api_user_data.fetchDataList('department',filterData).then(function(data){
  183. var myData = Restangular.stripRestangular(data);
  184. $scope.gridOptions.totalItems = myData.totalNum;
  185. $scope.myData = myData.list;
  186. $scope.ldloading[style.replace('-', '_')] = false;
  187. },function(){
  188. $scope.ldloading[style.replace('-', '_')] = false;
  189. });
  190. };
  191. $scope.refreshData('expand-right', defaultFilterData);
  192. }]);