changeCtrl.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. 'use strict';
  2. app.controller('changeListCtrl', ["$scope", "i18nService", "$rootScope", "$state", "$timeout", "$interval", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", function($scope, i18nService, $rootScope, $state, $timeout, $interval, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain) {
  3. $scope.langs = i18nService.getAllLangs();
  4. $scope.lang = 'zh-cn';
  5. i18nService.setCurrentLang($scope.lang);
  6. var pdKey = $state.current.pdKey;
  7. $scope.gridOptions = {};
  8. $scope.gridOptions.data = 'myData';
  9. $scope.gridOptions.enableColumnResizing = true;
  10. $scope.gridOptions.enableFiltering = true;
  11. $scope.gridOptions.enableGridMenu = true;
  12. $scope.gridOptions.enableRowSelection = true;
  13. $scope.gridOptions.showGridFooter = true;
  14. $scope.gridOptions.showColumnFooter = true;
  15. $scope.gridOptions.fastWatch = true;
  16. $scope.gridOptions.useExternalFiltering = true;
  17. $scope.gridOptions.useExternalPagination = true;
  18. $scope.gridOptions.paginationPageSizes = [10];
  19. $scope.gridOptions.paginationPageSize = 10;
  20. $scope.gridOptions.multiSelect = false;
  21. // $scope.gridOptions.rowTemplate= "<div ng-dblclick=\"grid.appScope.pdList.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>";
  22. //
  23. $scope.gridOptions.rowIdentity = function(row) {
  24. return row.id;
  25. };
  26. $scope.gridOptions.getRowIdentity = function(row) {
  27. return row.id;
  28. };
  29. $scope.gridOptions.columnDefs = [
  30. { name: 'changesign', displayName: '变更单号', width: 80 },
  31. { name: 'title', displayName: '变更标题', width: 100 },
  32. { name: 'requestingPerson.name', displayName: '请求人', width: 100, enableFiltering: false },
  33. { name: 'registrationTime', displayName: '登记时间', width: 120, enableFiltering: false },
  34. { name: 'source.name', displayName: '变更来源', width: 100, enableFiltering: false },
  35. { name: 'type.name', displayName: '变更类型', width: 100, enableFiltering: false },
  36. { name: 'classify.name', displayName: '变更分类', width: 100, enableFiltering: false },
  37. { name: 'rickLevel.name', displayName: '风险等级', width: 100, enableFiltering: false },
  38. { name: 'state.name', displayName: '状态', width: 100, enableFiltering: false },
  39. { name: '操作', cellTemplate: '<changeoperator item="row.entity" colobject="col">', width: 100, enableFiltering: false }
  40. ];
  41. $scope.searchstate = 'todo';
  42. $scope.states = [
  43. { id: "all", name: '全部的变更' },
  44. { id: "todo", name: '待我处理的变更' },
  45. { id: "create", name: '我创建的变更' },
  46. { id: "done", name: '我处理过的变更' }
  47. ];
  48. $scope.onChange = function(searchType) {
  49. $scope.searchstate = searchType;
  50. defaultFilterData = $scope.memoryfilterData;
  51. defaultFilterData['searchType'] = searchType;
  52. $scope.refreshData('expand-right', defaultFilterData);
  53. }
  54. $scope.clear = function() {
  55. $scope.searchkeys = {};
  56. // $scope.try_async_load();
  57. var fildata = {
  58. // "assignee": $rootScope.user.id,
  59. // "candidateGroups": loginuserGroup,
  60. // "searchType": JSON.parse(sessionStorage.getItem("searchproblem")).searchType,
  61. // "idx": JSON.parse(sessionStorage.getItem("searchproblem")).idx,
  62. // "sum": JSON.parse(sessionStorage.getItem("searchproblem")).sum
  63. "assignee": $rootScope.user.id,
  64. "candidateGroups": $rootScope.user.group[0].id,
  65. "idx": 0,
  66. "sum": 10,
  67. }
  68. sessionStorage.removeItem("searchchange");
  69. $scope.memoryfilterData = fildata;
  70. $scope.refreshData('expand-right', fildata);
  71. }
  72. $scope.chiceIncident = function(item, stateid) {
  73. // if (stateid && stateid.code) {
  74. // item.statusId = stateid.code;
  75. // } else {
  76. // item.statusId = undefined;
  77. // }
  78. var fildata = {};
  79. if (sessionStorage.searchincident) {
  80. fildata = JSON.parse(sessionStorage.getItem("searchchange"));
  81. $scope.gridOptions.paginationCurrentPage = 1;
  82. fildata.idx = 0;
  83. } else {
  84. fildata = defaultFilterData;
  85. }
  86. // $scope.memoryfilterData = fildata;
  87. // if (!fildata.incident) {
  88. // fildata['incident'] = {};
  89. // }
  90. // if (item.acceptDate) {
  91. // item.acceptDate = moment(item.acceptDate).format('YYYY-MM-DD HH:mm:ss');
  92. // }
  93. // if (item.acceptDateEnd) {
  94. // // item.acceptDateEnd = moment(item.acceptDateEnd).format('YYYY-MM-DD HH:mm:ss');
  95. // item.acceptDateEnd = moment(new Date(item.acceptDateEnd).getTime() + 86399999).format('YYYY-MM-DD HH:mm:ss');
  96. // }
  97. if (item) {
  98. if (!fildata.change) {
  99. fildata.change = {};
  100. }
  101. var transitiondata = angular.copy(item);
  102. angular.extend(fildata.change, transitiondata)
  103. sessionStorage['searchchange'] = angular.copy(JSON.stringify(fildata));
  104. }
  105. $scope.memoryfilterData = fildata;
  106. $scope.refreshData('expand-right', fildata);
  107. }
  108. $scope.gridOptions.onRegisterApi = function(gridApi) {
  109. $scope.gridApi = gridApi;
  110. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  111. var filtersData = $scope.memoryfilterData;
  112. filtersData.idx = newPage - 1;
  113. filtersData.sum = pageSize;
  114. $rootScope['idxchange'] = newPage - 1;
  115. $scope.refreshData('expand-right', filtersData);
  116. // $scope.refreshData('expand-right', {"assignee":$rootScope.user.id, "candidateGroups":$rootScope.user.group[0].id, "idx":newPage-1,"sum":pageSize});
  117. });
  118. gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  119. //$scope.selected.item = data.entity;
  120. // console.log(data);
  121. });
  122. gridApi.core.on.filterChanged($scope, function() {
  123. var grid = this.grid;
  124. var filtersData = {
  125. "assignee": $rootScope.user.id,
  126. "candidateGroups": $rootScope.user.group[0].id,
  127. idx: 0,
  128. sum: 10
  129. };
  130. angular.forEach(grid.columns, function(item) {
  131. if (item.enableFiltering) {
  132. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  133. // console.log('item.filters[0]='+JSON.stringify(item.filters[0]));
  134. if (angular.isUndefined(filtersData['change'])) {
  135. filtersData['change'] = {};
  136. }
  137. filtersData['change'][item.field] = item.filters[0].term;
  138. }
  139. }
  140. });
  141. $scope.memoryfilterData = filtersData;
  142. $scope.refreshData('expand-right', filtersData);
  143. });
  144. };
  145. $scope.memoryfilterData = defaultFilterData = {
  146. "assignee": $rootScope.user.id,
  147. // "searchType": "all",
  148. "candidateGroups": $rootScope.user.group[0].id,
  149. "idx": 0,
  150. "sum": 10
  151. };
  152. $scope.selectRowFunction = function(data) {
  153. // console.log(data);
  154. // $state.go('app.process.modeler',{modelId:data.id});
  155. $state.go('app.change.editor', { taskId: data.taskId, processInstanceId: data.processInstanceId });
  156. };
  157. $scope.lookFunction = function(data) {
  158. console.log('data=' + JSON.stringify(data.id));
  159. //$state.go('app.detail',{taskId:data.taskId,processInstanceId: data.processInstanceId});
  160. $state.go('app.detail', { formKey: 'changeDetail', pdKey: 'change', dataId: data.id, taskId: data.taskId, processInstanceId: data.processInstanceId });
  161. };
  162. this.removeRowFunction = function(data) {
  163. //TODO $translate('key')
  164. SweetAlert.swal({
  165. title: "确认删除?",
  166. text: "删除以后,你将不能恢复该数据!",
  167. type: "warning",
  168. cancelButtonText: "取消",
  169. showCancelButton: true,
  170. confirmButtonColor: "#DD6B55",
  171. confirmButtonText: "确认删除!"
  172. }, function(isConfirm) {
  173. if (isConfirm) {
  174. // api_bpm_domain.removemodel(data.id).then(function(response){
  175. // if(response){
  176. // $scope.refreshData();
  177. // SweetAlert.swal({
  178. // title: "删除成功!",
  179. // confirmButtonColor: "#007AFF"
  180. // });
  181. // }
  182. // });
  183. } else {
  184. }
  185. });
  186. }
  187. //$scope.callsPending = 0;
  188. //var i = 0;
  189. var defaultFilterData = {
  190. "assignee": $rootScope.user.id,
  191. "candidateGroups": $rootScope.user.group[0].id,
  192. // "searchType": "all",
  193. "idx": 0,
  194. "sum": 10
  195. };
  196. if (angular.isDefined($rootScope['searchchange'])) {
  197. defaultFilterData['searchType'] = $rootScope['searchchange'];
  198. $scope.searchTypes = $rootScope['searchchange'];
  199. // console.log($scope.searchTypes);
  200. }
  201. // $scope.searchTypeOptions = [
  202. // {name:'请选择...', search:''},
  203. // {name:'待我处理的变更', search:'todo'},
  204. // {name:'我创建的变更', search:'create'},
  205. // {name:'我处理过的变更', search:'done'},
  206. // ];
  207. // if(angular.isDefined($rootScope['idxchange'])){
  208. // defaultFilterData.idx=$rootScope['idxchange'];
  209. // }
  210. $scope.ldloading = {};
  211. $scope.refreshData = function(style, filterData) {
  212. $scope.ldloading[style.replace('-', '_')] = true;
  213. if (angular.isUndefined(filterData)) {
  214. filterData = defaultFilterData;
  215. }
  216. if (angular.isDefined($scope.searchTypes)) {
  217. filterData['searchType'] = $scope.searchTypes;
  218. $rootScope['searchchange'] = $scope.searchTypes;
  219. }
  220. $scope.myData = [];
  221. //var start = new Date();
  222. //var sec = $interval(function () {
  223. //$scope.callsPending++;
  224. api_bpm_domain.fetchtask(pdKey, filterData).then(function(data) {
  225. $scope.callsPending--;
  226. // console.log('filterData='+JSON.stringify(filterData));
  227. var myData = Restangular.stripRestangular(data);
  228. $scope.gridOptions.totalItems = myData.totalNum;
  229. $scope.myData = myData.data;
  230. $scope.ldloading[style.replace('-', '_')] = false;
  231. }, function() {
  232. $scope.ldloading[style.replace('-', '_')] = false;
  233. });
  234. };
  235. $scope.refreshData('expand-right', defaultFilterData);
  236. }]);
  237. app.controller('ChangeOperCtrl', ['$rootScope', '$http', '$scope', function($rootScope, $http, $scope, $event) {
  238. // console.log('$rootScope.user3='+JSON.stringify($scope.item));
  239. if ($scope.item.handlerUser != null) {
  240. if ($rootScope.user.id == $scope.item.handlerUser.id) {
  241. $scope.item.chaozuoPower = true;
  242. }
  243. }
  244. $scope.look = function() {
  245. $scope.colobject.grid.appScope.lookFunction($scope.item);
  246. // console.log('$scope.item='+JSON.stringify($scope.item));
  247. }
  248. $scope.edit = function() {
  249. $scope.colobject.grid.appScope.selectRowFunction($scope.item);
  250. // console.log('$scope.item='+JSON.stringify($scope.item));
  251. $scope.doEdit($scope.item.id);
  252. }
  253. }]);
  254. app.directive('changeoperator', function() {
  255. return {
  256. restrict: 'E',
  257. scope: {
  258. item: '=',
  259. colobject: '='
  260. },
  261. controller: 'ChangeOperCtrl',
  262. template: '<div class="links cl-effect-1">' +
  263. '<a ng-click="look()" tooltip="查看" tooltip-placement="left"><i class="ti-eye"></i></a>' +
  264. '<a ng-click="edit()" ng-show="{{item.chaozuoPower}}" tooltip="编辑" tooltip-placement="left"><i class="fa fa-pencil-square-o"></i></a>' +
  265. '</div>'
  266. };
  267. });