cmdbauditeditorCtrl.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. 'use strict';
  2. app.controller('cmdbauditeditorCtrl', ["$scope", "$http", "$filter", "i18nService", "$rootScope", "$state", "$timeout", "moment", "$interval", "$modal", "$stateParams", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", "api_text", "api_bpm_data", "api_user_data", "api_bpm", function($scope, $http, $filter, i18nService, $rootScope, $state, $timeout, moment, $interval, $modal, $stateParams, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain, api_text, api_bpm_data, api_user_data, api_bpm) {
  3. $scope.langs = i18nService.getAllLangs();
  4. $scope.lang = 'zh-cn';
  5. i18nService.setCurrentLang($scope.lang);
  6. $scope.myData = [];
  7. $scope.model = {};
  8. var loginUser = $rootScope.user;
  9. var pdKey = $state.current.pdKey;
  10. $scope.lookright = false;
  11. //时间
  12. if ($stateParams.model) {
  13. $scope.model = JSON.parse($stateParams.model);
  14. $scope.lookright = $scope.model.look;
  15. }
  16. // $scope.model.time = moment(new Date()).format('YYYY-MM-DD');
  17. $scope.mindata = new Date();
  18. $scope.endOpen = true;
  19. $scope.datepicker = {};
  20. $scope.datepicker.opened = false;
  21. $scope.datepicker.open = function($event) {
  22. $scope.datepicker.opened = true;
  23. };
  24. $scope.options = { 'key': "time" }
  25. $scope.datepickerPopup = "yyyy-MM-dd HH:mm:ss";
  26. $scope.width = { 'width': document.getElementById("formtow").scrollWidth };
  27. window.onresize = function() {
  28. if (document.getElementById("form")) {
  29. $scope.width = { 'width': document.getElementById("formtow").scrollWidth };
  30. }
  31. }
  32. $scope.transferdifferenceStatus = function(item) {
  33. var statecolor = "有差异";
  34. if (item == 1) {
  35. statecolor = "有差异";
  36. } else if (item == 2) {
  37. statecolor = "无差异";
  38. }
  39. return statecolor;
  40. }
  41. $scope.transferstatus = function(item) {
  42. var statecolor = "未处理";
  43. if (item == 1) { //待处理
  44. statecolor = "发起变更";
  45. } else if (item == 2) { //已处理
  46. statecolor = "忽略";
  47. } else if (item == 3) { //已处理
  48. statecolor = "无需处理";
  49. } else if (item == 4) { //已处理
  50. statecolor = "未处理";
  51. }
  52. return statecolor;
  53. }
  54. $scope.gridOptions = {};
  55. $scope.gridOptions.data = 'myData';
  56. $scope.gridOptions.enableColumnResizing = true;
  57. $scope.gridOptions.enableFiltering = false;
  58. $scope.gridOptions.enableGridMenu = false;
  59. $scope.gridOptions.enableSelectAll = true;
  60. $scope.gridOptions.enableRowSelection = true;
  61. $scope.gridOptions.showGridFooter = true;
  62. $scope.gridOptions.showColumnFooter = false;
  63. $scope.gridOptions.fastWatch = true;
  64. $scope.gridOptions.enableSorting = true;
  65. $scope.gridOptions.useExternalSorting = true;
  66. $scope.gridOptions.useExternalFiltering = false;
  67. $scope.gridOptions.useExternalPagination = true;
  68. $scope.gridOptions.paginationPageSizes = [1000];
  69. $scope.gridOptions.paginationPageSize = 1000;
  70. $scope.gridOptions.multiSelect = true;
  71. // $scope.gridOptions.rowTemplate = "<div ng-dblclick=\"grid.appScope.pdList.onDblClick(row,$event)\" 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>";
  72. $scope.gridOptions.columnDefs = [
  73. { name: 'item', displayName: '序号', width: 50 },
  74. { name: 'assetId', displayName: '配置项ID', width: 150, enableFiltering: false },
  75. { name: 'assetName', displayName: '配置项名称', width: 100, enableFiltering: false },
  76. {
  77. name: 'differenceStatus',
  78. displayName: '是否有差异',
  79. enableFiltering: false,
  80. width: 100,
  81. cellTemplate: '<div>' +
  82. '<div class="ui-grid-cell-contents">{{grid.appScope.transferdifferenceStatus(row.entity.differenceStatus)}}</div>' +
  83. '</div>'
  84. },
  85. { name: 'changeOrder', width: 150, displayName: '变更单号', enableFiltering: false },
  86. {
  87. name: 'status',
  88. displayName: '处理方式',
  89. enableFiltering: false,
  90. width: 100,
  91. cellTemplate: '<div>' +
  92. '<div class="ui-grid-cell-contents">{{grid.appScope.transferstatus(row.entity.status)}}</div>' +
  93. '</div>'
  94. },
  95. {
  96. name: '操作',
  97. enableSorting: false,
  98. cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents center" >' +
  99. '<a ng-click="grid.appScope.lookFunction(row.entity)" class="bianjifont">对比详情</a>' +
  100. '<a ng-click="grid.appScope.selectRowFunction(row.entity)" ng-show="{{row.entity.status==4&&row.entity.differenceStatus==1&&!grid.appScope.lookright}}" class="bianjifont">发起变更</a>' +
  101. '<a ng-click="grid.appScope.ignore(row.entity)" ng-show="{{row.entity.status==4&&row.entity.differenceStatus==1&&!grid.appScope.lookright}}" class="bianjifont">忽略</a>' +
  102. '</div></div>'
  103. }
  104. ];
  105. $scope.myDatalingbeiall = [];
  106. $scope.memoryfilterDatashe = {
  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. // $scope.loadData(filtersData);
  115. $scope.memoryfilterDatashe.idx = newPage - 1;
  116. $scope.memoryfilterDatashe.sum = pageSize;
  117. $scope.myDatalingbei = $scope.interceptMydata($scope.myDatalingbeiall, $scope.memoryfilterDatashe.idx, 10)
  118. });
  119. // gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  120. // $scope.selected.items = data.entity;
  121. // //console.log(data);
  122. // });
  123. // gridApi.selection.on.rowSelectionChangedBatch($scope, function(data) {
  124. // $scope.selected.items = data.entity;
  125. // //console.log(data);
  126. // });
  127. // gridApi.core.on.filterChanged($scope, function() {
  128. // var grid = this.grid;
  129. // var filtersData = {
  130. // idx: 0,
  131. // sum: 20,
  132. // "user": { "roledata": { "rolecode": "roleset" }, "selectType": "1" }
  133. // };
  134. // angular.forEach(grid.columns, function(item) {
  135. // if (item.enableFiltering) {
  136. // // console.log("item.filters[0]=" + JSON.stringify(item.filters));
  137. // if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  138. // if (angular.isUndefined(filtersData['user'])) {
  139. // filtersData['user'] = {};
  140. // }
  141. // filtersData['user'][item.field] = item.filters[0].term;
  142. // }
  143. // }
  144. // });
  145. // $scope.memoryfilterDatashe = filtersData;
  146. // // $scope.loadData(filtersData);
  147. // });
  148. };
  149. //管理员
  150. $scope.audituser = [];
  151. var fieldatas = { "idx": 0, "sum": 1000, "user": { "roledata": { "rolecode": "3ff5dd43-0a0b-44d9-a36e-2b5417f41242" }, "selectType": "1" } }
  152. api_user_data.fetchDataList('user', fieldatas).then(function(data) {
  153. if (data.status == 200) {
  154. $scope.audituser = data.list;
  155. }
  156. });
  157. //单号
  158. // var fieldatas = { "idx": 0, "sum": 1000, "user": { "roledata": { "rolecode": "change petitor" }, "selectType": "1" } }
  159. // api_bpm_domain.workernumber('PZSJ').then(function(data) {
  160. // if (data.status == 200) {
  161. // $scope.model.orderId = data.data;
  162. // }
  163. // });
  164. $scope.interceptMydata = function(mydate, idx, sum) {
  165. return mydate.slice(idx * sum, (idx + 1) * sum)
  166. }
  167. $scope.removeshebei = function(item) {
  168. event.preventDefault();
  169. var modalInstance = $modal.open({
  170. templateUrl: 'assets/views/delete.html',
  171. controller: function($scope, $modalInstance, scope) {
  172. $scope.title = '设备移除';
  173. $scope.connect = '确定要移除此设备?';
  174. $scope.consumptive = scope.selected.items;
  175. $scope.ok = function() {
  176. $modalInstance.close($scope.consumptive);
  177. };
  178. $scope.cancel = function() {
  179. $modalInstance.dismiss('cancel');
  180. };
  181. },
  182. size: 'sm',
  183. resolve: {
  184. scope: function() {
  185. return $scope;
  186. },
  187. }
  188. });
  189. modalInstance.result.then(function(selectedItem) {
  190. angular.forEach($scope.myDatalingbeiall, function(items, index) {
  191. if (items.id == selectedItem.id) {
  192. $scope.myDatalingbeiall.splice(index, 1);
  193. }
  194. })
  195. // $scope.myData3.push(selectedItem);
  196. $scope.model.comptrollerAssets = $scope.myDatalingbeiall;
  197. $scope.gridOptions['totalItems'] = $scope.myDatalingbeiall.length;
  198. for (var i = 0; i < $scope.myDatalingbeiall.length; i++) {
  199. $scope.myDatalingbeiall[i]['item'] = i + 1 + $scope.memoryfilterDatashe.idx * $scope.memoryfilterDatashe.sum
  200. }
  201. $scope.myDatalingbei = $scope.interceptMydata($scope.myDatalingbeiall, 0, 10)
  202. })
  203. }
  204. // $scope.onDblClick = function(data, event) {
  205. // $scope.selectButtonClick(data, event);
  206. // };
  207. //对比
  208. $scope.lookFunction = function(data) {
  209. // $state.go('app.means.cmdbcontrast', { model: JSON.stringify(data) });
  210. var url = $state.href('cmdbcontrast', { model: JSON.stringify(data) });
  211. window.open(url, '_blank');
  212. // if ($scope.lookright) {
  213. // $state.go('app.means.cmdbcontrast', { key: 1, model: JSON.stringify(data) });
  214. // } else {
  215. // $state.go('app.means.cmdbcontrast', { key: 2, model: JSON.stringify(data) });
  216. // }
  217. };
  218. //发起变更
  219. $scope.selectRowFunction = function(item) {
  220. var data = {
  221. "model": { change: { source: { id: 88 }, title: item.assetName, description: item.assetName }, cmdbId: item.id }
  222. }
  223. $state.go('app.change.incident', { 'key': 1, 'model': JSON.stringify(data) });
  224. }
  225. //关闭
  226. $scope.closeModel = function() {
  227. $state.go('app.means.auditlist', {});
  228. }
  229. //忽略
  230. $scope.ignore = function(data) {
  231. var modalInstance = $modal.open({
  232. templateUrl: 'assets/views/delete.html',
  233. controller: function($scope, $modalInstance, scope) {
  234. $scope.title = '提示';
  235. $scope.connect = '忽略后,将不再显示,是否确定忽略?';
  236. $scope.ok = function() {
  237. $modalInstance.close(data);
  238. };
  239. $scope.cancel = function() {
  240. $modalInstance.dismiss('cancel');
  241. };
  242. },
  243. size: 'sm',
  244. resolve: {
  245. scope: function() {
  246. return $scope;
  247. },
  248. }
  249. });
  250. modalInstance.result.then(function(selectedItem) {
  251. angular.forEach($scope.myData, function(items, index) {
  252. if (items.id == selectedItem.id) {
  253. $scope.myData[index].status = 2;
  254. }
  255. })
  256. })
  257. };
  258. var defaultdata = {
  259. "comptroller": {
  260. "id": $scope.model.id
  261. }
  262. }
  263. var defaultdatatwo = {
  264. "comptroller": {
  265. "orderId": $scope.model.orderId
  266. }
  267. }
  268. $scope.ldloading = {};
  269. $scope.refreshData = function(filterData) {
  270. $scope.ldloading.zoom_in = true;
  271. defaultdatatwo.idx = 0; //idx: 0
  272. defaultdatatwo.sum = 100; //sum: 10
  273. if ($scope.lookright) {
  274. api_bpm.fetchDataList('comptroller', defaultdatatwo).then(function(data) {
  275. $scope.model = Restangular.stripRestangular(data).list[0];
  276. $scope.myData = $scope.model.comptrollerAssets;
  277. $scope.gridOptions['totalItems'] = $scope.myData.length;
  278. for (var i = 0; i < $scope.myData.length; i++) {
  279. $scope.myData[i]['item'] = i + 1
  280. }
  281. $scope.ldloading.zoom_in = false;
  282. }, function() {});
  283. } else {
  284. api_bpm.updData('comptroller', filterData).then(function(data) {
  285. // var filterData = $scope.memoryfilterDatashe;
  286. $scope.model = Restangular.stripRestangular(data).data;
  287. $scope.myData = $scope.model.comptrollerAssets;
  288. $scope.gridOptions['totalItems'] = $scope.myData.length;
  289. for (var i = 0; i < $scope.myData.length; i++) {
  290. $scope.myData[i]['item'] = i + 1;
  291. }
  292. $scope.ldloading.zoom_in = false;
  293. }, function() {});
  294. }
  295. };
  296. $scope.refreshData(defaultdata);
  297. $scope.tworeash = function() {
  298. $scope.ldloading.zoom_in = true;
  299. $scope.refreshData(defaultdata);
  300. }
  301. //提交
  302. $scope.isvailu = true;
  303. $scope.changesubmit = function(data) {
  304. $scope.isvailu = true;
  305. angular.forEach(data.comptrollerAssets, function(item) {
  306. if (item.status == 4 && item.differenceStatus == 1) {
  307. $scope.isvailu = false;
  308. }
  309. })
  310. if ($scope.isvailu) {
  311. $rootScope.loading = true;
  312. if (!data.user || data.user == "") {
  313. $rootScope.loading = false;
  314. SweetAlert.swal({
  315. title: "提交失败",
  316. text: "审计管理员!",
  317. type: "error"
  318. });
  319. } else {
  320. if (!data.time || data.time == "") {
  321. $rootScope.loading = false;
  322. SweetAlert.swal({
  323. title: "提交失败",
  324. text: "审计日期!",
  325. type: "error"
  326. });
  327. } else {
  328. if (!data.comptrollerAssets || data.comptrollerAssets == "") {
  329. $rootScope.loading = false;
  330. SweetAlert.swal({
  331. title: "提交失败",
  332. text: "配置项未填!",
  333. type: "error"
  334. });
  335. } else {
  336. var filterData = { 'comptroller': data };
  337. // moment(filterData.time).format('YYYY-MM-DD hh:mm:ss');
  338. filterData.comptroller.status = 2;
  339. // api_bpm.addData('comptroller', filterData).then(function(data) {
  340. api_bpm.updData('comptroller', filterData).then(function(data) {
  341. if (data.status == 200) {
  342. SweetAlert.swal({
  343. title: "保存成功!",
  344. type: "success",
  345. confirmButtonColor: "#007AFF"
  346. }, function() {
  347. $rootScope.loading = false;
  348. $state.go("app.means.auditlist");
  349. });
  350. } else {
  351. $rootScope.loading = false;
  352. SweetAlert.swal({
  353. title: "系统错误",
  354. text: "请稍后再试!",
  355. type: "error"
  356. });
  357. }
  358. // $scope.ldloading[style.replace('-', '_')] = false;
  359. }, function() {
  360. // $scope.ldloading[style.replace('-', '_')] = false;
  361. });
  362. }
  363. }
  364. }
  365. } else {
  366. SweetAlert.swal({
  367. title: "提交失败",
  368. text: "请处理完全部数据!",
  369. type: "error"
  370. });
  371. }
  372. }
  373. }])
  374. //操作按钮权限控制
  375. app.controller('CmdbauditOperCtrl', ['$rootScope', '$http', '$scope', '$modal', function($rootScope, $http, $scope, $modal) {
  376. if ($scope.item.status != null) {
  377. if ($scope.item.status == 4) {
  378. $scope.item.chaozuoPower = true;
  379. }
  380. }
  381. $scope.$watch($scope.item.status, function() {
  382. console.log($scope.myData)
  383. })
  384. $scope.look = function() {
  385. //$state.go('app.detail', { formKey:'incident_back', pdKey:'incident', dataId: $scope.item.id});
  386. $scope.colobject.grid.appScope.lookFunction($scope.item);
  387. }
  388. $scope.edit = function() {
  389. $scope.colobject.grid.appScope.selectRowFunction($scope.item);
  390. }
  391. $scope.handler = function() {
  392. $scope.colobject.grid.appScope.ignore($scope.item);
  393. $scope.doEdit($scope.item.status);
  394. }
  395. }]);
  396. //操作按钮
  397. app.directive('cmdbauditoperator', function() {
  398. return {
  399. restrict: 'E',
  400. scope: {
  401. item: '=',
  402. colobject: '='
  403. },
  404. controller: 'CmdbauditOperCtrl',
  405. template: '<div><div class="cl-effect-1 ui-grid-cell-contents center" >' +
  406. '<a ng-click="look()" class="bianjifont">对比详情</a>' +
  407. '<a ng-click="edit()" ng-show="{{item.chaozuoPower}}" class="bianjifont">发起变更</a>' +
  408. '<a ng-click="handler()" ng-show="{{item.chaozuoPower}}" class="bianjifont">忽略</a>' +
  409. '</div></div>'
  410. };
  411. });