incidentHandlerCtrl.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. app.controller('incidentHandlerCtrl', ["$rootScope", "$scope", '$stateParams', '$http', '$aside', '$state', '$timeout', '$ionicPopover', '$ionicPopup', '$ionicLoading', '$ionicScrollDelegate', 'api_bpm_domain', 'Restangular', 'loginService', 'getLoginUser', function($rootScope, $scope, $stateParams, $http, $aside, $state, $timeout, $ionicPopover, $ionicPopup, $ionicLoading, $ionicScrollDelegate, 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', active: false },
  56. { status: 'todo', label: '待处理', idName: 'b', active: true },
  57. { status: 'create', label: '我创建', idName: 'c', active: false },
  58. { status: 'done', label: '已处理', idName: 'd', active: false },
  59. // { status: 's', label: '已驳回', idName: 'e' },
  60. // { status: '6', label: '已拒绝', idName: 'f' }
  61. ];
  62. $scope.searchTypeFunction = function(searchType) {
  63. $ionicScrollDelegate.scrollTop();
  64. angular.forEach($scope.statuses, function(item) {
  65. if (searchType == item.status) {
  66. item.active = true;
  67. } else {
  68. item.active = false;
  69. }
  70. })
  71. $scope.refreshListData({
  72. 'searchType': searchType,
  73. 'idx': 0,
  74. });
  75. $scope.popover.hide();
  76. }
  77. // 一个精心制作的自定义弹窗
  78. // var myPopup = $ionicPopup.show({
  79. // template: '<input type="password" ng-model="data.wifi">',
  80. // title: 'Enter Wi-Fi Password',
  81. // subTitle: 'Please use normal things',
  82. // scope: $scope,
  83. // buttons: [
  84. // { text: 'Cancel' },
  85. // {
  86. // text: '<b>Save</b>',
  87. // type: 'button-positive',
  88. // onTap: function(e) {
  89. // if (!$scope.data.wifi) {
  90. // //不允许用户关闭,除非他键入wifi密码
  91. // e.preventDefault();
  92. // } else {
  93. // return $scope.data.wifi;
  94. // }
  95. // }
  96. // },
  97. // ]
  98. // });
  99. // myPopup.then(function(res) {
  100. // console.log('Tapped!', res);
  101. // });
  102. // $timeout(function() {
  103. // myPopup.close(); //由于某种原因3秒后关闭弹出
  104. // }, 3000);
  105. //状态选择
  106. $scope.searchstate = { status: 'todo', label: '待处理', idName: 'b', active: true };
  107. $scope.inputclick = function() {
  108. var modalInstance = $aside.open({
  109. templateUrl: 'assets/views/customform/tpl/bottomlist.html',
  110. placement: 'bottom',
  111. backdrop: true,
  112. controller: function($scope, $modalInstance, scope) {
  113. $scope.statuses = [
  114. { status: 'all', label: '全部', idName: 'a', active: false },
  115. { status: 'todo', label: '待处理', idName: 'b', active: true },
  116. { status: 'create', label: '我创建', idName: 'c', active: false },
  117. { status: 'done', label: '已处理', idName: 'd', active: false },
  118. ];
  119. $scope.ok = function(item) {
  120. $modalInstance.close(item);
  121. }
  122. $scope.cancel = function() {
  123. $modalInstance.dismiss('cancel');
  124. }
  125. },
  126. size: 'sm',
  127. resolve: {
  128. scope: function() {
  129. return $scope;
  130. }
  131. }
  132. });
  133. modalInstance.result.then(function(selectedItem) {
  134. $ionicScrollDelegate.scrollTop();
  135. $scope.searchstate = selectedItem;
  136. angular.forEach($scope.statuses, function(item) {
  137. if (selectedItem.status == item.status) {
  138. item.active = true;
  139. } else {
  140. item.active = false;
  141. }
  142. })
  143. if (selectedItem.status == "done") {
  144. $scope.refreshListData({
  145. 'searchType': "all",
  146. incident: { statusId: "resolved" },
  147. 'idx': 0
  148. });
  149. } else {
  150. $scope.refreshListData({
  151. 'searchType': selectedItem.status,
  152. 'idx': 0
  153. });
  154. }
  155. });
  156. }
  157. // 一个确认对话框
  158. $scope.showConfirm = function() {
  159. var confirmPopup = $ionicPopup.confirm({
  160. title: 'Consume Ice Cream',
  161. template: 'Are you sure you want to eat this ice cream?'
  162. });
  163. confirmPopup.then(function(res) {
  164. if (res) {
  165. console.log('You are sure');
  166. } else {
  167. console.log('You are not sure');
  168. }
  169. });
  170. };
  171. // 一个提示对话框
  172. $scope.showAlert = function() {
  173. var alertPopup = $ionicPopup.alert({
  174. title: 'Don\'t eat that!',
  175. template: 'It might taste good'
  176. });
  177. alertPopup.then(function(res) {
  178. console.log('Thank you for not eating my delicious ice cream cone');
  179. });
  180. };
  181. // $scope.loginForm = {};
  182. // var loginUser = $rootScope.user;
  183. //获取login中的数据
  184. // var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
  185. // var loginUser = sessionLogin.user;
  186. // $rootScope.user = sessionLogin.user;
  187. //定义流程代号
  188. // var pdKey = $state.current.pdKey;
  189. var pdKey = 'bpm_incident';
  190. // var incidentListMobileParameter = {
  191. // 'assignee': loginUser.id,
  192. // 'idx': 0,
  193. // 'sum': 10,
  194. // 'status': '',
  195. // 'count': 0,
  196. // 'currentPage': 1,
  197. // 'endPage': 0,
  198. // 'pages': []
  199. // };
  200. //默认数据
  201. // var defaultData = {
  202. // 'assignee': loginUser.id,
  203. // 'idx': 0,
  204. // 'sum': 10,
  205. // 'candidateGroups': loginUser.group["0"].id
  206. // };
  207. //页面数据容器
  208. $scope.myData = [];
  209. //是否加载上拉刷新
  210. $scope.domore = false;
  211. //填充数据
  212. // $scope.filterData = {
  213. // 'assignee': loginUser.id,
  214. // 'idx': 0,
  215. // 'sum': 10,
  216. // };
  217. //本地数据初始化
  218. // sessionStorage.incidentListMobileParameter = JSON.stringify(incidentListMobileParameter);
  219. //新增数据
  220. $scope.addData = function() {
  221. var roleMan = false;
  222. if ($rootScope.user.role || $rootScope.user.role != null) {
  223. for (var i in $rootScope.user.role) {
  224. 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) {
  225. roleMan = true;
  226. break;
  227. }
  228. }
  229. }
  230. if (roleMan) {
  231. $state.go('tab.incidentHandlerNew', {
  232. // pdKey: 'bpm_incident'
  233. })
  234. } else {
  235. $ionicPopup.alert({
  236. title: '没有访问权限',
  237. // template: 'It might taste good'
  238. okText: '确认'
  239. });
  240. }
  241. // $state.go('tab.incidentHandlerNew', {
  242. // // pdKey: 'bpm_incident'
  243. // })
  244. };
  245. // if ($scope.item.state.id != null && $scope.item.handlerUser != null) {
  246. // if ($rootScope.user.id == $scope.item.handlerUser.id) {
  247. // $scope.item.chaozuoPower = true;
  248. // }
  249. // }
  250. // if ($scope.item.state.id != 6 && $scope.item.handlerUser == null) {
  251. // angular.forEach($rootScope.user.group, function(item) {
  252. // if (item.id == $scope.item.candidateGroups) {
  253. // $scope.item.tiquPower = true;
  254. // }
  255. // })
  256. // }
  257. $scope.look = function(item) {
  258. if (item.state.id != null && item.handlerUser != null) {
  259. if ($rootScope.user.id == item.handlingPersonnelUser.id) {
  260. $scope.editorFunction(item);
  261. } else {
  262. $scope.lookFunction(item);
  263. }
  264. } else if (item.state.id != 6 && item.handlerUser == null) {
  265. angular.forEach($rootScope.user.group, function(item) {
  266. if (item.id == item.candidateGroups) {
  267. $scope.acceptTaskAction(item);
  268. }
  269. })
  270. } else {
  271. $scope.lookFunction(item);
  272. }
  273. };
  274. //跳转到编辑列表
  275. $scope.editorFunction = function(data) {
  276. $state.go('tab.incidentHandlerCustomFormIndex', {
  277. taskId: data.taskId,
  278. processInstanceId: data.processInstanceId
  279. });
  280. };
  281. //跳转到查看列表
  282. $scope.lookFunction = function(data) {
  283. $state.go('tab.incidentHandlerCustomFormDetail', {
  284. "formKey": 'incident_back',
  285. "pdKey": 'incident',
  286. "dataId": data.id,
  287. "taskId": data.taskId,
  288. "processInstanceId": data.processInstanceId
  289. });
  290. };
  291. //页面刷新
  292. $scope.reload = function() {
  293. $scope.refreshListData();
  294. }
  295. //下拉刷新
  296. $scope.doRefresh = function() {
  297. $scope.filterData.idx = 0;
  298. var idx = {
  299. 'idx': $scope.filterData.idx
  300. }
  301. $scope.refreshListData(idx, 'down');
  302. $scope.domore = false;
  303. };
  304. $scope.statecolor = function(myData) {
  305. angular.forEach(myData, function(item, index) {
  306. if (item.state.id == 2) {
  307. myData[index].statecolor = "state-wrap-basetwo"
  308. } else if (item.state.id == 3) {
  309. myData[index].statecolor = "state-wrap-basethree"
  310. } else if (item.state.id == 4) {
  311. myData[index].statecolor = "state-wrap-basefour"
  312. } else if (item.state.id == 5) {
  313. myData[index].statecolor = "state-wrap-baseone"
  314. } else if (item.state.id == 6) {
  315. myData[index].statecolor = "state-wrap-basetwo"
  316. } else if (item.state.id == 7) {
  317. myData[index].statecolor = "state-wrap-basethree"
  318. }
  319. });
  320. }
  321. //上拉加载
  322. $scope.loadMore = function() {
  323. //开启上拉加载
  324. $scope.domore = false;
  325. //数据列表加1
  326. // $scope.filterData.idx += 1;
  327. $scope.load.pageIndex += 1;
  328. //定时器
  329. var timer = null;
  330. //参数
  331. var filterData = $scope.defaultData;
  332. angular.extend(filterData, { 'idx': $scope.load.pageIndex });
  333. //加载
  334. if ($scope.load.pageIndex < $scope.load.pageCount) {
  335. api_bpm_domain.fetchtask(pdKey, filterData).then(function(data) {
  336. var myData = Restangular.stripRestangular(data);
  337. $scope.statecolor(myData.data);
  338. if (angular.isArray(myData.data) && myData.data.length > 0) {
  339. angular.forEach(myData.data, function(item) {
  340. $scope.myData.push(item);
  341. });
  342. $scope.$broadcast('scroll.infiniteScrollComplete');
  343. } else {
  344. $scope.domore = true;
  345. $scope.$broadcast('scroll.infiniteScrollComplete');
  346. }
  347. }, function(data) {});
  348. } else {
  349. $scope.domore = true;
  350. $scope.$broadcast('scroll.infiniteScrollComplete');
  351. }
  352. };
  353. //数据加载
  354. $scope.isgetdata = true;
  355. $scope.refreshListData = function(filterData, loadStyle) {
  356. $scope.isgetdata = false;
  357. //获取本地数据
  358. // var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  359. //对接口参数进行重新组装
  360. // var showData = {
  361. // 'assignee': filterData.assignee,
  362. // // 'idx': filterData.currentPage ? filterData.currentPage - 1 : 0,
  363. // 'idx': filterData.idx,
  364. // 'searchType': filterData.searchType,
  365. // 'status': filterData.status,
  366. // 'sum': filterData.sum,
  367. // };
  368. var showData = {};
  369. var defaultData = {
  370. 'assignee': loginUser.id,
  371. 'idx': 0,
  372. 'sum': 10,
  373. // 'candidateGroups': loginUser.group["0"].id
  374. 'candidateGroups': 0
  375. };
  376. if (filterData) {
  377. showData = angular.extend(defaultData, filterData);
  378. } else {
  379. showData = defaultData;
  380. }
  381. // if (filterData.candidateGroups) {
  382. // angular.extend(showData, { 'candidateGroups': filterData.candidateGroups });
  383. // };
  384. //遮罩层开启
  385. $ionicLoading.show({
  386. template: 'Loading...'
  387. });
  388. $scope.defaultData = showData;
  389. api_bpm_domain.fetchtask(pdKey, showData).then(function(data) {
  390. var myData = Restangular.stripRestangular(data);
  391. $scope.statecolor(myData.data);
  392. // filterData.count = myData.resultCount;
  393. // if (angular.isArray(myData.data) && myData.data.length > 0) {
  394. if (angular.isArray(myData.data)) {
  395. $scope.myData = myData.data;
  396. $scope.load.pageIndex = myData.pageIndex;
  397. $scope.load.pageCount = myData.pageCount;
  398. if (loadStyle == 'down') {
  399. $scope.$broadcast('scroll.refreshComplete');
  400. }
  401. } else {
  402. // SweetAlert.swal({
  403. // title: "数据为空",
  404. // text: myData.data,
  405. // type: "warning"
  406. // });
  407. // if ($scope.paginationList || $scope.paginationList.count) {
  408. // $scope.paginationList.count = 0;
  409. // }
  410. $scope.listShow = false;
  411. }
  412. $scope.domore = false;
  413. $scope.isgetdata = true;
  414. //遮罩层关闭
  415. $ionicLoading.hide();
  416. }, function() {
  417. $ionicLoading.hide();
  418. });
  419. }
  420. //事件提取
  421. $scope.acceptTaskAction = function(item) {
  422. var confirmPopup = $ionicPopup.confirm({
  423. title: '抢单',
  424. template: '是否抢单?',
  425. cancelText: '取消',
  426. okText: '确认'
  427. });
  428. confirmPopup.then(function(res) {
  429. // var receiveTask = function(receive_code, item) {
  430. // var data = {
  431. // 'receive_code': receive_code
  432. // };
  433. // if (item) {
  434. // return {
  435. // taskId: item.taskId,
  436. // data: data
  437. // };
  438. // } else {
  439. // return 'error';
  440. // }
  441. // };
  442. // var data = receiveTask($scope.receive_code, item);
  443. if (res) {
  444. api_bpm_domain.claimAndCompletedTask(item.taskId, { userId: loginUser.id, receive_code: "handler" }).then(function(response) {
  445. if (response.status == 200) {
  446. // $scope.reload()
  447. item.tiquPower = false;
  448. item.chaozuoPower = true;
  449. $ionicPopup.alert({
  450. title: '操作成功!',
  451. // template: 'It might taste good'
  452. okText: '确认'
  453. });
  454. confirmPopup.close();
  455. } else if (response.status == 500) {
  456. $ionicPopup.alert({
  457. title: '操作失败!',
  458. template: '该单已被抢,请刷新页面!',
  459. okText: '确认'
  460. });
  461. confirmPopup.close();
  462. } else {
  463. $ionicPopup.alert({
  464. title: '操作失败!',
  465. template: '操作失败, 请稍后再试!',
  466. okText: '确认'
  467. });
  468. confirmPopup.close();
  469. }
  470. });
  471. } else {
  472. }
  473. });
  474. }
  475. //页面加载
  476. // $scope.reload();
  477. //跳转成功刷新页面
  478. // $scope.$on('$stateChangeSucess', $scope.reload());
  479. if (!sessionStorage.sessionLogin) {
  480. var promise = getLoginUser.query();
  481. promise.then(function(sessionLogin) { //返回成功
  482. $scope.tokenType = sessionLogin.tokenType;
  483. var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
  484. var loginUser = sessionLogin.user;
  485. $scope.sessionLogin = sessionLogin
  486. $rootScope.user = sessionLogin.user;
  487. $scope.defaultData = {
  488. 'assignee': loginUser.id,
  489. 'idx': 0,
  490. 'sum': 10,
  491. // 'candidateGroups': loginUser.group["0"].id
  492. 'candidateGroups': 0
  493. };
  494. $scope.filterData = {
  495. 'assignee': loginUser.id,
  496. 'idx': 0,
  497. 'sum': 10,
  498. };
  499. $scope.reload()
  500. }, function(data) { //返回失败
  501. });
  502. } else {
  503. var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
  504. var loginUser = sessionLogin.user;
  505. $scope.sessionLogin = sessionLogin
  506. $rootScope.user = sessionLogin.user;
  507. $scope.defaultData = {
  508. 'assignee': loginUser.id,
  509. 'idx': 0,
  510. 'sum': 10,
  511. // 'candidateGroups': loginUser.group["0"].id
  512. 'candidateGroups': 0
  513. };
  514. $scope.filterData = {
  515. 'assignee': loginUser.id,
  516. 'idx': 0,
  517. 'sum': 10,
  518. };
  519. $scope.reload()
  520. }
  521. }])
  522. app.controller('handlerExtendCtrl', ['$scope', '$rootScope', '$http', function($scope, $rootScope, $http) {
  523. //判断当前事件状态
  524. // if ($scope.item.state.id != null && $scope.item.state.id != 6 && $scope.item.handlerUser != null) {
  525. // if ($rootScope.user.id && $rootScope.user.id == $scope.item.handlerUser.id) {
  526. // $scope.item.chaozuoPower = true;
  527. // } else {
  528. // // angular.forEach($rootScope.user.group, function(userItem) {
  529. // // angular.forEach($scope.item.handlerUser.group, function(handlerUserItem) {
  530. // // if (handlerUserItem == userItem.id) {
  531. // // $scope.item.chaozuoPower = true;
  532. // // }
  533. // // });
  534. // // });
  535. // }
  536. // }
  537. // if ($scope.item.state.id != 6 && $scope.item.handlerUser == null) {
  538. // $scope.item.tiquPower = true;
  539. // }
  540. //判断当前事件状态
  541. if ($scope.item.state.id != null && $scope.item.handlerUser != null) {
  542. if ($rootScope.user.id == $scope.item.handlerUser.id) {
  543. $scope.item.chaozuoPower = true;
  544. }
  545. }
  546. if ($scope.item.state.id != 6 && $scope.item.handlerUser == null) {
  547. angular.forEach($rootScope.user.group, function(item) {
  548. if (item.id == $scope.item.candidateGroups) {
  549. $scope.item.tiquPower = true;
  550. }
  551. })
  552. }
  553. // if ($scope.item.state.id != null && $scope.item.handlerUser != null) {
  554. // if ($rootScope.user.id == $scope.item.handlerUser.id) {
  555. // $scope.item.chaozuoPower = true;
  556. // }
  557. // }
  558. $scope.look = function() {
  559. $scope.$parent.$parent.$parent.lookFunction($scope.item);
  560. };
  561. $scope.edit = function() {
  562. $scope.$parent.$parent.$parent.editorFunction($scope.item);
  563. };
  564. $scope.handler = function() {
  565. $scope.$parent.$parent.$parent.acceptTaskAction($scope.item);
  566. }
  567. }]);