inspectListCtrl.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('inspectListCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_schedule", "api_bpm_data", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_schedule, api_bpm_data) {
  6. $scope.langs = i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser = $rootScope.user;
  10. var defaultFilterData = {
  11. "assignee": loginUser.id,
  12. // "assignee": "1",
  13. "idx": 0,
  14. "sum": 10,
  15. "status": '',
  16. "searchType": "todo"
  17. };
  18. var inspectListParameter = {
  19. "assignee": loginUser.id,
  20. // "assignee": "1",
  21. "idx": 0,
  22. "sum": 10,
  23. "status": ''
  24. };
  25. // $scope.memoryfilterData = {
  26. // "idx": 0,
  27. // "sum": 10
  28. // }
  29. //ui-grid设置
  30. $scope.gridOptions = {};
  31. $scope.gridOptions.data = 'myData';
  32. $scope.gridOptions.enableColumnResizing = true;
  33. $scope.gridOptions.enableFiltering = true;
  34. $scope.gridOptions.enableGridMenu = false;
  35. $scope.gridOptions.enableRowSelection = true;
  36. $scope.gridOptions.showGridFooter = true;
  37. $scope.gridOptions.showColumnFooter = false;
  38. $scope.gridOptions.fastWatch = true;
  39. $scope.gridOptions.useExternalFiltering = true;
  40. $scope.gridOptions.useExternalPagination = true;
  41. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  42. $scope.gridOptions.paginationPageSize = 10;
  43. $scope.gridOptions.multiSelect = true;
  44. // $scope.gridOptions.rowTemplate = '<div style="background: red"><a>123</a></div';
  45. // $scope.gridOptions.rowTemplate = "<div ng-dblclick=\"grid.appScope.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>";
  46. $scope.gridOptions.rowIdentity = function(row) {
  47. return row.id;
  48. };
  49. $scope.gridOptions.getRowIdentity = function(row) {
  50. return row.id;
  51. };
  52. $scope.transferColor = function(item) {
  53. var color = "icon iconfont icon-zhengchang greenfont";
  54. if (item && item.colourInfo) {
  55. if (item.colourInfo.id == 1) {
  56. color = "icon iconfont icon-yiyuqi redfont";
  57. } else if (item.colourInfo.id == 2) {
  58. color = "iconfont icon-yuqixinxiu yellofont";
  59. }
  60. } else {
  61. // color = "white";
  62. }
  63. return color;
  64. }
  65. $scope.transfertip = function(item) {
  66. var tip = "正常";
  67. if (item && item.colourInfo) {
  68. if (item.colourInfo.id == 1) {
  69. tip = "逾期";
  70. } else if (item.colourInfo.id == 2) {
  71. tip = "即将逾期";
  72. }
  73. } else {
  74. // color = "white";
  75. }
  76. return tip;
  77. }
  78. $scope.gridOptions.columnDefs = [{
  79. name: 'id',
  80. displayName: '',
  81. width: 40,
  82. enableFiltering: false,
  83. cellTemplate: '<div>' +
  84. '<div class="ui-grid-cell-contents" tooltip={{grid.appScope.transfertip(row.entity.ruleColour)}} tooltip-placement="right"><i style="font-size: 18px !important;" class="{{grid.appScope.transferColor(row.entity.ruleColour)}}"></i></div></div>'
  85. },
  86. {
  87. name: 'inspection.inspectionTypeDTO.type',
  88. displayName: '巡检分类',
  89. width: 120,
  90. enableFiltering: false
  91. },
  92. {
  93. name: 'inspection.title',
  94. displayName: '计划主题',
  95. width: 120,
  96. enableFiltering: false
  97. },
  98. {
  99. name: 'inspection.createUser.name',
  100. displayName: '创建人',
  101. width: 80,
  102. enableFiltering: false
  103. },
  104. {
  105. name: 'stateName',
  106. displayName: '状态',
  107. width: 80,
  108. enableFiltering: false
  109. },
  110. {
  111. name: 'processUser.name',
  112. displayName: '处理人',
  113. width: 80,
  114. enableFiltering: false
  115. },
  116. {
  117. name: 'startDate',
  118. displayName: '开始时间',
  119. width: 160,
  120. enableFiltering: false
  121. },
  122. {
  123. name: 'overdueTime',
  124. displayName: '逾期时间',
  125. width: 160,
  126. enableFiltering: false
  127. },
  128. {
  129. name: '操作',
  130. width: 100,
  131. enableFiltering: false,
  132. cellTemplate: '<div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  133. // '<a ng-click="grid.appScope.lookFunction(row.entity)" tooltip="查看" tooltip-placement="right"><i class="ti-eye"></i></a>' +
  134. '<a ng-show="{{!row.entity.state==1}}" ng-click="grid.appScope.selectRowFunction(row.entity)" class="bianjifont">编辑</a>' +
  135. // '<a ng-show="{{!row.entity.state==1}}" ng-click="grid.appScope.selectRowFunction(row.entity)" tooltip="编辑" tooltip-placement="left"><i class="fa fa-pencil-square-o"/></a>' +
  136. '</div>'
  137. },
  138. ];
  139. // $scope.addData = function() {
  140. // $state.go('app.inspection.inspectList.editor', {
  141. // formKey: 'inspectionform',
  142. // service: 'api_bpm_data'
  143. // });
  144. // }
  145. $scope.selectRowFunction = function(data) {
  146. $state.go('app.inspection.inspectListEditor', {
  147. "taskId": data.taskId,
  148. "processInstanceId": data.processInstanceId,
  149. "pdKey": data.processKey,
  150. "formUiEdit": data.inspection.inspectionTypeDTO.formUiEdit,
  151. // "formUiName": data.inspection.inspectionTypeDTO.formUiName,
  152. });
  153. };
  154. $scope.lookFunction = function(data) {
  155. $state.go('app.inspection.inspectListdetail', {
  156. "formKey": data.inspection.inspectionTypeDTO.formUiName,
  157. "dataId": data.id,
  158. "taskId": data.taskId,
  159. "processInstanceId": data.processInstanceId,
  160. "pdKey": data.processKey,
  161. // "formUiEdit": data.inspection.inspectionTypeDTO.formUiEdit,
  162. "formUiName": data.inspection.inspectionTypeDTO.formUiName,
  163. });
  164. };
  165. // $scope.removeData = function() {
  166. // // var rmvList = [$scope.selected.items.id]
  167. // var rmvList = [];
  168. // angular.forEach($scope.selected.items, function(item) {
  169. // rmvList.push(item.id);
  170. // });
  171. // if (rmvList.length > 0) {
  172. // api_bpm_data.rmvData('inspection', rmvList).then(function(response) {
  173. // if (response.status == 200) {
  174. // SweetAlert.swal({
  175. // title: "删除成功!",
  176. // type: "success",
  177. // confirmButtonColor: "#007AFF"
  178. // }, function() {
  179. // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); });
  180. // $scope.selected = {
  181. // items: []
  182. // };
  183. // });
  184. // } else {
  185. // SweetAlert.swal({
  186. // title: "操作异常!",
  187. // text: "系统异常,请稍后重试,或者联系管理员!",
  188. // type: "error"
  189. // });
  190. // }
  191. // })
  192. // }
  193. // }
  194. $scope.selected = {
  195. items: []
  196. }
  197. $scope.editted = {
  198. items: []
  199. }
  200. //分页控制
  201. $scope.gridOptions.onRegisterApi = function(gridApi) {
  202. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  203. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  204. filterData.idx = newPage - 1;
  205. filterData.sum = pageSize;
  206. $scope.refreshData('expand-right', filterData);
  207. });
  208. // gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  209. // data.grid.appScope.selected.items = data.entity
  210. // console.log(data);
  211. // });
  212. }
  213. //本地存储
  214. sessionStorage.inspectListParameter = JSON.stringify(inspectListParameter);
  215. // var data = JSON.parse(sessionStorage.inspectListParameter);
  216. // sessionStorage.inspectListParameter = JSON.stringify(data);
  217. $scope.ldloading = {};
  218. //搜索事件
  219. $scope.searchinspectlist = function(item) {
  220. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  221. if (item.type) {
  222. filterData.status = item.type.id;
  223. }
  224. if (item.title) {
  225. filterData.title = item.title;
  226. }
  227. // filterData.status = item;
  228. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  229. $scope.refreshData('expand-right', filterData);
  230. };
  231. //树形控件点击事件
  232. $scope.my_tree_handler = function(branch) {
  233. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  234. filterData.status = branch.id;
  235. // if (filterData.inspectionProcessActual) {
  236. // filterData.inspectionProcessActual.inspectionTypeId = branch.id;
  237. // } else {
  238. // filterData = angular.extend(filterData, {
  239. // "inspectionProcessActual": {
  240. // "inspectionTypeId": branch.id
  241. // }
  242. // })
  243. // }
  244. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  245. $scope.refreshData('expand-right', filterData);
  246. };
  247. //搜索栏点击事件
  248. $scope.searchstate = 'todo';
  249. $scope.onChange = function(searchType) {
  250. $scope.searchstate = searchType;
  251. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  252. filterData.searchType = searchType;
  253. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  254. $scope.refreshData('expand-right', filterData);
  255. }
  256. $scope.reload = function() {
  257. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  258. $scope.refreshData('expand-right', filterData);
  259. }
  260. $scope.refreshData = function(style, filterData) {
  261. $scope.ldloading[style.replace('-', '_')] = true;
  262. if (angular.isUndefined(filterData)) {
  263. filterData = defaultFilterData;
  264. }
  265. $scope.myData = [];
  266. $scope.memoryfilterData = filterData;
  267. api_bpm_data.fetchInspectServiceTasks(filterData.status, filterData).then(function(data) {
  268. var myData = Restangular.stripRestangular(data);
  269. $scope.gridOptions.totalItems = myData.resultCount;
  270. if (angular.isArray(myData.data)) {
  271. $scope.myData = myData.data;
  272. for (var i = 0; i < $scope.myData.length; i++) {
  273. //添加序号
  274. $scope.myData[i]['itemId'] = i + 1 + filterData.idx * filterData.sum;
  275. }
  276. $scope.ldloading[style.replace('-', '_')] = false;
  277. } else {
  278. $scope.ldloading[style.replace('-', '_')] = false;
  279. SweetAlert.swal({
  280. title: "数据为空",
  281. text: myData.data,
  282. type: "warning"
  283. });
  284. }
  285. }, function() {
  286. $scope.ldloading[style.replace('-', '_')] = false;
  287. });
  288. };
  289. //树形控件加载
  290. $scope.my_tree = {};
  291. $scope.try_async_load = function() {
  292. $scope.my_data = [];
  293. $scope.doing_async = true;
  294. api_bpm_data.fetchDataList('inspectionType', { "idx": 0, "sum": 1000 }).then(function(response) {
  295. if (response.status == 200) {
  296. var data = response.list;
  297. var objects = [];
  298. for (var i = 0; i < data.length; i++) {
  299. var object = {};
  300. object.id = data[i].id;
  301. if (data[i].parent && data[i].parent.id != 0) {
  302. object.parent = data[i].parent.id;
  303. }
  304. object.label = data[i].type;
  305. objects.push(object);
  306. }
  307. $scope.my_data = convertParentToChildList(objects);
  308. $scope.tree_data = angular.copy($scope.my_data);
  309. if ($scope.my_data.length > 0) {
  310. $scope.doing_async = false;
  311. }
  312. // return $scope.my_tree.expand_all()
  313. } else {
  314. SweetAlert.swal({
  315. title: "系统错误!",
  316. text: "请刷新重试!",
  317. type: "error"
  318. });
  319. }
  320. });
  321. };
  322. function convertListToTree(data, treeMap) {
  323. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  324. var root = null; //Initially set our loop to null
  325. var parentNode = null;
  326. //loop over data
  327. for (var i = 0; i < data.length; i++) {
  328. var datum = data[i];
  329. //each node will have children, so let's give it a "children" poperty
  330. datum.children = [];
  331. //add an entry for this node to the map so that any future children can
  332. //lookup the parent
  333. idToNodeMap[datum.id] = datum;
  334. //Does this node have a parent?
  335. if (typeof datum.parent === "undefined" || datum.parent == null) {
  336. //Doesn't look like it, so this node is the root of the tree
  337. root = datum;
  338. treeMap[datum.id] = root;
  339. } else {
  340. //This node has a parent, so let's look it up using the id
  341. parentNode = idToNodeMap[datum.parent];
  342. //We don't need this property, so let's delete it.
  343. delete datum.parent;
  344. //Let's add the current node as a child of the parent node.
  345. parentNode.children.push(datum);
  346. }
  347. }
  348. return root;
  349. }
  350. function convertParentToChildList(data) {
  351. var treeMap = {};
  352. var list = [];
  353. convertListToTree(data, treeMap);
  354. angular.forEach(treeMap, function(item) {
  355. list.push(item);
  356. });
  357. return list;
  358. }
  359. $scope.refreshData('expand-right', defaultFilterData);
  360. $scope.try_async_load();
  361. }]);