inspectListMobileCtrl.1.js 16 KB

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