gdzc_historyCtrl.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. 'use strict';
  2. app.controller('gdzc_historyCtrl', ["$scope", "$http", "i18nService", "$rootScope", "$state", "$timeout", "moment", "$interval", "$modal", "$stateParams", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", "api_text", "api_bpm_data", "api_user_data", "api_cmdb", "api_cmdb2", "api_cmdb3", "api_cmdb4", function($scope, $http, i18nService, $rootScope, $state, $timeout, moment, $interval, $modal, $stateParams, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain, api_text, api_bpm_data, api_user_data, api_cmdb, api_cmdb2, api_cmdb3, api_cmdb4) {
  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 pdKey = $state.current.pdKey;
  9. $scope.gridOptions = {};
  10. $scope.gridOptions.data = 'myData';
  11. $scope.gridOptions.enableColumnResizing = true;
  12. $scope.gridOptions.enableFiltering = false;
  13. $scope.gridOptions.enableGridMenu = false;
  14. $scope.gridOptions.enableSelectAll = true;
  15. $scope.gridOptions.enableRowSelection = true;
  16. $scope.gridOptions.showGridFooter = true;
  17. $scope.gridOptions.showColumnFooter = false;
  18. $scope.gridOptions.fastWatch = true;
  19. $scope.gridOptions.enableSorting = true;
  20. $scope.gridOptions.useExternalSorting = true;
  21. $scope.gridOptions.useExternalFiltering = false;
  22. $scope.gridOptions.useExternalPagination = true;
  23. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  24. $scope.gridOptions.paginationPageSize = 10;
  25. $scope.gridOptions.multiSelect = true;
  26. var mun = $scope.gridOptions.paginationPageSize;
  27. $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>";
  28. $scope.gridOptions.rowIdentity = function(row) {
  29. return row.id;
  30. };
  31. $scope.gridOptions.getRowIdentity = function(row) {
  32. return row.id;
  33. };
  34. $scope.transferColor = function(item) {
  35. var color = "icon iconfont icon-zhengchang greenfont";
  36. if (item.colourInfo) {
  37. if (item.colourInfo.id == 1) {
  38. color = "icon iconfont icon-yiyuqi redfont";
  39. } else if (item.colourInfo.id == 2) {
  40. color = "iconfont icon-yuqixinxiu yellofont";
  41. }
  42. } else {
  43. // color = "white";
  44. }
  45. return color;
  46. }
  47. $scope.transfertip = function(item) {
  48. var tip = "正常";
  49. if (item.colourInfo) {
  50. if (item.colourInfo.id == 1) {
  51. tip = "逾期";
  52. } else if (item.colourInfo.id == 2) {
  53. tip = "即将逾期";
  54. }
  55. } else {
  56. // color = "white";
  57. }
  58. return tip;
  59. }
  60. $scope.transferstatus = function(item) {
  61. var statecolor = "#fc4c58";
  62. if (item.id == 2) { //待处理
  63. statecolor = "#fc4c58";
  64. } else if (item.id == 7) { //待审核
  65. statecolor = "#fcb44c";
  66. } else if (item.id == 3) { //请求重新指派
  67. statecolor = "#ebf902";
  68. } else if (item.id == 4) { //处理中
  69. statecolor = "#0aa5f5";
  70. } else if (item.id == 5) { //已解决
  71. statecolor = "#2edbb8";
  72. } else if (item.id == 6) { //已关闭
  73. statecolor = "#bbbbbb";
  74. }
  75. return statecolor;
  76. }
  77. $scope.gridOptions.columnDefs = [{
  78. name: 'versionNumber',
  79. displayName: '版本',
  80. width: '14%',
  81. cellTemplate: '<div>' +
  82. '<div class="ui-grid-cell-contents">{{row.entity.versionNumber}}</div>' +
  83. '</div>'
  84. },
  85. {
  86. name: 'name',
  87. displayName: '操作人',
  88. width: '13%',
  89. cellTemplate: '<div>' +
  90. '<div class="ui-grid-cell-contents">{{row.entity.operator.name}}</div>' +
  91. '</div>'
  92. },
  93. {
  94. name: 'time',
  95. displayName: '操作时间',
  96. width: '20%',
  97. cellTemplate: '<div>' +
  98. '<div class="ui-grid-cell-contents">{{row.entity.time}}</div>' +
  99. '</div>'
  100. },
  101. {
  102. name: 'motion',
  103. displayName: '操作动作',
  104. width: '13%',
  105. cellTemplate: '<div>' +
  106. '<div class="ui-grid-cell-contents">{{row.entity.motion}}</div>' +
  107. '</div>'
  108. }, {
  109. name: 'description',
  110. displayName: '内容',
  111. width: '40%',
  112. cellTemplate: '<div>' +
  113. '<div class="ui-grid-cell-contents" tooltip={{row.entity.description}} ng-if="row.entity.description&&row.entity.description.length>23" tooltip-placement="bottom">{{row.entity.description}}</div><div class="ui-grid-cell-contents" ng-if="row.entity.description&&row.entity.description.length<=23" >{{row.entity.description}}</div>' +
  114. '</div>'
  115. }
  116. ];
  117. $scope.value = 10;
  118. $scope.decrement = function() {
  119. $scope.value = $scope.value - 1;
  120. };
  121. $scope.record = function() {
  122. api_text.record($rootScope.takes).then(function(data) {
  123. if (data.errno == 0) {
  124. $scope.busy = false;
  125. }
  126. })
  127. };
  128. $scope.parameters = null;
  129. $scope.open = function($event) {
  130. $event.preventDefault();
  131. $event.stopPropagation();
  132. $scope.opened = !$scope.opened;
  133. };
  134. $scope.endOpen = function($event) {
  135. $event.preventDefault();
  136. $event.stopPropagation();
  137. $scope.startOpened = false;
  138. $scope.endOpened = !$scope.endOpened;
  139. };
  140. $scope.startOpen = function($event) {
  141. $event.preventDefault();
  142. $event.stopPropagation();
  143. $scope.endOpened = false;
  144. $scope.startOpened = !$scope.startOpened;
  145. };
  146. $scope.othcode = {};
  147. var items = [];
  148. $scope.selected = {
  149. items: []
  150. };
  151. var wt_data = {};
  152. //列表排序
  153. $scope.gridOptions.onRegisterApi = function(gridApi) {
  154. $scope.gridApi = gridApi;
  155. var index = 0;
  156. var oldheader = {};
  157. gridApi.grid.sortColumn = function(gridApi) {
  158. if (oldheader.field) {
  159. if (oldheader.field == gridApi.field) {
  160. // index = 0;
  161. } else {
  162. index = 0;
  163. }
  164. }
  165. index++;
  166. oldheader = gridApi;
  167. var fildata = $scope.memoryfilterData;
  168. if (index % 3 == 0) {
  169. delete $scope.memoryfilterData.incident;
  170. fildata = $scope.memoryfilterData;
  171. } else if (index % 3 == 1) {
  172. if (fildata.incident) {
  173. if (gridApi.field == "acceptDate") {
  174. angular.extend(fildata.incident, { "sort": gridApi.field });
  175. } else {
  176. angular.extend(fildata.incident, { "sort": gridApi.field + " desc , _incident.acceptDate" });
  177. }
  178. } else {
  179. if (gridApi.field == "acceptDate") {
  180. angular.extend(fildata, { 'incident': { "sort": gridApi.field } });
  181. } else {
  182. angular.extend(fildata, { 'incident': { "sort": gridApi.field + " desc , _incident.acceptDate" } });
  183. }
  184. }
  185. } else if (index % 3 == 2) {
  186. if (fildata.incident) {
  187. if (gridApi.field == "acceptDate") {
  188. angular.extend(fildata.incident, { "sort": gridApi.field, "order": "asc" });
  189. } else {
  190. angular.extend(fildata.incident, { "sort": gridApi.field + " asc , _incident.acceptDate" });
  191. }
  192. } else {
  193. if (gridApi.field == "acceptDate") {
  194. angular.extend(fildata, { 'incident': { "sort": gridApi.field, "order": "asc" } });
  195. } else {
  196. angular.extend(fildata.incident, { "sort": gridApi.field + " asc , _incident.acceptDate" });
  197. }
  198. }
  199. // angular.extend(fildata, { 'incident': { "sort": gridApi.field, "order": "asc" } });
  200. }
  201. $scope.refreshData('expand-right', fildata);
  202. }
  203. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  204. var filtersData = $scope.memoryfilterData;
  205. filtersData.idx = newPage - 1;
  206. filtersData.sum = pageSize;
  207. $scope.refreshData('expand-right', filtersData);
  208. });
  209. gridApi.core.on.filterChanged($scope, function() {
  210. var grid = this.grid;
  211. if ($rootScope.user.group) {
  212. var filtersData = {
  213. idx: 0,
  214. sum: mun
  215. };
  216. } else {
  217. var filtersData = {
  218. idx: 0,
  219. sum: mun
  220. };
  221. }
  222. angular.forEach(grid.columns, function(item) {
  223. if (item.enableFiltering) {
  224. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  225. filtersData = $scope.memoryfilterData
  226. if (angular.isUndefined(filtersData['incident'])) {
  227. filtersData['incident'] = {};
  228. }
  229. if (item.field == 'requester.name') {
  230. filtersData['incident']['requester'] = {};
  231. filtersData.incident.requester['accountName'] = item.filters[0].term;
  232. } else if (item.field == 'handlingPersonnelUser.name') {
  233. filtersData['incident']['handlingPersonnelUser'] = {};
  234. filtersData.incident.handlingPersonnelUser['name'] = item.filters[0].term;
  235. } else if (item.field == 'requester.account') {
  236. filtersData['incident']['requester'] = {};
  237. filtersData.incident.requester['account'] = item.filters[0].term;
  238. } else if (item.field == 'acceptUser.name') {
  239. filtersData['incident']['acceptUser'] = {};
  240. filtersData.incident.acceptUser['name'] = item.filters[0].term;
  241. } else {
  242. filtersData['incident'][item.field] = item.filters[0].term;
  243. }
  244. }
  245. }
  246. });
  247. filtersData.idx = 0;
  248. $scope.memoryfilterData = filtersData;
  249. $scope.refreshData('expand-right', filtersData);
  250. });
  251. };
  252. //当前人是否分组
  253. if ($rootScope.user.group) {
  254. if ($rootScope.user.group.length == 0) {
  255. SweetAlert.swal("访问失败!", "当前登录人未分配工作组,无权限访问,请添加工作组后重试。", "error");
  256. } else {
  257. $scope.memoryfilterData = defaultFilterData = {
  258. "idx": 0,
  259. "sum": mun
  260. };
  261. }
  262. } else {
  263. $scope.memoryfilterData = defaultFilterData = {
  264. "idx": 0,
  265. "sum": mun
  266. };
  267. };
  268. var items = [];
  269. if ($stateParams.model) {
  270. if (JSON.parse($stateParams.model).searchType && JSON.parse($stateParams.model).searchType != null) {
  271. $scope.searchTypes = JSON.parse($stateParams.model).searchType;
  272. } else {
  273. $scope.searchTypes = "todo";
  274. }
  275. } else {
  276. $scope.searchTypes = "todo";
  277. }
  278. if ($rootScope.user.group) {
  279. var defaultFilterData = {
  280. "idx": 0,
  281. "sum": mun
  282. };
  283. } else {
  284. var defaultFilterData = {
  285. "idx": 0,
  286. "sum": mun
  287. };
  288. }
  289. if (angular.isDefined($rootScope.search) && angular.isDefined($rootScope.search.incident)) {
  290. defaultFilterData['searchType'] = $rootScope.search.incident;
  291. $scope.searchTypes = $rootScope.search.incident;
  292. }
  293. if ($rootScope['cmdbs'] != 'incident') { $rootScope.idx = 1 }
  294. if (angular.isDefined($rootScope.idx) && $rootScope.cmdbs != "false") {
  295. $rootScope['cmdbs'] = 'incident';
  296. defaultFilterData.idx = $rootScope.idx - 1;
  297. } else { $rootScope.cmdbs = ""; }
  298. $scope.ldloading = {};
  299. // console.log($stateParams.idd)
  300. //获取列表数据
  301. $scope.refreshData = function(style, filterData) {
  302. var pdKey = "assetConsumablesHistory";
  303. $scope.myData = [];
  304. $scope.gridOptions['sum'] = filterData.sum;
  305. filterData['assetConsumablesHistory'] = { "assetConsumablesId": $stateParams.idd };
  306. api_cmdb3.fetchDataList(pdKey, filterData).then(function(data) {
  307. // console.log(data.list);
  308. if (data.list) {
  309. var myData = Restangular.stripRestangular(data);
  310. var list = [];
  311. $scope.gridOptions['totalItems'] = myData.totalNum;
  312. $scope.myData = myData.list;
  313. // console.log($scope.myData);
  314. for (var i = 0; i < $scope.myData.length; i++) {
  315. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  316. }
  317. } else {
  318. SweetAlert.swal({
  319. title: "系统错误",
  320. text: "请稍后再试!",
  321. type: "error"
  322. });
  323. }
  324. $scope.ldloading[style.replace('-', '_')] = false;
  325. }, function() {
  326. $scope.ldloading[style.replace('-', '_')] = false;
  327. });
  328. };
  329. $scope.refreshData('expand-right', defaultFilterData);
  330. }])