incidentRequestMobileCtrl.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. app.controller('incidentRequestMobileCtrl', ["$rootScope", "$scope", "i18nService", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "FileUploader", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_solution", "api_bpm_domain", "api_bpm_data", "$aside", function($rootScope, $scope, i18nService, $state, $timeout, $interval, SweetAlert, $modal, FileUploader, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_solution, api_bpm_domain, api_bpm_data, $aside) {
  2. $scope.langs = i18nService.getAllLangs();
  3. $scope.lang = 'zh-cn';
  4. i18nService.setCurrentLang($scope.lang);
  5. var loginUser = $rootScope.user;
  6. var pdKey = $state.current.pdKey;
  7. // $rootScope.app.topTitle = '事件列表';
  8. var incidentListMobileParameter = {
  9. 'assignee': loginUser.account,
  10. 'idx': 0,
  11. 'sum': 10,
  12. 'status': '',
  13. 'count': 0,
  14. 'currentPage': 1,
  15. 'endPage': 0,
  16. 'pages': []
  17. }
  18. //本地数据初始化
  19. sessionStorage.incidentListMobileParameter = JSON.stringify(incidentListMobileParameter);
  20. if ($rootScope.user.group) {
  21. if ($rootScope.user.group.length == 0) {
  22. SweetAlert.swal("访问失败!", "当前登录人未分配工作组,无权限访问,请添加工作组后重试。", "error");
  23. } else {
  24. var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  25. angular.extend(filterData, { "candidateGroups": $rootScope.user.group[0].id, });
  26. sessionStorage.incidentListMobileParameter = JSON.stringify(filterData);
  27. }
  28. }
  29. $scope.transferTime = function(time) {
  30. return moment(time).format('YYYY-MM-DD ');
  31. }
  32. $scope.transferStatus = function(status) {};
  33. $scope.paginationList = {};
  34. //新增数据
  35. $scope.addData = function() {
  36. var data = JSON.parse(sessionStorage.incidentListMobileParameter);
  37. if (data.formUiEdit) {
  38. var formUiEdit = data.formUiEdit;
  39. };
  40. if (data.formUiName) {
  41. var formUiName = data.formUiName;
  42. };
  43. if (data.processKey) {
  44. var pdKey = data.processKey;
  45. };
  46. if (data.formUiStart) {
  47. var formUiStart = data.formUiStart;
  48. };
  49. if (pdKey) {
  50. $state.go('app.inspectionMobile.inspectionEditorMobile', {
  51. 'pdKey': pdKey,
  52. 'formUiEdit': formUiEdit,
  53. 'formUiName': formUiName,
  54. 'formUiStart': formUiStart,
  55. 'userId': data.status
  56. });
  57. } else {
  58. SweetAlert.swal({
  59. title: "当前服务类型不可新建",
  60. // text: myData.data,
  61. type: "warning"
  62. });
  63. }
  64. };
  65. // $scope.newincident = function(data) {
  66. // $state.go('app.incident.editor', {});
  67. // };
  68. // $scope.selectRowFunction = function(data) {
  69. // $state.go('app.incident.editor', { taskId: data.taskId, processInstanceId: data.processInstanceId });
  70. // };
  71. // $scope.followFunction = function(data) {
  72. // //console.log('data='+JSON.stringify(data));
  73. // $state.go('app.detail', { formKey: 'statusform', pdKey: 'incident', dataId: data.id, processInstanceId: data.processInstanceId });
  74. // };
  75. $scope.addNewFunction = function() {
  76. $state.go('app.incidentMobile.incidentRequestEditorMobile', {
  77. 'formKey': 'requestMobileEditor'
  78. // 'weChatFlag': 'requestMobile'
  79. });
  80. };
  81. //跳转到编辑列表
  82. $scope.editorFunction = function(data) {
  83. // $state.go('app.inspection.inspectListEditor', {
  84. // "taskId": data.taskId,
  85. // "processInstanceId": data.processInstanceId,
  86. // "pdKey": data.processKey,
  87. // "formUiEdit": data.inspection.inspectionTypeDTO.formUiEdit,
  88. // // "formUiName": data.inspection.inspectionTypeDTO.formUiName,
  89. // });
  90. $state.go('app.inspectionMobile.inspectionEditorMobile', {
  91. taskId: data.taskId,
  92. processInstanceId: data.processInstanceId
  93. });
  94. };
  95. //跳转到查看列表
  96. $scope.lookFunction = function(data) {
  97. $state.go('app.inspectionMobile.inspectionDetailMobile', {
  98. // "formKey": data.inspection.inspectionTypeDTO.formUiName,
  99. // "dataId": data.id,
  100. // "taskId": data.taskId,
  101. // "processInstanceId": data.processInstanceId,
  102. // "pdKey": data.processKey,
  103. // "formUiEdit": data.inspection.inspectionTypeDTO.formUiEdit,
  104. // "formUiName": data.inspection.inspectionTypeDTO.formUiName,
  105. "formKey": 'incident_back',
  106. "pdKey": 'incident',
  107. "dataId": data.id,
  108. "taskId": data.taskId,
  109. "processInstanceId": data.processInstanceId
  110. });
  111. };
  112. //页面刷新
  113. $scope.reload = function() {
  114. $scope.refreshListData('expand-right');
  115. }
  116. //前往第一页按钮
  117. $scope.paginationFristPage = function() {
  118. var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  119. filterData.currentPage = 1;
  120. sessionStorage.incidentListMobileParameter = JSON.stringify(filterData);
  121. $scope.refreshListData('expand-right');
  122. }
  123. //前往最后一页按钮
  124. $scope.paginationLastPage = function() {
  125. var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  126. filterData.currentPage = filterData.endPage;
  127. sessionStorage.incidentListMobileParameter = JSON.stringify(filterData);
  128. $scope.refreshListData('expand-right');
  129. }
  130. //加载某一页
  131. $scope.paginationLoadPage = function(page) {
  132. var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  133. filterData.currentPage = page;
  134. sessionStorage.incidentListMobileParameter = JSON.stringify(filterData);
  135. $scope.refreshListData('expand-right');
  136. }
  137. //初始化分页栏
  138. var reloadPno = function() {
  139. var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  140. filterData.pages = calculateIndexes(filterData.currentPage, filterData.endPage, 4);
  141. $scope.paginationList = filterData;
  142. };
  143. //分页算法
  144. var calculateIndexes = function(current, length, displayLength) {
  145. var indexes = [];
  146. var start = Math.round(current - displayLength / 2);
  147. var end = Math.round(current + displayLength / 2);
  148. if (start <= 1) {
  149. start = 1;
  150. end = start + displayLength - 1;
  151. if (end >= length - 1) {
  152. end = length - 1;
  153. }
  154. }
  155. if (end >= length - 1) {
  156. end = length;
  157. start = end - displayLength + 1;
  158. if (start <= 1) {
  159. start = 1;
  160. }
  161. }
  162. for (var i = start; i <= end; i++) {
  163. indexes.push(i);
  164. }
  165. return indexes;
  166. };
  167. //数据加载
  168. $scope.ldloading = {};
  169. $scope.refreshListData = function(style) {
  170. //刷新按钮动画
  171. $scope.ldloading[style.replace('-', '_')] = true;
  172. //获取本地数据
  173. var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  174. //对接口参数进行重新组装
  175. var showData = {
  176. 'assignee': filterData.assignee,
  177. 'idx': filterData.currentPage ? filterData.currentPage - 1 : 0,
  178. 'searchType': filterData.searchType,
  179. 'status': filterData.status,
  180. 'sum': filterData.sum,
  181. };
  182. if (filterData.candidateGroups) {
  183. angular.extend(showData, { 'candidateGroups': filterData.candidateGroups });
  184. };
  185. $scope.myData = [];
  186. api_bpm_domain.weChatFetchServiceTasks(pdKey, showData).then(function(data) {
  187. var myData = Restangular.stripRestangular(data);
  188. filterData.count = myData.resultCount;
  189. if (angular.isArray(myData.data) && myData.data.length > 0) {
  190. $scope.myData = myData.data;
  191. $scope.listShow = true;
  192. filterData.endPage = Math.ceil(filterData.count / filterData.sum);
  193. // filterData.currentPage = filterData.pageIndex + 1;
  194. sessionStorage.incidentListMobileParameter = JSON.stringify(filterData);
  195. reloadPno();
  196. angular.forEach($scope.myData, function(ObjIndex) {
  197. if (angular.isUndefined(ObjIndex.extendStatus)) {
  198. angular.extend(ObjIndex, { 'extendStatus': false })
  199. }
  200. });
  201. } else {
  202. // SweetAlert.swal({
  203. // title: "数据为空",
  204. // text: myData.data,
  205. // type: "warning"
  206. // });
  207. // if ($scope.paginationList || $scope.paginationList.count) {
  208. // $scope.paginationList.count = 0;
  209. // }
  210. $scope.listShow = false;
  211. }
  212. $scope.ldloading[style.replace('-', '_')] = false;
  213. }, function() {
  214. $scope.ldloading[style.replace('-', '_')] = false;
  215. });
  216. }
  217. $scope.openAside = function(position) {
  218. var asideOpen = $aside.open({
  219. templateUrl: 'assets/views/incident/incidentListMoblieDetail.html',
  220. placement: position,
  221. size: 'sm',
  222. backdrop: true,
  223. controller: function($scope, $modalInstance, api_user_data, api_solution, inspectListMobileCtrlTree) {
  224. var searchCriteria = {
  225. // 'searchType': '',
  226. // 'status': '',
  227. };
  228. // var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  229. // searchCriteria.searchType = "";
  230. // searchCriteria.status = "";
  231. $scope.ok = function(e) {
  232. $modalInstance.close(searchCriteria);
  233. // e.stopPropagation();
  234. };
  235. $scope.cancel = function(e) {
  236. $modalInstance.dismiss();
  237. // e.stopPropagation();
  238. };
  239. $scope.statuses = [
  240. { status: 'all', label: '全部的事件', idName: 'a' },
  241. { status: 'todo', label: '待我处理的', idName: 'b' },
  242. { status: 'create', label: '我创建的', idName: 'c' },
  243. { status: 'done', label: '我处理过的', idName: 'd' },
  244. // { status: 's', label: '已驳回', idName: 'e' },
  245. // { status: '6', label: '已拒绝', idName: 'f' }
  246. ];
  247. //获取服务请求类型
  248. $scope.onChange = function(searchType) {
  249. // var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  250. if (angular.isUndefined(searchType)) {
  251. searchCriteria.searchType = $scope.searchType;
  252. } else {
  253. searchCriteria.searchType = searchType;
  254. }
  255. // sessionStorage.incidentListMobileParameter = JSON.stringify(filterData);
  256. }
  257. //通过树型控件获取服务请求分类
  258. $scope.my_tree_handler = function(branch) {
  259. // var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  260. var filterData = {};
  261. searchCriteria.status = branch.id;
  262. if (branch.formUiEdit) {
  263. filterData.formUiEdit = branch.formUiEdit;
  264. };
  265. if (branch.formUiName) {
  266. filterData.formUiName = branch.formUiName;
  267. };
  268. if (branch.processKey) {
  269. filterData.processKey = branch.processKey;
  270. };
  271. if (branch.formUiStart) {
  272. filterData.formUiStart = branch.formUiStart;
  273. };
  274. searchCriteria.idx = 0;
  275. angular.extend(searchCriteria, filterData);
  276. // sessionStorage.incidentListMobileParameter = JSON.stringify(filterData);
  277. };
  278. $scope.my_data = [];
  279. $scope.tree_data = [];
  280. $scope.my_tree = tree = {};
  281. $scope.try_async_load = function() {
  282. api_bpm_data.fetchDataList('inspectionType', { "idx": 0, "sum": 1000 }).then(function(response) {
  283. var responseData = inspectListMobileCtrlTree(response);
  284. $scope.my_data = responseData.my_data;
  285. $scope.tree_data = responseData.tree_data;
  286. });
  287. }
  288. $scope.try_async_load();
  289. }
  290. });
  291. asideOpen.result.then(function(searchCriteria) {
  292. if (searchCriteria.searchType || searchCriteria.status) {
  293. var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  294. angular.extend(filterData, searchCriteria);
  295. sessionStorage.incidentListMobileParameter = JSON.stringify(filterData);
  296. $scope.refreshListData('expand-right');
  297. } else {
  298. SweetAlert.swal({
  299. title: "条件未选",
  300. text: "请选择服务请求条件",
  301. type: "warning"
  302. });
  303. }
  304. });
  305. };
  306. $scope.refreshListData('expand_right');
  307. // $scope.try_async_load();
  308. }]);
  309. app.factory('inspectListMobileCtrlTree', ['api_bpm_data', function(api_bpm_data) {
  310. function convertListToTree(data, treeMap) {
  311. var idToNodeMap = {};
  312. var root = null;
  313. var parentNode = null;
  314. for (var i = 0; i < data.length; i++) {
  315. var datum = data[i];
  316. datum.children = [];
  317. idToNodeMap[datum.id] = datum;
  318. if (typeof datum.parent === "undefined" || datum.parent == null) {
  319. root = datum;
  320. treeMap[datum.id] = root;
  321. } else {
  322. parentNode = idToNodeMap[datum.parent];
  323. delete datum.parent;
  324. parentNode.children.push(datum);
  325. }
  326. }
  327. return root;
  328. };
  329. function convertParentToChildList(data) {
  330. var treeMap = {};
  331. var list = [];
  332. convertListToTree(data, treeMap);
  333. angular.forEach(treeMap, function(item) {
  334. list.push(item);
  335. });
  336. return list;
  337. };
  338. var forEachEelement = function forEachEelement(response) {
  339. var objects = [];
  340. angular.forEach(response.list, function(ObjIndex, index, destObj) {
  341. var object = {};
  342. object.id = ObjIndex.id;
  343. object.label = ObjIndex.type;
  344. if (ObjIndex.parent && ObjIndex.parent.id != 0) {
  345. object.parent = ObjIndex.parent.id;
  346. };
  347. if (ObjIndex.formUiEdit) {
  348. object.formUiEdit = ObjIndex.formUiEdit;
  349. };
  350. if (ObjIndex.formUiName) {
  351. object.formUiName = ObjIndex.formUiName;
  352. };
  353. if (ObjIndex.processKey) {
  354. object.processKey = ObjIndex.processKey;
  355. };
  356. if (ObjIndex.formUiStart) {
  357. object.formUiStart = ObjIndex.formUiStart;
  358. };
  359. objects.push(object);
  360. });
  361. var my_data = convertParentToChildList(objects);
  362. var tree_data = angular.copy(my_data);
  363. return {
  364. 'my_data': my_data,
  365. 'tree_data': tree_data
  366. }
  367. }
  368. return forEachEelement;
  369. }]);