changeCtrl.js 13 KB

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