myKnowledgeListCtrl.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. app.controller('myKnowledgeListCtrl', ["$rootScope", "$scope", '$stateParams', '$http', '$state', '$timeout', '$ionicPopover', '$ionicPopup', '$ionicLoading', 'api_bpm_domain', 'Restangular', 'api_solution', function($rootScope, $scope, $stateParams, $http, $state, $timeout, $ionicPopover, $ionicPopup, $ionicLoading, api_bpm_domain, Restangular, api_solution) {
  2. console.log('myKnowledgeListCtrl is load');
  3. $scope.load = {
  4. 'pageIndex': 0, //第几页
  5. 'pageSum': 10, //每页条数
  6. 'pageCount': 0 //总页数
  7. };
  8. //弹出框
  9. // 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>';
  10. // $scope.popover = $ionicPopover.fromTemplate(template, {
  11. // scope: $scope
  12. // });
  13. // .fromTemplateUrl() method
  14. $ionicPopover.fromTemplateUrl('assets/views/weChat/myIncident/popover.html', {
  15. scope: $scope
  16. }).then(function(popover) {
  17. $scope.popover = popover;
  18. });
  19. $scope.openPopover = function($event) {
  20. $scope.popover.show($event);
  21. };
  22. $scope.closePopover = function() {
  23. $scope.popover.hide();
  24. };
  25. //Cleanup the popover when we're done with it!
  26. $scope.$on('$destroy', function() {
  27. $scope.popover.remove();
  28. });
  29. // Execute action on hidden popover
  30. $scope.$on('popover.hidden', function() {
  31. // Execute action
  32. });
  33. // Execute action on remove popover
  34. $scope.$on('popover.removed', function() {
  35. // Execute action
  36. });
  37. $scope.statuses = [
  38. { status: 'all', label: '全部的事件', idName: 'a' },
  39. { status: 'todo', label: '待我处理的', idName: 'b' },
  40. { status: 'create', label: '我创建的', idName: 'c' },
  41. { status: 'done', label: '我处理过的', idName: 'd' },
  42. // { status: 's', label: '已驳回', idName: 'e' },
  43. // { status: '6', label: '已拒绝', idName: 'f' }
  44. ];
  45. $scope.searchTypeFunction = function(searchType) {
  46. $scope.reload(searchType);
  47. $scope.popover.hide();
  48. }
  49. // $scope.loginForm = {};
  50. // var loginUser = $rootScope.user;
  51. //获取login中的数据
  52. var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
  53. var loginUser = sessionLogin.user;
  54. var solutionUser = $scope.solutionUser = JSON.parse($state.params.item);
  55. //定义流程代号
  56. // var pdKey = $state.current.pdKey;
  57. var pdKey = 'bpm_incident';
  58. //默认数据
  59. var defaultData = {
  60. 'assignee': loginUser.id,
  61. 'idx': 0,
  62. 'sum': 10,
  63. };
  64. //页面数据容器
  65. $scope.myData = [];
  66. //是否加载上拉刷新
  67. $scope.domore = false;
  68. //填充数据
  69. $scope.filterData = {
  70. 'assignee': loginUser.id,
  71. 'idx': 0,
  72. 'sum': 10,
  73. };
  74. //本地数据初始化
  75. // sessionStorage.incidentListMobileParameter = JSON.stringify(incidentListMobileParameter);
  76. $scope.goBack = function() {
  77. // $state.go('myKnowledgeList', {});
  78. history.go(-1);
  79. }
  80. $scope.commentFunction = function() {
  81. $state.go('tab.myKnowledgeComment', {
  82. 'item': JSON.stringify(solutionUser)
  83. // 'solutionId': $state.params.id,
  84. // 'review': $state.params.content
  85. });
  86. }
  87. //页面刷新
  88. $scope.reload = function() {
  89. $scope.refreshListData();
  90. }
  91. //下拉刷新
  92. $scope.doRefresh = function() {
  93. $scope.load.pageIndex = 0;
  94. $scope.refreshListData('', 'down');
  95. $scope.domore = false;
  96. if (angular.isString($scope.searchInput) && $scope.searchInput != '') {
  97. $scope.searchInput = '';
  98. }
  99. };
  100. //上拉加载
  101. $scope.loadMore = function() {
  102. //开启上拉加载
  103. $scope.domore = false;
  104. //数据列表加1
  105. $scope.filterData.idx += 1;
  106. $scope.load.pageIndex += 1;
  107. //定时器
  108. var timer = null;
  109. //参数
  110. var filterData = defaultData;
  111. angular.extend(filterData, { 'idx': $scope.filterData.idx });
  112. //加载
  113. if ($scope.load.pageIndex < $scope.load.pageCount) {
  114. // api_solution.findSolutionReviewById(loginUser.id, solutionUser.id, $scope.filterData.idx, $scope.load.pageSum).then(function(response) {
  115. api_solution.fetchDataList('solutionReview', { 'idx': $scope.filterData.idx, 'sum': $scope.load.pageSum, 'solutionReview': { 'solutionId': solutionUser.id, 'userId': loginUser.id, 'status': 2 } }).then(function(response) {
  116. var myData = Restangular.stripRestangular(response);
  117. if (angular.isArray(myData.list) && myData.list.length > 0) {
  118. angular.forEach(myData.list, function(item) {
  119. $scope.myData.push(item);
  120. });
  121. $scope.$broadcast('scroll.infiniteScrollComplete');
  122. } else {
  123. $scope.domore = true;
  124. $scope.$broadcast('scroll.infiniteScrollComplete');
  125. }
  126. }, function(data) {});
  127. } else {
  128. $scope.domore = true;
  129. $scope.$broadcast('scroll.infiniteScrollComplete');
  130. }
  131. };
  132. //数据加载
  133. $scope.refreshListData = function(filterData, loadStyle) {
  134. var showData = {};
  135. if (filterData) {
  136. showData = angular.extend(defaultData, filterData);
  137. } else {
  138. showData = defaultData;
  139. }
  140. //遮罩层开启
  141. $ionicLoading.show({
  142. template: 'Loading...'
  143. });
  144. // api_solution.findSolutionReviewById(loginUser.id, solutionUser.id, 0, $scope.load.pageSum).then(function(response) {
  145. api_solution.fetchDataList('solutionReview', { 'idx': 0, 'sum': $scope.load.pageSum, 'solutionReview': { 'solutionId': solutionUser.id, 'userId': loginUser.id, 'status': 2 } }).then(function(response) {
  146. var myData = Restangular.stripRestangular(response);
  147. if (angular.isArray(myData.list) && myData.list.length > 0) {
  148. $scope.myData = myData.list;
  149. //计算总页数
  150. $scope.load.pageCount = Math.ceil(myData.totalNum / $scope.load.pageSum);
  151. if (loadStyle == 'down') {
  152. $scope.$broadcast('scroll.refreshComplete');
  153. }
  154. } else {
  155. $scope.listShow = false;
  156. }
  157. //遮罩层关闭
  158. $ionicLoading.hide();
  159. }, function() {
  160. //遮罩层关闭
  161. $ionicLoading.hide();
  162. });
  163. }
  164. //页面加载
  165. // $scope.reload();
  166. //跳转成功刷新页面
  167. $scope.$on('$stateChangeSucess', $scope.reload())
  168. }])