historyCtrl.js 14 KB

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