incidentHandlerCtrl.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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.handlerUser.id) {
  260. // 编辑
  261. $scope.editorFunction(item);
  262. } else {
  263. // 查看详情
  264. $scope.lookFunction(item);
  265. }
  266. } else if (item.state.id != 6 && item.handlerUser == null) {
  267. // 抢单
  268. angular.forEach($rootScope.user.group, function(item) {
  269. if (item.id == item.candidateGroups) {
  270. $scope.acceptTaskAction(item);
  271. }
  272. })
  273. } else {
  274. $scope.lookFunction(item);
  275. }
  276. };
  277. //跳转到编辑列表
  278. $scope.editorFunction = function(data) {
  279. $state.go('tab.incidentHandlerCustomFormIndex', {
  280. taskId: data.taskId,
  281. processInstanceId: data.processInstanceId
  282. });
  283. };
  284. //跳转到查看列表
  285. $scope.lookFunction = function(data) {
  286. $state.go('tab.incidentHandlerCustomFormDetail', {
  287. "formKey": 'incident_back',
  288. "pdKey": 'incident',
  289. "dataId": data.id,
  290. "taskId": data.taskId,
  291. "processInstanceId": data.processInstanceId
  292. });
  293. };
  294. //页面刷新
  295. $scope.reload = function() {
  296. $scope.refreshListData();
  297. }
  298. //下拉刷新
  299. $scope.doRefresh = function() {
  300. $scope.filterData.idx = 0;
  301. var idx = {
  302. 'idx': $scope.filterData.idx
  303. }
  304. $scope.refreshListData(idx, 'down');
  305. $scope.domore = false;
  306. };
  307. $scope.statecolor = function(myData) {
  308. angular.forEach(myData, function(item, index) {
  309. if (item.state.id == 2) {
  310. myData[index].statecolor = "state-wrap-basetwo"
  311. } else if (item.state.id == 3) {
  312. myData[index].statecolor = "state-wrap-basethree"
  313. } else if (item.state.id == 4) {
  314. myData[index].statecolor = "state-wrap-basefour"
  315. } else if (item.state.id == 5) {
  316. myData[index].statecolor = "state-wrap-baseone"
  317. } else if (item.state.id == 6) {
  318. myData[index].statecolor = "state-wrap-basetwo"
  319. } else if (item.state.id == 7) {
  320. myData[index].statecolor = "state-wrap-basethree"
  321. }
  322. });
  323. }
  324. //上拉加载
  325. $scope.loadMore = function() {
  326. //开启上拉加载
  327. $scope.domore = false;
  328. //数据列表加1
  329. // $scope.filterData.idx += 1;
  330. $scope.load.pageIndex += 1;
  331. //定时器
  332. var timer = null;
  333. //参数
  334. var filterData = $scope.defaultData;
  335. angular.extend(filterData, { 'idx': $scope.load.pageIndex });
  336. //加载
  337. if ($scope.load.pageIndex < $scope.load.pageCount) {
  338. api_bpm_domain.fetchtask(pdKey, filterData).then(function(data) {
  339. var myData = Restangular.stripRestangular(data);
  340. $scope.statecolor(myData.data);
  341. if (angular.isArray(myData.data) && myData.data.length > 0) {
  342. angular.forEach(myData.data, function(item) {
  343. $scope.myData.push(item);
  344. });
  345. $scope.$broadcast('scroll.infiniteScrollComplete');
  346. } else {
  347. $scope.domore = true;
  348. $scope.$broadcast('scroll.infiniteScrollComplete');
  349. }
  350. }, function(data) {});
  351. } else {
  352. $scope.domore = true;
  353. $scope.$broadcast('scroll.infiniteScrollComplete');
  354. }
  355. };
  356. //数据加载
  357. $scope.isgetdata = true;
  358. $scope.refreshListData = function(filterData, loadStyle) {
  359. $scope.isgetdata = false;
  360. //获取本地数据
  361. // var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
  362. //对接口参数进行重新组装
  363. // var showData = {
  364. // 'assignee': filterData.assignee,
  365. // // 'idx': filterData.currentPage ? filterData.currentPage - 1 : 0,
  366. // 'idx': filterData.idx,
  367. // 'searchType': filterData.searchType,
  368. // 'status': filterData.status,
  369. // 'sum': filterData.sum,
  370. // };
  371. var showData = {};
  372. var defaultData = {
  373. 'assignee': loginUser.id,
  374. 'idx': 0,
  375. 'sum': 10,
  376. 'candidateGroups': loginUser.group["0"].id,
  377. 'searchType':'todo'
  378. };
  379. if (filterData) {
  380. showData = angular.extend(defaultData, filterData);
  381. } else {
  382. showData = defaultData;
  383. }
  384. // if (filterData.candidateGroups) {
  385. // angular.extend(showData, { 'candidateGroups': filterData.candidateGroups });
  386. // };
  387. //遮罩层开启
  388. $ionicLoading.show({
  389. template: 'Loading...'
  390. });
  391. $scope.defaultData = showData;
  392. api_bpm_domain.fetchtask(pdKey, showData).then(function(data) {
  393. var myData = Restangular.stripRestangular(data);
  394. $scope.statecolor(myData.data);
  395. // filterData.count = myData.resultCount;
  396. // if (angular.isArray(myData.data) && myData.data.length > 0) {
  397. if (angular.isArray(myData.data)) {
  398. $scope.myData = myData.data;
  399. $scope.load.pageIndex = myData.pageIndex;
  400. $scope.load.pageCount = myData.pageCount;
  401. if (loadStyle == 'down') {
  402. $scope.$broadcast('scroll.refreshComplete');
  403. }
  404. } else {
  405. // SweetAlert.swal({
  406. // title: "数据为空",
  407. // text: myData.data,
  408. // type: "warning"
  409. // });
  410. // if ($scope.paginationList || $scope.paginationList.count) {
  411. // $scope.paginationList.count = 0;
  412. // }
  413. $scope.listShow = false;
  414. }
  415. $scope.domore = false;
  416. $scope.isgetdata = true;
  417. //遮罩层关闭
  418. $ionicLoading.hide();
  419. }, function() {
  420. $ionicLoading.hide();
  421. });
  422. }
  423. //事件提取
  424. $scope.acceptTaskAction = function(item) {
  425. var confirmPopup = $ionicPopup.confirm({
  426. title: '抢单',
  427. template: '是否抢单?',
  428. cancelText: '取消',
  429. okText: '确认'
  430. });
  431. confirmPopup.then(function(res) {
  432. // var receiveTask = function(receive_code, item) {
  433. // var data = {
  434. // 'receive_code': receive_code
  435. // };
  436. // if (item) {
  437. // return {
  438. // taskId: item.taskId,
  439. // data: data
  440. // };
  441. // } else {
  442. // return 'error';
  443. // }
  444. // };
  445. // var data = receiveTask($scope.receive_code, item);
  446. if (res) {
  447. api_bpm_domain.claimAndCompletedTask(item.taskId, { userId: loginUser.id, receive_code: "handler" }).then(function(response) {
  448. if (response.status == 200) {
  449. // $scope.reload()
  450. item.tiquPower = false;
  451. item.chaozuoPower = true;
  452. $ionicPopup.alert({
  453. title: '操作成功!',
  454. // template: 'It might taste good'
  455. okText: '确认'
  456. });
  457. confirmPopup.close();
  458. } else if (response.status == 500) {
  459. $ionicPopup.alert({
  460. title: '操作失败!',
  461. template: '该单已被抢,请刷新页面!',
  462. okText: '确认'
  463. });
  464. confirmPopup.close();
  465. } else {
  466. $ionicPopup.alert({
  467. title: '操作失败!',
  468. template: '操作失败, 请稍后再试!',
  469. okText: '确认'
  470. });
  471. confirmPopup.close();
  472. }
  473. });
  474. } else {
  475. }
  476. });
  477. }
  478. //页面加载
  479. // $scope.reload();
  480. //跳转成功刷新页面
  481. // $scope.$on('$stateChangeSucess', $scope.reload());
  482. if (!sessionStorage.sessionLogin) {
  483. var promise = getLoginUser.query();
  484. promise.then(function(sessionLogin) { //返回成功
  485. $scope.tokenType = sessionLogin.tokenType;
  486. var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
  487. var loginUser = sessionLogin.user;
  488. $scope.sessionLogin = sessionLogin
  489. $rootScope.user = sessionLogin.user;
  490. $scope.defaultData = {
  491. 'assignee': loginUser.id,
  492. 'idx': 0,
  493. 'sum': 10,
  494. 'candidateGroups': loginUser.group["0"].id
  495. };
  496. $scope.filterData = {
  497. 'assignee': loginUser.id,
  498. 'idx': 0,
  499. 'sum': 10,
  500. };
  501. $scope.reload()
  502. }, function(data) { //返回失败
  503. });
  504. } else {
  505. var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
  506. var loginUser = sessionLogin.user;
  507. $scope.sessionLogin = sessionLogin
  508. $rootScope.user = sessionLogin.user;
  509. $scope.defaultData = {
  510. 'assignee': loginUser.id,
  511. 'idx': 0,
  512. 'sum': 10,
  513. 'candidateGroups': loginUser.group["0"].id
  514. };
  515. $scope.filterData = {
  516. 'assignee': loginUser.id,
  517. 'idx': 0,
  518. 'sum': 10,
  519. };
  520. $scope.reload()
  521. }
  522. }])
  523. app.controller('handlerExtendCtrl', ['$scope', '$rootScope', '$http', function($scope, $rootScope, $http) {
  524. //判断当前事件状态
  525. // if ($scope.item.state.id != null && $scope.item.state.id != 6 && $scope.item.handlerUser != null) {
  526. // if ($rootScope.user.id && $rootScope.user.id == $scope.item.handlerUser.id) {
  527. // $scope.item.chaozuoPower = true;
  528. // } else {
  529. // // angular.forEach($rootScope.user.group, function(userItem) {
  530. // // angular.forEach($scope.item.handlerUser.group, function(handlerUserItem) {
  531. // // if (handlerUserItem == userItem.id) {
  532. // // $scope.item.chaozuoPower = true;
  533. // // }
  534. // // });
  535. // // });
  536. // }
  537. // }
  538. // if ($scope.item.state.id != 6 && $scope.item.handlerUser == null) {
  539. // $scope.item.tiquPower = true;
  540. // }
  541. //判断当前事件状态
  542. if ($scope.item.state.id != null && $scope.item.handlerUser != null) {
  543. if ($rootScope.user.id == $scope.item.handlerUser.id) {
  544. $scope.item.chaozuoPower = true;
  545. }
  546. }
  547. if ($scope.item.state.id != 6 && $scope.item.handlerUser == null) {
  548. angular.forEach($rootScope.user.group, function(item) {
  549. if (item.id == $scope.item.candidateGroups) {
  550. $scope.item.tiquPower = true;
  551. }
  552. })
  553. }
  554. // if ($scope.item.state.id != null && $scope.item.handlerUser != null) {
  555. // if ($rootScope.user.id == $scope.item.handlerUser.id) {
  556. // $scope.item.chaozuoPower = true;
  557. // }
  558. // }
  559. $scope.look = function() {
  560. $scope.$parent.$parent.$parent.lookFunction($scope.item);
  561. };
  562. $scope.edit = function() {
  563. $scope.$parent.$parent.$parent.editorFunction($scope.item);
  564. };
  565. $scope.handler = function() {
  566. $scope.$parent.$parent.$parent.acceptTaskAction($scope.item);
  567. }
  568. }]);