incidentHandlerCtrl.1.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. app.controller('incidentHandlerCtrl', ["$rootScope", "$scope", '$stateParams', '$http', '$state', '$timeout', '$ionicPopover', '$ionicPopup', '$ionicLoading', 'api_bpm_domain', 'Restangular', 'loginService', 'getLoginUser', function($rootScope, $scope, $stateParams, $http, $state, $timeout, $ionicPopover, $ionicPopup, $ionicLoading, api_bpm_domain, Restangular, loginService, getLoginUser) {
  2. console.log('incidentHandlerCtrl is load');
  3. //弹出框
  4. // .fromTemplate() method
  5. // var template = '<ion-popover-view><ion-header-bar> <h1 class="title">My Popover Title</h1> </ion-header-bar> <ion-content> Hello! </ion-content></ion-popover-view>';
  6. // $scope.popover = $ionicPopover.fromTemplate(template, {
  7. // scope: $scope
  8. // });
  9. // .fromTemplateUrl() method
  10. var promise = getLoginUser.query(); // 同步调用,获得承诺接口
  11. promise.then(function(data) { // 调用承诺API获取数据 .resolve
  12. // $scope.user = data;
  13. console.log(data)
  14. }, function(data) { // 处理错误 .reject
  15. // $scope.user = {error: '用户不存在!'};
  16. console.log(data)
  17. });
  18. $scope.goBack = function() {
  19. history.go(-1);
  20. }
  21. $scope.newFunction = function() {
  22. $state.go('tab.customFormIndex', {
  23. 'formKey': 'requestMobileEditor'
  24. });
  25. };
  26. $scope.load = {
  27. 'pageIndex': 0, //第几页
  28. 'pageSum': 10, //每页条数
  29. 'pageCount': 0 //总页数
  30. };
  31. $ionicPopover.fromTemplateUrl('assets/views/weChat/myIncident/popover.html', {
  32. scope: $scope
  33. }).then(function(popover) {
  34. $scope.popover = popover;
  35. });
  36. $scope.openPopover = function($event) {
  37. $scope.popover.show($event);
  38. };
  39. $scope.closePopover = function() {
  40. $scope.popover.hide();
  41. };
  42. //Cleanup the popover when we're done with it!
  43. $scope.$on('$destroy', function() {
  44. $scope.popover.remove();
  45. });
  46. // Execute action on hidden popover
  47. $scope.$on('popover.hidden', function(res) {
  48. // Execute action
  49. });
  50. // Execute action on remove popover
  51. $scope.$on('popover.removed', function() {
  52. // Execute action
  53. });
  54. $scope.statuses = [
  55. { status: 'all', label: '全部的事件', idName: 'a' },
  56. { status: 'todo', label: '待我处理的', idName: 'b' },
  57. { status: 'create', label: '我创建的', idName: 'c' },
  58. { status: 'done', label: '我处理过的', idName: 'd' },
  59. // { status: 's', label: '已驳回', idName: 'e' },
  60. // { status: '6', label: '已拒绝', idName: 'f' }
  61. ];
  62. $scope.searchTypeFunction = function(searchType) {
  63. $scope.refreshListData({ 'searchType': searchType });
  64. $scope.popover.hide();
  65. }
  66. // 一个精心制作的自定义弹窗
  67. // var myPopup = $ionicPopup.show({
  68. // template: '<input type="password" ng-model="data.wifi">',
  69. // title: 'Enter Wi-Fi Password',
  70. // subTitle: 'Please use normal things',
  71. // scope: $scope,
  72. // buttons: [
  73. // { text: 'Cancel' },
  74. // {
  75. // text: '<b>Save</b>',
  76. // type: 'button-positive',
  77. // onTap: function(e) {
  78. // if (!$scope.data.wifi) {
  79. // //不允许用户关闭,除非他键入wifi密码
  80. // e.preventDefault();
  81. // } else {
  82. // return $scope.data.wifi;
  83. // }
  84. // }
  85. // },
  86. // ]
  87. // });
  88. // myPopup.then(function(res) {
  89. // console.log('Tapped!', res);
  90. // });
  91. // $timeout(function() {
  92. // myPopup.close(); //由于某种原因3秒后关闭弹出
  93. // }, 3000);
  94. // 一个确认对话框
  95. $scope.showConfirm = function() {
  96. var confirmPopup = $ionicPopup.confirm({
  97. title: 'Consume Ice Cream',
  98. template: 'Are you sure you want to eat this ice cream?'
  99. });
  100. confirmPopup.then(function(res) {
  101. if (res) {
  102. console.log('You are sure');
  103. } else {
  104. console.log('You are not sure');
  105. }
  106. });
  107. };
  108. // 一个提示对话框
  109. $scope.showAlert = function() {
  110. var alertPopup = $ionicPopup.alert({
  111. title: 'Don\'t eat that!',
  112. template: 'It might taste good'
  113. });
  114. alertPopup.then(function(res) {
  115. console.log('Thank you for not eating my delicious ice cream cone');
  116. });
  117. };
  118. // $scope.loginForm = {};
  119. // var loginUser = $rootScope.user;
  120. //获取login中的数据
  121. var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
  122. var loginUser = sessionLogin.user;
  123. $rootScope.user = sessionLogin.user;
  124. //定义流程代号
  125. // var pdKey = $state.current.pdKey;
  126. var pdKey = 'bpm_incident';
  127. // var incidentListMobileParameter = {
  128. // 'assignee': loginUser.id,
  129. // 'idx': 0,
  130. // 'sum': 10,
  131. // 'status': '',
  132. // 'count': 0,
  133. // 'currentPage': 1,
  134. // 'endPage': 0,
  135. // 'pages': []
  136. // };
  137. //默认数据
  138. var defaultData = {
  139. 'assignee': loginUser.id,
  140. 'idx': 0,
  141. 'sum': 10,
  142. 'candidateGroups': loginUser.group["0"].id
  143. };
  144. //页面数据容器
  145. $scope.myData = [];
  146. //是否加载上拉刷新
  147. $scope.domore = false;
  148. //填充数据
  149. $scope.filterData = {
  150. 'assignee': loginUser.id,
  151. 'idx': 0,
  152. 'sum': 10,
  153. };
  154. //本地数据初始化
  155. // sessionStorage.incidentListMobileParameter = JSON.stringify(incidentListMobileParameter);
  156. //新增数据
  157. $scope.addData = function() {
  158. var roleMan = false;
  159. if ($rootScope.user.role || $rootScope.user.role != null) {
  160. for (var i in $rootScope.user.role) {
  161. if ($rootScope.user.role[i].id == 3 || $rootScope.user.role[i].id == 5 || $rootScope.user.role[i].id == 29700 || $rootScope.user.role[i].id == 29701) {
  162. roleMan = true;
  163. break;
  164. }
  165. }
  166. }
  167. if (roleMan) {
  168. $state.go('tab.incidentHandlerNew', {
  169. // pdKey: 'bpm_incident'
  170. })
  171. } else {
  172. $ionicPopup.alert({
  173. title: '没有访问权限',
  174. // template: 'It might taste good'
  175. });
  176. }
  177. // $state.go('tab.incidentHandlerNew', {
  178. // // pdKey: 'bpm_incident'
  179. // })
  180. };
  181. //跳转到编辑列表
  182. $scope.editorFunction = function(data) {
  183. $state.go('tab.incidentHandlerCustomFormIndex', {
  184. taskId: data.taskId,
  185. processInstanceId: data.processInstanceId
  186. });
  187. };
  188. //跳转到查看列表
  189. $scope.lookFunction = function(data) {
  190. $state.go('tab.incidentHandlerCustomFormDetail', {
  191. "formKey": 'incident_back',
  192. "pdKey": 'incident',
  193. "dataId": data.id,
  194. "taskId": data.taskId,
  195. "processInstanceId": data.processInstanceId
  196. });
  197. };
  198. //页面刷新
  199. $scope.reload = function() {
  200. $scope.refreshListData();
  201. }
  202. //下拉刷新
  203. $scope.doRefresh = function() {
  204. $scope.filterData.idx = 0;
  205. var idx = {
  206. 'idx': $scope.filterData.idx
  207. }
  208. $scope.refreshListData(idx, 'down');
  209. $scope.domore = false;
  210. };
  211. //上拉加载
  212. $scope.loadMore = function() {
  213. //开启上拉加载
  214. $scope.domore = false;
  215. //数据列表加1
  216. $scope.filterData.idx += 1;
  217. $scope.load.pageIndex += 1;
  218. //定时器
  219. var timer = null;
  220. //参数
  221. var filterData = defaultData;
  222. angular.extend(filterData, { 'idx': $scope.filterData.idx });
  223. //加载
  224. if ($scope.load.pageIndex < $scope.load.pageCount) {
  225. api_bpm_domain.fetchtask(pdKey, filterData).then(function(data) {
  226. var myData = Restangular.stripRestangular(data);
  227. if (myData.pageIndex <= myData.pageCount) {
  228. if (angular.isArray(myData.data) && myData.data.length > 0) {
  229. angular.forEach(myData.data, function(item) {
  230. $scope.myData.push(item);
  231. });
  232. }
  233. $scope.$broadcast('scroll.infiniteScrollComplete');
  234. } else {
  235. $scope.domore = true;
  236. $scope.$broadcast('scroll.infiniteScrollComplete');
  237. }
  238. }, function(data) {});
  239. } else {
  240. $scope.domore = true;
  241. $scope.$broadcast('scroll.infiniteScrollComplete');
  242. }
  243. };
  244. //数据加载
  245. $scope.refreshListData = function(filterData, loadStyle) {
  246. //获取本地数据
  247. // var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  248. //对接口参数进行重新组装
  249. // var showData = {
  250. // 'assignee': filterData.assignee,
  251. // // 'idx': filterData.currentPage ? filterData.currentPage - 1 : 0,
  252. // 'idx': filterData.idx,
  253. // 'searchType': filterData.searchType,
  254. // 'status': filterData.status,
  255. // 'sum': filterData.sum,
  256. // };
  257. var showData = {};
  258. if (filterData) {
  259. showData = angular.extend(defaultData, filterData);
  260. } else {
  261. showData = defaultData;
  262. }
  263. // if (filterData.candidateGroups) {
  264. // angular.extend(showData, { 'candidateGroups': filterData.candidateGroups });
  265. // };
  266. //遮罩层开启
  267. $ionicLoading.show({
  268. template: 'Loading...'
  269. });
  270. api_bpm_domain.fetchtask(pdKey, showData).then(function(data) {
  271. var myData = Restangular.stripRestangular(data);
  272. // filterData.count = myData.resultCount;
  273. if (angular.isArray(myData.data) && myData.data.length > 0) {
  274. $scope.myData = myData.data;
  275. $scope.load.pageIndex = myData.pageIndex;
  276. $scope.load.pageCount = myData.pageCount;
  277. if (loadStyle == 'down') {
  278. $scope.$broadcast('scroll.refreshComplete');
  279. }
  280. } else {
  281. // SweetAlert.swal({
  282. // title: "数据为空",
  283. // text: myData.data,
  284. // type: "warning"
  285. // });
  286. // if ($scope.paginationList || $scope.paginationList.count) {
  287. // $scope.paginationList.count = 0;
  288. // }
  289. $scope.listShow = false;
  290. }
  291. //遮罩层关闭
  292. $ionicLoading.hide();
  293. }, function() {
  294. $ionicLoading.hide();
  295. });
  296. }
  297. //事件提取
  298. $scope.acceptTaskAction = function(item) {
  299. var confirmPopup = $ionicPopup.confirm({
  300. title: '事件提取',
  301. template: '是否提取该事件?'
  302. });
  303. confirmPopup.then(function(res) {
  304. // var receiveTask = function(receive_code, item) {
  305. // var data = {
  306. // 'receive_code': receive_code
  307. // };
  308. // if (item) {
  309. // return {
  310. // taskId: item.taskId,
  311. // data: data
  312. // };
  313. // } else {
  314. // return 'error';
  315. // }
  316. // };
  317. // var data = receiveTask($scope.receive_code, item);
  318. if (res) {
  319. api_bpm_domain.claimAndCompletedTask(item.taskId, { userId: loginUser.id, receive_code: "handler" }).then(function(response) {
  320. if (response.status == 200) {
  321. $ionicPopup.alert({
  322. title: '操作成功!',
  323. // template: 'It might taste good'
  324. });
  325. $scope.reload()
  326. confirmPopup.close();
  327. } else if (response.status == 500) {
  328. $ionicPopup.alert({
  329. title: '操作失败!',
  330. template: '该事件已被提取,请刷新页面!'
  331. });
  332. confirmPopup.close();
  333. } else {
  334. $ionicPopup.alert({
  335. title: '操作失败!',
  336. template: '操作失败, 请稍后再试!'
  337. });
  338. confirmPopup.close();
  339. }
  340. });
  341. } else {
  342. }
  343. });
  344. }
  345. //页面加载
  346. // $scope.reload();
  347. //跳转成功刷新页面
  348. $scope.$on('$stateChangeSucess', $scope.reload());
  349. }])
  350. app.controller('handlerExtendCtrl', ['$scope', '$rootScope', '$http', function($scope, $rootScope, $http) {
  351. //判断当前事件状态
  352. if ($scope.item.state.id != null && $scope.item.state.id != 6 && $scope.item.handlerUser != null) {
  353. if ($rootScope.user.id && $rootScope.user.id == $scope.item.handlerUser.id) {
  354. $scope.item.chaozuoPower = true;
  355. } else {
  356. // angular.forEach($rootScope.user.group, function(userItem) {
  357. // angular.forEach($scope.item.handlerUser.group, function(handlerUserItem) {
  358. // if (handlerUserItem == userItem.id) {
  359. // $scope.item.chaozuoPower = true;
  360. // }
  361. // });
  362. // });
  363. }
  364. }
  365. if ($scope.item.state.id != 6 && $scope.item.handlerUser == null) {
  366. $scope.item.tiquPower = true;
  367. }
  368. // if ($scope.item.state.id != null && $scope.item.handlerUser != null) {
  369. // if ($rootScope.user.id == $scope.item.handlerUser.id) {
  370. // $scope.item.chaozuoPower = true;
  371. // }
  372. // }
  373. $scope.look = function() {
  374. $scope.$parent.$parent.$parent.lookFunction($scope.item);
  375. };
  376. $scope.edit = function() {
  377. $scope.$parent.$parent.$parent.editorFunction($scope.item);
  378. };
  379. $scope.handler = function() {
  380. $scope.$parent.$parent.$parent.acceptTaskAction($scope.item);
  381. }
  382. }]);