historyCtrl.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. 'use strict';
  2. app.controller('hc_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. {
  79. name: 'name',
  80. displayName: '操作人',
  81. width: '25%',
  82. cellTemplate: '<div>' +
  83. '<div class="ui-grid-cell-contents">{{row.entity.operator.name}}</div>' +
  84. '</div>'
  85. },
  86. {
  87. name: 'time',
  88. displayName: '操作时间',
  89. width: '25%',
  90. cellTemplate: '<div>' +
  91. '<div class="ui-grid-cell-contents">{{row.entity.time}}</div>' +
  92. '</div>'
  93. },
  94. {
  95. name: 'motion',
  96. displayName: '操作动作',
  97. width: '25%',
  98. cellTemplate: '<div>' +
  99. '<div class="ui-grid-cell-contents">{{row.entity.motion}}</div>' +
  100. '</div>'
  101. },
  102. {
  103. name: 'consumablesSum',
  104. displayName: '数量',
  105. width: '25%',
  106. cellTemplate: '<div>' +
  107. '<div class="ui-grid-cell-contents">{{row.entity.consumablesSum}}</div>' +
  108. '</div>'
  109. },
  110. ];
  111. $scope.value = 10;
  112. $scope.decrement = function () {
  113. $scope.value = $scope.value - 1;
  114. };
  115. $scope.record = function () {
  116. api_text.record($rootScope.takes).then(function (data) {
  117. if (data.errno == 0) {
  118. $scope.busy = false;
  119. }
  120. })
  121. };
  122. $scope.parameters = null;
  123. $scope.open = function ($event) {
  124. $event.preventDefault();
  125. $event.stopPropagation();
  126. $scope.opened = !$scope.opened;
  127. };
  128. $scope.endOpen = function ($event) {
  129. $event.preventDefault();
  130. $event.stopPropagation();
  131. $scope.startOpened = false;
  132. $scope.endOpened = !$scope.endOpened;
  133. };
  134. $scope.startOpen = function ($event) {
  135. $event.preventDefault();
  136. $event.stopPropagation();
  137. $scope.endOpened = false;
  138. $scope.startOpened = !$scope.startOpened;
  139. };
  140. $scope.othcode = {};
  141. var items=[];
  142. $scope.selected = {
  143. items: []
  144. };
  145. var wt_data={};
  146. //列表排序
  147. $scope.gridOptions.onRegisterApi = function (gridApi) {
  148. $scope.gridApi = gridApi;
  149. var index = 0;
  150. var oldheader = {};
  151. gridApi.grid.sortColumn = function (gridApi) {
  152. if (oldheader.field) {
  153. if (oldheader.field == gridApi.field) {
  154. // index = 0;
  155. } else {
  156. index = 0;
  157. }
  158. }
  159. index++;
  160. oldheader = gridApi;
  161. var fildata = $scope.memoryfilterData;
  162. if (index % 3 == 0) {
  163. delete $scope.memoryfilterData.incident;
  164. fildata = $scope.memoryfilterData;
  165. } else if (index % 3 == 1) {
  166. if (fildata.incident) {
  167. if (gridApi.field == "acceptDate") {
  168. angular.extend(fildata.incident, { "sort": gridApi.field });
  169. } else {
  170. angular.extend(fildata.incident, { "sort": gridApi.field + " desc , _incident.acceptDate" });
  171. }
  172. } else {
  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. }
  179. } else if (index % 3 == 2) {
  180. if (fildata.incident) {
  181. if (gridApi.field == "acceptDate") {
  182. angular.extend(fildata.incident, { "sort": gridApi.field, "order": "asc" });
  183. } else {
  184. angular.extend(fildata.incident, { "sort": gridApi.field + " asc , _incident.acceptDate" });
  185. }
  186. } else {
  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. }
  193. // angular.extend(fildata, { 'incident': { "sort": gridApi.field, "order": "asc" } });
  194. }
  195. $scope.refreshData('expand-right', fildata);
  196. }
  197. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  198. var filtersData = $scope.memoryfilterData;
  199. filtersData.idx = newPage - 1;
  200. filtersData.sum = pageSize;
  201. $scope.refreshData('expand-right', filtersData);
  202. });
  203. gridApi.core.on.filterChanged($scope, function () {
  204. var grid = this.grid;
  205. if ($rootScope.user.group) {
  206. var filtersData = {
  207. idx: 0,
  208. sum: mun
  209. };
  210. } else {
  211. var filtersData = {
  212. idx: 0,
  213. sum: mun
  214. };
  215. }
  216. angular.forEach(grid.columns, function (item) {
  217. if (item.enableFiltering) {
  218. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  219. filtersData = $scope.memoryfilterData
  220. if (angular.isUndefined(filtersData['incident'])) {
  221. filtersData['incident'] = {};
  222. }
  223. if (item.field == 'requester.name') {
  224. filtersData['incident']['requester'] = {};
  225. filtersData.incident.requester['accountName'] = item.filters[0].term;
  226. } else if (item.field == 'handlingPersonnelUser.name') {
  227. filtersData['incident']['handlingPersonnelUser'] = {};
  228. filtersData.incident.handlingPersonnelUser['name'] = item.filters[0].term;
  229. } else if (item.field == 'requester.account') {
  230. filtersData['incident']['requester'] = {};
  231. filtersData.incident.requester['account'] = item.filters[0].term;
  232. } else if (item.field == 'acceptUser.name') {
  233. filtersData['incident']['acceptUser'] = {};
  234. filtersData.incident.acceptUser['name'] = item.filters[0].term;
  235. } else {
  236. filtersData['incident'][item.field] = item.filters[0].term;
  237. }
  238. }
  239. }
  240. });
  241. filtersData.idx = 0;
  242. $scope.memoryfilterData = filtersData;
  243. $scope.refreshData('expand-right', filtersData);
  244. });
  245. };
  246. //当前人是否分组
  247. if ($rootScope.user.group) {
  248. if ($rootScope.user.group.length == 0) {
  249. SweetAlert.swal("访问失败!", "当前登录人未分配工作组,无权限访问,请添加工作组后重试。", "error");
  250. } else {
  251. $scope.memoryfilterData = defaultFilterData = {
  252. "idx": 0,
  253. "sum": mun
  254. };
  255. }
  256. } else {
  257. $scope.memoryfilterData = defaultFilterData = {
  258. "idx": 0,
  259. "sum": mun
  260. };
  261. }
  262. var items=[];
  263. if ($stateParams.model) {
  264. if (JSON.parse($stateParams.model).searchType && JSON.parse($stateParams.model).searchType != null) {
  265. $scope.searchTypes = JSON.parse($stateParams.model).searchType;
  266. } else {
  267. $scope.searchTypes = "todo";
  268. }
  269. } else {
  270. $scope.searchTypes = "todo";
  271. }
  272. if ($rootScope.user.group) {
  273. var defaultFilterData = {
  274. "idx": 0,
  275. "sum": mun
  276. };
  277. } else {
  278. var defaultFilterData = {
  279. "idx": 0,
  280. "sum": mun
  281. };
  282. }
  283. if (angular.isDefined($rootScope.search) && angular.isDefined($rootScope.search.incident)) {
  284. defaultFilterData['searchType'] = $rootScope.search.incident;
  285. $scope.searchTypes = $rootScope.search.incident;
  286. }
  287. if ($rootScope['cmdbs'] != 'incident') { $rootScope.idx = 1 }
  288. if (angular.isDefined($rootScope.idx) && $rootScope.cmdbs != "false") {
  289. $rootScope['cmdbs'] = 'incident';
  290. defaultFilterData.idx = $rootScope.idx - 1;
  291. } else { $rootScope.cmdbs = ""; }
  292. $scope.ldloading = {};
  293. console.log($stateParams.idd)
  294. //获取列表数据
  295. $scope.refreshData = function (style, filterData) {
  296. var pdKey = "assetConsumablesHistory";
  297. $scope.myData = [];
  298. $scope.gridOptions['sum'] = filterData.sum;
  299. filterData['assetConsumablesHistory']={"assetConsumablesId":$stateParams.idd};
  300. api_cmdb3.fetchDataList(pdKey, filterData).then(function (data) {
  301. // console.log(data.list);
  302. if (data.list) {
  303. var myData = Restangular.stripRestangular(data);
  304. var list = [];
  305. $scope.gridOptions['totalItems'] = myData.totalNum;
  306. $scope.myData = myData.list;
  307. // console.log($scope.myData);
  308. for (var i = 0; i < $scope.myData.length; i++) {
  309. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  310. }
  311. } else {
  312. SweetAlert.swal({
  313. title: "系统错误",
  314. text: "请稍后再试!",
  315. type: "error"
  316. });
  317. }
  318. $scope.ldloading[style.replace('-', '_')] = false;
  319. }, function () {
  320. $scope.ldloading[style.replace('-', '_')] = false;
  321. });
  322. };
  323. $scope.refreshData('expand-right', defaultFilterData);
  324. }])