cmdbauditlistCtrl.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. 'use strict';
  2. app.controller('cmdbauditlistCtrl', ["$scope", "$http", "i18nService", "$rootScope", "$state", "$timeout", "moment", "$interval", "$modal", "$stateParams", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", "api_bpm", "api_bpm_data", "api_user_data", function($scope, $http, i18nService, $rootScope, $state, $timeout, moment, $interval, $modal, $stateParams, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain, api_bpm, api_bpm_data, api_user_data) {
  3. $scope.langs = i18nService.getAllLangs();
  4. $scope.lang = 'zh-cn';
  5. i18nService.setCurrentLang($scope.lang);
  6. $scope.myData = [];
  7. var loginUser = $rootScope.user;
  8. var loginuserGroup = "";
  9. for (var i = 0; i < $rootScope.user.group.length; i++) {
  10. if (i == 0) {
  11. loginuserGroup = $rootScope.user.group[i].id;
  12. } else {
  13. loginuserGroup = loginuserGroup + "," + $rootScope.user.group[i].id;
  14. }
  15. }
  16. var pdKey = $state.current.pdKey;
  17. $scope.gridOptions = {};
  18. $scope.gridOptions.data = 'myData';
  19. $scope.gridOptions.enableColumnResizing = true;
  20. $scope.gridOptions.enableFiltering = false;
  21. $scope.gridOptions.enableGridMenu = false;
  22. $scope.gridOptions.enableSelectAll = true;
  23. $scope.gridOptions.enableRowSelection = true;
  24. $scope.gridOptions.showGridFooter = true;
  25. $scope.gridOptions.showColumnFooter = false;
  26. $scope.gridOptions.fastWatch = true;
  27. $scope.gridOptions.enableSorting = true;
  28. $scope.gridOptions.useExternalSorting = true;
  29. $scope.gridOptions.useExternalFiltering = false;
  30. $scope.gridOptions.useExternalPagination = true;
  31. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  32. $scope.gridOptions.paginationPageSize = 10;
  33. $scope.gridOptions.multiSelect = true;
  34. var mun = $scope.gridOptions.paginationPageSize;
  35. // $scope.gridOptions.rowTemplate = "<div ng-click=\"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>";
  36. $scope.gridOptions.rowIdentity = function(row) {
  37. return row.id;
  38. };
  39. $scope.gridOptions.getRowIdentity = function(row) {
  40. return row.id;
  41. };
  42. $scope.transferstatus = function(item) {
  43. var statecolor = "待处理";
  44. if (item == 1) { //待处理
  45. statecolor = "待处理";
  46. } else if (item == 2) { //已处理
  47. statecolor = "已处理";
  48. }
  49. return statecolor;
  50. }
  51. $scope.gridOptions.columnDefs = [
  52. // {
  53. // name: 'id',
  54. // displayName: '',
  55. // width: 40,
  56. // cellTemplate: '<div>' +
  57. // '<div class="ui-grid-cell-contents" tooltip={{grid.appScope.transfertip(row.entity)}} tooltip-placement="right"><i style="font-size: 18px !important;" class="{{grid.appScope.transferColor(row.entity)}}"></i></div></div>' +
  58. // '</div>'
  59. // },
  60. {
  61. name: 'item',
  62. displayName: '序号',
  63. width: 50,
  64. cellTemplate: '<div>' +
  65. '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
  66. '</div>'
  67. },
  68. {
  69. name: 'orderId',
  70. displayName: '审计单号',
  71. width: '25%',
  72. enableSorting: false
  73. },
  74. {
  75. name: 'user.name',
  76. displayName: '审计执行人',
  77. width: '15%',
  78. enableSorting: false
  79. },
  80. {
  81. name: 'time',
  82. displayName: '审计时间',
  83. width: '20%'
  84. },
  85. {
  86. name: 'status',
  87. displayName: '状态',
  88. width: '15%',
  89. enableSorting: false,
  90. cellTemplate: '<div>' +
  91. '<div class="ui-grid-cell-contents">{{grid.appScope.transferstatus(row.entity.status)}}</div>' +
  92. '</div>'
  93. },
  94. { name: '操作', enableSorting: false, cellTemplate: '<cmdblistoperator style="background-color:{{row.entity.colourInfo.rgb}}" item="row.entity" colobject="col">', enableFiltering: false },
  95. ];
  96. $scope.value = 10;
  97. $scope.decrement = function() {
  98. $scope.value = $scope.value - 1;
  99. };
  100. $scope.record = function() {
  101. api_text.record($rootScope.takes).then(function(data) {
  102. if (data.errno == 0) {
  103. $scope.busy = false;
  104. }
  105. })
  106. };
  107. $scope.parameters = null;
  108. $scope.open = function($event) {
  109. $event.preventDefault();
  110. $event.stopPropagation();
  111. $scope.opened = !$scope.opened;
  112. };
  113. $scope.endOpen = function($event) {
  114. $event.preventDefault();
  115. $event.stopPropagation();
  116. $scope.startOpened = false;
  117. $scope.endOpened = !$scope.endOpened;
  118. };
  119. $scope.startOpen = function($event) {
  120. $event.preventDefault();
  121. $event.stopPropagation();
  122. $scope.endOpened = false;
  123. $scope.startOpened = !$scope.startOpened;
  124. };
  125. $scope.othcode = {};
  126. $scope.searchkeys = {};
  127. //状态
  128. $scope.state = [{ id: 1, name: "待处理" }, { id: 2, name: "已处理" }];
  129. // api_bpm_data.fetchDataList('incidentstatus', { "idx": 0, "sum": 100 }).then(function(response) {
  130. // if (response) {
  131. // if (response.status = 200) {
  132. // $scope.state = response.list;
  133. // if (sessionStorage.searchcmdbau && JSON.parse(sessionStorage.getItem("searchcmdbau")).comptroller) {
  134. // angular.forEach($scope.state, function(item) {
  135. // if (item.code == JSON.parse(sessionStorage.getItem("searchcmdbau")).comptroller.statusId) {
  136. // $scope.othcode = { "state": item };
  137. // }
  138. // })
  139. // }
  140. // }
  141. // }
  142. // })
  143. if (sessionStorage.searchcmdbau && JSON.parse(sessionStorage.getItem("searchcmdbau")).comptroller) {
  144. if (JSON.parse(sessionStorage.getItem("searchcmdbau")).comptroller) {
  145. $scope.searchkeys = JSON.parse(sessionStorage.getItem("searchcmdbau")).comptroller;
  146. }
  147. if ($scope.searchkeys.startDate) {
  148. $scope.searchkeys.startDate = new Date($scope.searchkeys.startDate);
  149. }
  150. if ($scope.searchkeys.endDate) {
  151. $scope.searchkeys.endDate = new Date($scope.searchkeys.endDate);
  152. }
  153. }
  154. //重置
  155. $scope.clear = function() {
  156. $scope.searchkeys = {};
  157. $scope.othcode = {};
  158. var fildata = {
  159. "idx": JSON.parse(sessionStorage.getItem("searchcmdbau")).idx,
  160. "sum": JSON.parse(sessionStorage.getItem("searchcmdbau")).sum
  161. }
  162. sessionStorage.removeItem("searchcmdbau");
  163. $scope.memoryfilterData = fildata;
  164. $scope.refreshData('expand-right', fildata);
  165. }
  166. $scope.chiceIncident = function(item) {
  167. var fildata = {};
  168. if (sessionStorage.searchcmdbau) {
  169. fildata = JSON.parse(sessionStorage.getItem("searchcmdbau"));
  170. $scope.gridOptions.paginationCurrentPage = 1;
  171. fildata.idx = 0;
  172. } else {
  173. fildata = defaultFilterData;
  174. }
  175. // $scope.memoryfilterData = fildata;
  176. if (!fildata.comptroller) {
  177. fildata['comptroller'] = {};
  178. }
  179. if (item.startDate) {
  180. item.startDate = moment(item.startDate).format('YYYY-MM-DD HH:mm:ss');
  181. }
  182. if (item.endDate) {
  183. item.endDate = moment(item.endDate).format('YYYY-MM-DD 23:59:59')
  184. }
  185. var transitiondata = angular.copy(item);
  186. angular.extend(fildata.comptroller, transitiondata)
  187. sessionStorage['searchcmdbau'] = angular.copy(JSON.stringify(fildata));
  188. $scope.memoryfilterData = fildata;
  189. $scope.refreshData('expand-right', fildata);
  190. }
  191. //受理人,处理人
  192. var getUser = function(fieldatas, it) {
  193. api_user_data.fetchDataList('user', fieldatas).then(function(data) {
  194. if (it == 1) {
  195. $scope.acceptUser = data.list;
  196. } else if (it == 2) {
  197. $scope.handlingPersonnelUser = data.list;
  198. // } else if (it == 3) {
  199. // $scope.acceptUser = data.list;
  200. // $scope.handlingPersonnelUser = data.list;
  201. }
  202. });
  203. }
  204. // var fieldata = { "idx": 0, "sum": 10, "flag": -1 };
  205. // getUser(fieldata, 3);
  206. //受理人过滤
  207. $scope.onChangeacceptUser = function(key) {
  208. var filuser = {
  209. "idx": 0,
  210. "sum": 10,
  211. "flag": -1,
  212. "user": { "flag": -1, "name": key }
  213. }
  214. getUser(filuser, 1);
  215. }
  216. //处理人过滤
  217. $scope.onChangehandling = function(key) {
  218. var filuser = {
  219. "idx": 0,
  220. "sum": 10,
  221. "flag": -1,
  222. "user": { "flag": -1, "name": key }
  223. }
  224. getUser(filuser, 2);
  225. }
  226. $scope.starttime = function(data) {
  227. return moment(new Date(data)).format('YYYY-MM-DD')
  228. }
  229. $scope.overtime = function(data) {
  230. return moment(new Date(data)).format('YYYY-MM-DD HH:mm')
  231. }
  232. $scope.gridOptions.onRegisterApi = function(gridApi) {
  233. $scope.gridApi = gridApi;
  234. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  235. var filtersData = $scope.memoryfilterData;
  236. filtersData.idx = newPage - 1;
  237. filtersData.sum = pageSize;
  238. $scope.refreshData('expand-right', filtersData);
  239. });
  240. gridApi.core.on.filterChanged($scope, function() {
  241. var grid = this.grid;
  242. var filtersData = {
  243. "assignee": $rootScope.user.id,
  244. "candidateGroups": $rootScope.user.group[0].id,
  245. idx: 0,
  246. sum: 10
  247. };
  248. angular.forEach(grid.columns, function(item) {
  249. if (item.enableFiltering) {
  250. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  251. // console.log('item.filters[0]='+JSON.stringify(item.filters[0]));
  252. if (angular.isUndefined(filtersData['comptroller'])) {
  253. filtersData['comptroller'] = {};
  254. }
  255. filtersData['comptroller'][item.field] = item.filters[0].term;
  256. }
  257. }
  258. });
  259. $scope.memoryfilterData = filtersData;
  260. $scope.refreshData('expand-right', filtersData);
  261. });
  262. };
  263. //当前人是否分组
  264. if ($rootScope.user.group) {
  265. if ($rootScope.user.group.length == 0) {
  266. SweetAlert.swal("访问失败!", "当前登录人未分配工作组,无权限访问,请添加工作组后重试。", "error");
  267. } else {
  268. $scope.memoryfilterData = defaultFilterData = {
  269. "idx": 0,
  270. "sum": mun
  271. };
  272. }
  273. } else {
  274. $scope.memoryfilterData = defaultFilterData = {
  275. "idx": 0,
  276. "sum": mun
  277. };
  278. }
  279. //编辑
  280. $scope.selectRowFunction = function(data) {
  281. $state.go('app.means.auditeditor', { model: JSON.stringify(data) });
  282. };
  283. //查看
  284. $scope.onDblClick = function(data) {
  285. data.entity.look = true;
  286. $state.go('app.means.auditeditor', { model: JSON.stringify(data.entity) });
  287. };
  288. //新增
  289. $scope.newaudit = function() {
  290. $state.go('app.means.newaudit', {});
  291. };
  292. //删除
  293. $scope.eventDeleted = function(event) {
  294. SweetAlert.swal({
  295. title: "确认删除?",
  296. text: "删除的数据不可恢复,请确认继续操作!",
  297. type: "warning",
  298. showCancelButton: true,
  299. confirmButtonColor: "#DD6B55",
  300. confirmButtonText: "继续删除",
  301. cancelButtonText: "取消操作",
  302. closeOnConfirm: false,
  303. closeOnCancel: false
  304. }, function(isConfirm) {
  305. if (isConfirm) {
  306. api_bpm_schedule.remove([event.id]).then(function(response) {
  307. if (response.status == 200) {
  308. $scope.events.splice(event.id, 1); //有修改的一行
  309. SweetAlert.swal("操作成功!", "数据已经被删除.", "success");
  310. } else {
  311. SweetAlert.swal("操作失败!", "数据暂时无法被删除,请稍候重试", "error");
  312. }
  313. });
  314. } else {
  315. SweetAlert.swal("操作取消", "数据安全", "error");
  316. }
  317. });
  318. };
  319. if ($stateParams.model) {
  320. if (JSON.parse($stateParams.model).searchType && JSON.parse($stateParams.model).searchType != null) {
  321. $scope.searchTypes = JSON.parse($stateParams.model).searchType;
  322. } else {
  323. $scope.searchTypes = "todo";
  324. }
  325. } else {
  326. $scope.searchTypes = "todo";
  327. }
  328. if ($rootScope.user.group) {
  329. var defaultFilterData = {
  330. "idx": 0,
  331. "sum": mun
  332. };
  333. } else {
  334. var defaultFilterData = {
  335. "idx": 0,
  336. "sum": mun
  337. };
  338. }
  339. // var defaultFilterData = {
  340. // "assignee":$rootScope.user.id,
  341. // "candidateGroups":$rootScope.user.group[0].id,
  342. // "idx":0,
  343. // "sum":mun
  344. // };
  345. if (angular.isDefined($rootScope.search) && angular.isDefined($rootScope.search.comptroller)) {
  346. defaultFilterData['searchType'] = $rootScope.search.comptroller;
  347. $scope.searchTypes = $rootScope.search.comptroller;
  348. }
  349. // if ($rootScope['cmdbs'] != 'incident') { $rootScope.idx = 1 }
  350. // if (angular.isDefined($rootScope.idx) && $rootScope.cmdbs != "false") {
  351. // $rootScope['cmdbs'] = 'incident';
  352. // defaultFilterData.idx = $rootScope.idx - 1;
  353. // } else { $rootScope.cmdbs = ""; }
  354. $scope.ldloading = {};
  355. // $scope.Change= function(upTypes){
  356. // if(angular.isDefined(upTypes)&&upTypes=='upincident'){
  357. // $state.go('app.problem.incident',{});
  358. // }
  359. // else if(angular.isDefined(upTypes)&&upTypes=='upchange'){
  360. // $state.go('app.change.incident',{});
  361. // }
  362. // }
  363. //事件类型筛选
  364. $scope.onChange = function(searchType) {
  365. defaultFilterData = $scope.memoryfilterData;
  366. defaultFilterData['searchType'] = searchType;
  367. $scope.refreshData('expand-right', defaultFilterData);
  368. }
  369. //获取列表数据
  370. $scope.refreshData = function(style, filterData) {
  371. $scope.ldloading[style.replace('-', '_')] = true;
  372. if (angular.isUndefined(filterData)) {
  373. if (sessionStorage.searchcmdbau) {
  374. filterData = JSON.parse(sessionStorage.getItem("searchcmdbau"));
  375. $scope.gridOptions.paginationCurrentPage = 1 + filterData.idx;
  376. } else {
  377. filterData = defaultFilterData;
  378. }
  379. }
  380. $scope.myData = [];
  381. sessionStorage['searchcmdbau'] = angular.copy(JSON.stringify(filterData));
  382. $scope.memoryfilterData = filterData;
  383. $scope.gridOptions['sum'] = filterData.sum;
  384. if (filterData.comptroller && filterData.comptroller.status) {
  385. if (filterData.comptroller.status.id == 1) {
  386. filterData.comptroller.status = 1;
  387. } else if (filterData.comptroller.status.id == 2) {
  388. filterData.comptroller.status = 2;
  389. }
  390. }
  391. api_bpm.fetchDataList('comptroller', filterData).then(function(data) {
  392. if (data.status == 200) {
  393. var myData = Restangular.stripRestangular(data);
  394. var list = [];
  395. $scope.gridOptions['totalItems'] = myData.totalNum;
  396. $scope.myData = myData.list;
  397. for (var i = 0; i < $scope.myData.length; i++) {
  398. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  399. }
  400. } else {
  401. SweetAlert.swal({
  402. title: "系统错误",
  403. text: "请稍后再试!",
  404. type: "error"
  405. });
  406. }
  407. $scope.ldloading[style.replace('-', '_')] = false;
  408. }, function() {
  409. $scope.ldloading[style.replace('-', '_')] = false;
  410. });
  411. };
  412. $scope.refreshData('expand-right');
  413. }]);
  414. //操作按钮权限控制
  415. app.controller('CmdblistOperCtrl', ['$rootScope', '$http', '$scope', '$modal', function($rootScope, $http, $scope, $modal) {
  416. if ($scope.item.status != null) {
  417. if ($scope.item.status == 1 && $scope.item.user.id == $rootScope.user.id) {
  418. $scope.item.chaozuoPower = true;
  419. } else {
  420. $scope.item.chaozuoPower = false;
  421. }
  422. }
  423. $scope.look = function() {
  424. //$state.go('app.detail', { formKey:'incident_back', pdKey:'incident', dataId: $scope.item.id});
  425. $scope.colobject.grid.appScope.lookFunction($scope.item);
  426. }
  427. $scope.edit = function() {
  428. $scope.colobject.grid.appScope.selectRowFunction($scope.item);
  429. }
  430. // $scope.handler = function() {
  431. // $scope.colobject.grid.appScope.acceptTaskAction($scope.item);
  432. // $scope.doComment($scope.item.id);
  433. // }
  434. }]);
  435. //操作按钮
  436. app.directive('cmdblistoperator', function() {
  437. return {
  438. restrict: 'E',
  439. scope: {
  440. item: '=',
  441. colobject: '='
  442. },
  443. controller: 'CmdblistOperCtrl',
  444. template: '<div><div class="cl-effect-1 ui-grid-cell-contents center" >' +
  445. // '<a ng-click="changeCenter()" ng-show="{{item.xiugai}}" class="luyinfont">修改</a>' +
  446. '<a ng-click="edit()" ng-show="{{item.chaozuoPower}}" class="bianjifont">处理</a>' +
  447. '</div></div>'
  448. };
  449. });