123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643 |
- 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) {
- console.log('incidentHandlerCtrl is load');
- //弹出框
- // .fromTemplate() method
- // 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>';
- // $scope.popover = $ionicPopover.fromTemplate(template, {
- // scope: $scope
- // });
- // .fromTemplateUrl() method
- // var promise = getLoginUser.query(); // 同步调用,获得承诺接口
- // promise.then(function(data) { // 调用承诺API获取数据 .resolve
- // // $scope.user = data;
- // console.log(data)
- // }, function(data) { // 处理错误 .reject
- // // $scope.user = {error: '用户不存在!'};
- // console.log(data)
- // });
- $scope.goBack = function() {
- history.go(-1);
- }
- $scope.newFunction = function() {
- $state.go('tab.customFormIndex', {
- 'formKey': 'requestMobileEditor'
- });
- };
- $scope.load = {
- 'pageIndex': 0, //第几页
- 'pageSum': 10, //每页条数
- 'pageCount': 0 //总页数
- };
- $ionicPopover.fromTemplateUrl('assets/views/weChat/myIncident/popover.html', {
- scope: $scope
- }).then(function(popover) {
- $scope.popover = popover;
- });
- $scope.openPopover = function($event) {
- $scope.popover.show($event);
- };
- $scope.closePopover = function() {
- $scope.popover.hide();
- };
- //Cleanup the popover when we're done with it!
- $scope.$on('$destroy', function() {
- $scope.popover.remove();
- });
- // Execute action on hidden popover
- $scope.$on('popover.hidden', function(res) {
- // Execute action
- });
- // Execute action on remove popover
- $scope.$on('popover.removed', function() {
- // Execute action
- });
- $scope.statuses = [
- { status: 'all', label: '全部', idName: 'a', active: false },
- { status: 'todo', label: '待处理', idName: 'b', active: true },
- { status: 'create', label: '我创建', idName: 'c', active: false },
- { status: 'done', label: '已处理', idName: 'd', active: false },
- // { status: 's', label: '已驳回', idName: 'e' },
- // { status: '6', label: '已拒绝', idName: 'f' }
- ];
- $scope.searchTypeFunction = function(searchType) {
- $ionicScrollDelegate.scrollTop();
- angular.forEach($scope.statuses, function(item) {
- if (searchType == item.status) {
- item.active = true;
- } else {
- item.active = false;
- }
- })
- $scope.refreshListData({
- 'searchType': searchType,
- 'idx': 0,
- });
- $scope.popover.hide();
- }
- // 一个精心制作的自定义弹窗
- // var myPopup = $ionicPopup.show({
- // template: '<input type="password" ng-model="data.wifi">',
- // title: 'Enter Wi-Fi Password',
- // subTitle: 'Please use normal things',
- // scope: $scope,
- // buttons: [
- // { text: 'Cancel' },
- // {
- // text: '<b>Save</b>',
- // type: 'button-positive',
- // onTap: function(e) {
- // if (!$scope.data.wifi) {
- // //不允许用户关闭,除非他键入wifi密码
- // e.preventDefault();
- // } else {
- // return $scope.data.wifi;
- // }
- // }
- // },
- // ]
- // });
- // myPopup.then(function(res) {
- // console.log('Tapped!', res);
- // });
- // $timeout(function() {
- // myPopup.close(); //由于某种原因3秒后关闭弹出
- // }, 3000);
- //状态选择
- $scope.searchstate = { status: 'todo', label: '待处理', idName: 'b', active: true };
- $scope.inputclick = function() {
- var modalInstance = $aside.open({
- templateUrl: 'assets/views/customform/tpl/bottomlist.html',
- placement: 'bottom',
- backdrop: true,
- controller: function($scope, $modalInstance, scope) {
- $scope.statuses = [
- { status: 'all', label: '全部', idName: 'a', active: false },
- { status: 'todo', label: '待处理', idName: 'b', active: true },
- { status: 'create', label: '我创建', idName: 'c', active: false },
- { status: 'done', label: '已处理', idName: 'd', active: false },
- ];
- $scope.ok = function(item) {
- $modalInstance.close(item);
- }
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- }
- },
- size: 'sm',
- resolve: {
- scope: function() {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function(selectedItem) {
- $ionicScrollDelegate.scrollTop();
- $scope.searchstate = selectedItem;
- angular.forEach($scope.statuses, function(item) {
- if (selectedItem.status == item.status) {
- item.active = true;
- } else {
- item.active = false;
- }
- })
- if (selectedItem.status == "done") {
- $scope.refreshListData({
- 'searchType': "all",
- incident: { statusId: "resolved" },
- 'idx': 0
- });
- } else {
- $scope.refreshListData({
- 'searchType': selectedItem.status,
- 'idx': 0
- });
- }
- });
- }
- // 一个确认对话框
- $scope.showConfirm = function() {
- var confirmPopup = $ionicPopup.confirm({
- title: 'Consume Ice Cream',
- template: 'Are you sure you want to eat this ice cream?'
- });
- confirmPopup.then(function(res) {
- if (res) {
- console.log('You are sure');
- } else {
- console.log('You are not sure');
- }
- });
- };
- // 一个提示对话框
- $scope.showAlert = function() {
- var alertPopup = $ionicPopup.alert({
- title: 'Don\'t eat that!',
- template: 'It might taste good'
- });
- alertPopup.then(function(res) {
- console.log('Thank you for not eating my delicious ice cream cone');
- });
- };
- // $scope.loginForm = {};
- // var loginUser = $rootScope.user;
- //获取login中的数据
- // var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
- // var loginUser = sessionLogin.user;
- // $rootScope.user = sessionLogin.user;
- //定义流程代号
- // var pdKey = $state.current.pdKey;
- var pdKey = 'bpm_incident';
- // var incidentListMobileParameter = {
- // 'assignee': loginUser.id,
- // 'idx': 0,
- // 'sum': 10,
- // 'status': '',
- // 'count': 0,
- // 'currentPage': 1,
- // 'endPage': 0,
- // 'pages': []
- // };
- //默认数据
- // var defaultData = {
- // 'assignee': loginUser.id,
- // 'idx': 0,
- // 'sum': 10,
- // 'candidateGroups': loginUser.group["0"].id
- // };
- //页面数据容器
- $scope.myData = [];
- //是否加载上拉刷新
- $scope.domore = false;
- //填充数据
- // $scope.filterData = {
- // 'assignee': loginUser.id,
- // 'idx': 0,
- // 'sum': 10,
- // };
- //本地数据初始化
- // sessionStorage.incidentListMobileParameter = JSON.stringify(incidentListMobileParameter);
- //新增数据
- $scope.addData = function() {
- var roleMan = false;
- if ($rootScope.user.role || $rootScope.user.role != null) {
- for (var i in $rootScope.user.role) {
- 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) {
- roleMan = true;
- break;
- }
- }
- }
- if (roleMan) {
- $state.go('tab.incidentHandlerNew', {
- // pdKey: 'bpm_incident'
- })
- } else {
- $ionicPopup.alert({
- title: '没有访问权限',
- // template: 'It might taste good'
- okText: '确认'
- });
- }
- // $state.go('tab.incidentHandlerNew', {
- // // pdKey: 'bpm_incident'
- // })
- };
- // if ($scope.item.state.id != null && $scope.item.handlerUser != null) {
- // if ($rootScope.user.id == $scope.item.handlerUser.id) {
- // $scope.item.chaozuoPower = true;
- // }
- // }
- // if ($scope.item.state.id != 6 && $scope.item.handlerUser == null) {
- // angular.forEach($rootScope.user.group, function(item) {
- // if (item.id == $scope.item.candidateGroups) {
- // $scope.item.tiquPower = true;
- // }
- // })
- // }
- $scope.look = function(item) {
- if (item.state.id != null && item.handlerUser != null) {
- if ($rootScope.user.id == item.handlingPersonnelUser.id) {
- $scope.editorFunction(item);
- } else {
- $scope.lookFunction(item);
- }
- } else if (item.state.id != 6 && item.handlerUser == null) {
- angular.forEach($rootScope.user.group, function(item) {
- if (item.id == item.candidateGroups) {
- $scope.acceptTaskAction(item);
- }
- })
- } else {
- $scope.lookFunction(item);
- }
- };
- //跳转到编辑列表
- $scope.editorFunction = function(data) {
- $state.go('tab.incidentHandlerCustomFormIndex', {
- taskId: data.taskId,
- processInstanceId: data.processInstanceId
- });
- };
- //跳转到查看列表
- $scope.lookFunction = function(data) {
- $state.go('tab.incidentHandlerCustomFormDetail', {
- "formKey": 'incident_back',
- "pdKey": 'incident',
- "dataId": data.id,
- "taskId": data.taskId,
- "processInstanceId": data.processInstanceId
- });
- };
- //页面刷新
- $scope.reload = function() {
- $scope.refreshListData();
- }
- //下拉刷新
- $scope.doRefresh = function() {
- $scope.filterData.idx = 0;
- var idx = {
- 'idx': $scope.filterData.idx
- }
- $scope.refreshListData(idx, 'down');
- $scope.domore = false;
- };
- $scope.statecolor = function(myData) {
- angular.forEach(myData, function(item, index) {
- if (item.state.id == 2) {
- myData[index].statecolor = "state-wrap-basetwo"
- } else if (item.state.id == 3) {
- myData[index].statecolor = "state-wrap-basethree"
- } else if (item.state.id == 4) {
- myData[index].statecolor = "state-wrap-basefour"
- } else if (item.state.id == 5) {
- myData[index].statecolor = "state-wrap-baseone"
- } else if (item.state.id == 6) {
- myData[index].statecolor = "state-wrap-basetwo"
- } else if (item.state.id == 7) {
- myData[index].statecolor = "state-wrap-basethree"
- }
- });
- }
- //上拉加载
- $scope.loadMore = function() {
- //开启上拉加载
- $scope.domore = false;
- //数据列表加1
- // $scope.filterData.idx += 1;
- $scope.load.pageIndex += 1;
- //定时器
- var timer = null;
- //参数
- var filterData = $scope.defaultData;
- angular.extend(filterData, { 'idx': $scope.load.pageIndex });
- //加载
- if ($scope.load.pageIndex < $scope.load.pageCount) {
- api_bpm_domain.fetchtask(pdKey, filterData).then(function(data) {
- var myData = Restangular.stripRestangular(data);
- $scope.statecolor(myData.data);
- if (angular.isArray(myData.data) && myData.data.length > 0) {
- angular.forEach(myData.data, function(item) {
- $scope.myData.push(item);
- });
- $scope.$broadcast('scroll.infiniteScrollComplete');
- } else {
- $scope.domore = true;
- $scope.$broadcast('scroll.infiniteScrollComplete');
- }
- }, function(data) {});
- } else {
- $scope.domore = true;
- $scope.$broadcast('scroll.infiniteScrollComplete');
- }
- };
- //数据加载
- $scope.isgetdata = true;
- $scope.refreshListData = function(filterData, loadStyle) {
- $scope.isgetdata = false;
- //获取本地数据
- // var filterData = JSON.parse(sessionStorage.incidentListMobileParameter);
- //对接口参数进行重新组装
- // var showData = {
- // 'assignee': filterData.assignee,
- // // 'idx': filterData.currentPage ? filterData.currentPage - 1 : 0,
- // 'idx': filterData.idx,
- // 'searchType': filterData.searchType,
- // 'status': filterData.status,
- // 'sum': filterData.sum,
- // };
- var showData = {};
- var defaultData = {
- 'assignee': loginUser.id,
- 'idx': 0,
- 'sum': 10,
- // 'candidateGroups': loginUser.group["0"].id
- 'candidateGroups': 0
- };
- if (filterData) {
- showData = angular.extend(defaultData, filterData);
- } else {
- showData = defaultData;
- }
- // if (filterData.candidateGroups) {
- // angular.extend(showData, { 'candidateGroups': filterData.candidateGroups });
- // };
- //遮罩层开启
- $ionicLoading.show({
- template: 'Loading...'
- });
- $scope.defaultData = showData;
- api_bpm_domain.fetchtask(pdKey, showData).then(function(data) {
- var myData = Restangular.stripRestangular(data);
- $scope.statecolor(myData.data);
- // filterData.count = myData.resultCount;
- // if (angular.isArray(myData.data) && myData.data.length > 0) {
- if (angular.isArray(myData.data)) {
- $scope.myData = myData.data;
- $scope.load.pageIndex = myData.pageIndex;
- $scope.load.pageCount = myData.pageCount;
- if (loadStyle == 'down') {
- $scope.$broadcast('scroll.refreshComplete');
- }
- } else {
- // SweetAlert.swal({
- // title: "数据为空",
- // text: myData.data,
- // type: "warning"
- // });
- // if ($scope.paginationList || $scope.paginationList.count) {
- // $scope.paginationList.count = 0;
- // }
- $scope.listShow = false;
- }
- $scope.domore = false;
- $scope.isgetdata = true;
- //遮罩层关闭
- $ionicLoading.hide();
- }, function() {
- $ionicLoading.hide();
- });
- }
- //事件提取
- $scope.acceptTaskAction = function(item) {
- var confirmPopup = $ionicPopup.confirm({
- title: '抢单',
- template: '是否抢单?',
- cancelText: '取消',
- okText: '确认'
- });
- confirmPopup.then(function(res) {
- // var receiveTask = function(receive_code, item) {
- // var data = {
- // 'receive_code': receive_code
- // };
- // if (item) {
- // return {
- // taskId: item.taskId,
- // data: data
- // };
- // } else {
- // return 'error';
- // }
- // };
- // var data = receiveTask($scope.receive_code, item);
- if (res) {
- api_bpm_domain.claimAndCompletedTask(item.taskId, { userId: loginUser.id, receive_code: "handler" }).then(function(response) {
- if (response.status == 200) {
- // $scope.reload()
- item.tiquPower = false;
- item.chaozuoPower = true;
- $ionicPopup.alert({
- title: '操作成功!',
- // template: 'It might taste good'
- okText: '确认'
- });
- confirmPopup.close();
- } else if (response.status == 500) {
- $ionicPopup.alert({
- title: '操作失败!',
- template: '该单已被抢,请刷新页面!',
- okText: '确认'
- });
- confirmPopup.close();
- } else {
- $ionicPopup.alert({
- title: '操作失败!',
- template: '操作失败, 请稍后再试!',
- okText: '确认'
- });
- confirmPopup.close();
- }
- });
- } else {
- }
- });
- }
- //页面加载
- // $scope.reload();
- //跳转成功刷新页面
- // $scope.$on('$stateChangeSucess', $scope.reload());
- if (!sessionStorage.sessionLogin) {
- var promise = getLoginUser.query();
- promise.then(function(sessionLogin) { //返回成功
- $scope.tokenType = sessionLogin.tokenType;
- var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
- var loginUser = sessionLogin.user;
- $scope.sessionLogin = sessionLogin
- $rootScope.user = sessionLogin.user;
- $scope.defaultData = {
- 'assignee': loginUser.id,
- 'idx': 0,
- 'sum': 10,
- // 'candidateGroups': loginUser.group["0"].id
- 'candidateGroups': 0
- };
- $scope.filterData = {
- 'assignee': loginUser.id,
- 'idx': 0,
- 'sum': 10,
- };
- $scope.reload()
- }, function(data) { //返回失败
- });
- } else {
- var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
- var loginUser = sessionLogin.user;
- $scope.sessionLogin = sessionLogin
- $rootScope.user = sessionLogin.user;
- $scope.defaultData = {
- 'assignee': loginUser.id,
- 'idx': 0,
- 'sum': 10,
- // 'candidateGroups': loginUser.group["0"].id
- 'candidateGroups': 0
- };
- $scope.filterData = {
- 'assignee': loginUser.id,
- 'idx': 0,
- 'sum': 10,
- };
- $scope.reload()
- }
- }])
- app.controller('handlerExtendCtrl', ['$scope', '$rootScope', '$http', function($scope, $rootScope, $http) {
- //判断当前事件状态
- // if ($scope.item.state.id != null && $scope.item.state.id != 6 && $scope.item.handlerUser != null) {
- // if ($rootScope.user.id && $rootScope.user.id == $scope.item.handlerUser.id) {
- // $scope.item.chaozuoPower = true;
- // } else {
- // // angular.forEach($rootScope.user.group, function(userItem) {
- // // angular.forEach($scope.item.handlerUser.group, function(handlerUserItem) {
- // // if (handlerUserItem == userItem.id) {
- // // $scope.item.chaozuoPower = true;
- // // }
- // // });
- // // });
- // }
- // }
- // if ($scope.item.state.id != 6 && $scope.item.handlerUser == null) {
- // $scope.item.tiquPower = true;
- // }
- //判断当前事件状态
- if ($scope.item.state.id != null && $scope.item.handlerUser != null) {
- if ($rootScope.user.id == $scope.item.handlerUser.id) {
- $scope.item.chaozuoPower = true;
- }
- }
- if ($scope.item.state.id != 6 && $scope.item.handlerUser == null) {
- angular.forEach($rootScope.user.group, function(item) {
- if (item.id == $scope.item.candidateGroups) {
- $scope.item.tiquPower = true;
- }
- })
- }
- // if ($scope.item.state.id != null && $scope.item.handlerUser != null) {
- // if ($rootScope.user.id == $scope.item.handlerUser.id) {
- // $scope.item.chaozuoPower = true;
- // }
- // }
- $scope.look = function() {
- $scope.$parent.$parent.$parent.lookFunction($scope.item);
- };
- $scope.edit = function() {
- $scope.$parent.$parent.$parent.editorFunction($scope.item);
- };
- $scope.handler = function() {
- $scope.$parent.$parent.$parent.acceptTaskAction($scope.item);
- }
- }]);
|