inspectListCtrl.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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.inspectionType.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">查看</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. var filedata={
  147. model:{inspectionProcessActual:data}
  148. }
  149. $state.go('app.inspection.inspectListEditor', {
  150. "taskId": data.taskId,
  151. "processInstanceId": data.processInstanceId,
  152. "pdKey": data.processKey,
  153. "formUiEdit": data.inspection.inspectionType.formUiEdit,
  154. // "formUiName": data.inspection.inspectionTypeDTO.formUiName,
  155. "model" : JSON.stringify(filedata)
  156. });
  157. };
  158. $scope.lookFunction = function(data) {
  159. var filedata={
  160. model:{inspectionProcessActual:data}
  161. // model:data
  162. }
  163. $state.go('app.inspection.inspectListdetail', {
  164. "formKey": data.inspection.inspectionType.formUiName,
  165. "dataId": data.id,
  166. "taskId": data.taskId,
  167. "processInstanceId": data.processInstanceId,
  168. "pdKey": data.processKey,
  169. // "formUiEdit": data.inspection.inspectionTypeDTO.formUiEdit,
  170. "formUiName": data.inspection.inspectionType.formUiName,
  171. "model" : JSON.stringify(filedata)
  172. });
  173. };
  174. // $scope.removeData = function() {
  175. // // var rmvList = [$scope.selected.items.id]
  176. // var rmvList = [];
  177. // angular.forEach($scope.selected.items, function(item) {
  178. // rmvList.push(item.id);
  179. // });
  180. // if (rmvList.length > 0) {
  181. // api_bpm_data.rmvData('inspection', rmvList).then(function(response) {
  182. // if (response.status == 200) {
  183. // SweetAlert.swal({
  184. // title: "删除成功!",
  185. // type: "success",
  186. // confirmButtonColor: "#007AFF"
  187. // }, function() {
  188. // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); });
  189. // $scope.selected = {
  190. // items: []
  191. // };
  192. // });
  193. // } else {
  194. // SweetAlert.swal({
  195. // title: "操作异常!",
  196. // text: "系统异常,请稍后重试,或者联系管理员!",
  197. // type: "error"
  198. // });
  199. // }
  200. // })
  201. // }
  202. // }
  203. $scope.selected = {
  204. items: []
  205. }
  206. $scope.editted = {
  207. items: []
  208. }
  209. //分页控制
  210. $scope.gridOptions.onRegisterApi = function(gridApi) {
  211. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  212. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  213. filterData.idx = newPage - 1;
  214. filterData.sum = pageSize;
  215. $scope.refreshData('expand-right', filterData);
  216. });
  217. // gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  218. // data.grid.appScope.selected.items = data.entity
  219. // console.log(data);
  220. // });
  221. }
  222. //本地存储
  223. sessionStorage.inspectListParameter = JSON.stringify(inspectListParameter);
  224. // var data = JSON.parse(sessionStorage.inspectListParameter);
  225. // sessionStorage.inspectListParameter = JSON.stringify(data);
  226. $scope.ldloading = {};
  227. //搜索事件
  228. $scope.searchinspectlist = function(item) {
  229. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  230. if (item.type) {
  231. filterData.status = item.type.id;
  232. }
  233. if (item.title) {
  234. filterData.title = item.title;
  235. }
  236. // filterData.status = item;
  237. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  238. $scope.refreshData('expand-right', filterData);
  239. };
  240. //树形控件点击事件
  241. $scope.my_tree_handler = function(branch) {
  242. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  243. filterData.status = branch.id;
  244. // if (filterData.inspectionProcessActual) {
  245. // filterData.inspectionProcessActual.inspectionTypeId = branch.id;
  246. // } else {
  247. // filterData = angular.extend(filterData, {
  248. // "inspectionProcessActual": {
  249. // "inspectionTypeId": branch.id
  250. // }
  251. // })
  252. // }
  253. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  254. $scope.refreshData('expand-right', filterData);
  255. };
  256. //搜索栏点击事件
  257. $scope.searchstate = 'todo';
  258. $scope.onChange = function(searchType) {
  259. $scope.searchstate = searchType;
  260. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  261. filterData.searchType = searchType;
  262. sessionStorage.inspectListParameter = JSON.stringify(filterData);
  263. $scope.refreshData('expand-right', filterData);
  264. }
  265. $scope.reload = function() {
  266. var filterData = JSON.parse(sessionStorage.inspectListParameter);
  267. $scope.refreshData('expand-right', filterData);
  268. }
  269. $scope.refreshData = function(style, filterData) {
  270. $scope.ldloading[style.replace('-', '_')] = true;
  271. if (angular.isUndefined(filterData)) {
  272. filterData = defaultFilterData;
  273. }
  274. $scope.myData = [];
  275. $scope.memoryfilterData = filterData;
  276. api_bpm_data.fetchInspectServiceTasks(filterData.status, filterData).then(function(data) {
  277. var myData = Restangular.stripRestangular(data);
  278. $scope.gridOptions.totalItems = myData.resultCount;
  279. if (angular.isArray(myData.data)) {
  280. $scope.myData = myData.data;
  281. for (var i = 0; i < $scope.myData.length; i++) {
  282. //添加序号
  283. $scope.myData[i]['itemId'] = i + 1 + filterData.idx * filterData.sum;
  284. }
  285. $scope.ldloading[style.replace('-', '_')] = false;
  286. } else {
  287. $scope.ldloading[style.replace('-', '_')] = false;
  288. SweetAlert.swal({
  289. title: "数据为空",
  290. text: myData.data,
  291. type: "warning"
  292. });
  293. }
  294. }, function() {
  295. $scope.ldloading[style.replace('-', '_')] = false;
  296. });
  297. };
  298. //树形控件加载
  299. $scope.my_tree = {};
  300. $scope.try_async_load = function() {
  301. $scope.my_data = [];
  302. $scope.doing_async = true;
  303. api_bpm_data.fetchDataList('inspectionType', { "idx": 0, "sum": 1000 }).then(function(response) {
  304. if (response.status == 200) {
  305. var data = response.list;
  306. var objects = [];
  307. for (var i = 0; i < data.length; i++) {
  308. var object = {};
  309. object.id = data[i].id;
  310. if (data[i].parent && data[i].parent.id != 0) {
  311. object.parent = data[i].parent.id;
  312. }
  313. object.label = data[i].type;
  314. objects.push(object);
  315. }
  316. $scope.my_data = convertParentToChildList(objects);
  317. $scope.tree_data = angular.copy($scope.my_data);
  318. if ($scope.my_data.length > 0) {
  319. $scope.doing_async = false;
  320. }
  321. // return $scope.my_tree.expand_all()
  322. } else {
  323. SweetAlert.swal({
  324. title: "系统错误!",
  325. text: "请刷新重试!",
  326. type: "error"
  327. });
  328. }
  329. });
  330. };
  331. function convertListToTree(data, treeMap) {
  332. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  333. var root = null; //Initially set our loop to null
  334. var parentNode = null;
  335. //loop over data
  336. for (var i = 0; i < data.length; i++) {
  337. var datum = data[i];
  338. //each node will have children, so let's give it a "children" poperty
  339. datum.children = [];
  340. //add an entry for this node to the map so that any future children can
  341. //lookup the parent
  342. idToNodeMap[datum.id] = datum;
  343. //Does this node have a parent?
  344. if (typeof datum.parent === "undefined" || datum.parent == null) {
  345. //Doesn't look like it, so this node is the root of the tree
  346. root = datum;
  347. treeMap[datum.id] = root;
  348. } else {
  349. //This node has a parent, so let's look it up using the id
  350. parentNode = idToNodeMap[datum.parent];
  351. //We don't need this property, so let's delete it.
  352. delete datum.parent;
  353. //Let's add the current node as a child of the parent node.
  354. parentNode.children.push(datum);
  355. }
  356. }
  357. return root;
  358. }
  359. function convertParentToChildList(data) {
  360. var treeMap = {};
  361. var list = [];
  362. convertListToTree(data, treeMap);
  363. angular.forEach(treeMap, function(item) {
  364. list.push(item);
  365. });
  366. return list;
  367. }
  368. $scope.refreshData('expand-right', defaultFilterData);
  369. $scope.try_async_load();
  370. }]);