changeCtrl.js 15 KB

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