controllers.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. starter.controller('AuditCtrl', function ($rootScope, $scope, $state, $ionicActionSheet, $window, $timeout, Audit, global, formatFilter) {
  2. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function (event, data) {
  3. global.fetch_user().then(function () {
  4. getcountdata();
  5. });
  6. });
  7. $scope.doRefresh = function () {
  8. getcountdata();
  9. }
  10. $scope.show = function () {
  11. $ionicActionSheet.show({
  12. buttons: [
  13. {text: '过滤条件'}
  14. ],
  15. titleText: '设置',
  16. cancelText: '取消',
  17. buttonClicked: function (index) {
  18. if (index == 0)
  19. $state.go('audit-filter');
  20. }
  21. });
  22. };
  23. function getcountdata() {
  24. if (global.user.token != "") {
  25. Audit.Audit('GetAuditCounts').save(Audit.getFilter(), function (data) {
  26. $scope.count = data;
  27. }, function (err) {
  28. if (err.status == 401 && _.has(err.data, 'IsAuth'))
  29. $window.location.href = formatFilter("http://" + $window.location.host + "/apps/authuser/index.html");
  30. }).$promise.finally(function () {
  31. $scope.$broadcast('scroll.refreshComplete');
  32. });
  33. }
  34. }
  35. var CountDoRefresh = $rootScope.$on('CountDoRefresh', function (event ,data) {
  36. getcountdata();
  37. })
  38. $scope.$on('$destroy', function () {
  39. beforeEnter();
  40. CountDoRefresh();
  41. })
  42. })
  43. .controller('FilterCtrl', function ($rootScope, $scope, $state, Audit, showPopup) {
  44. showPopup.modalTemplate('templates/modal-selectdate.html', 'slide-in-right', $scope).then(function (modal) {
  45. $scope.select_date_modal = modal;
  46. });
  47. $scope.filter = Audit.getFilter();
  48. $scope.chkdd_tv_arr = Audit.chkdd_tv_arr;
  49. $scope.clearLocalStorage = function () {
  50. window.localStorage.clear();
  51. $scope.filter = Audit.getFilter();
  52. }
  53. $scope.showModal = function () {
  54. $scope.select_date_modal.show();
  55. $rootScope.commons.modal = $scope.select_date_modal;
  56. }
  57. $scope.closeModal = function () {
  58. Audit.setFilter($scope.filter);
  59. $rootScope.commons.modal.hide();
  60. }
  61. var watchFilter = $scope.$watch('filter.substitutechk', function (n, o) {
  62. if (n == o)
  63. return;
  64. Audit.setFilter($scope.filter);
  65. });
  66. $scope.$on('$destroy', function () {
  67. if ($rootScope.commons.modal)
  68. $rootScope.commons.modal = null;
  69. $scope.select_date_modal.remove();
  70. watchFilter();
  71. })
  72. })
  73. .controller('ListCtrl', function ($rootScope, $scope, $state, $stateParams, Audit, global, Tool) {
  74. $scope.QueryID = $stateParams.QueryID;
  75. global.fetch_user().then(function () {
  76. getlistdata();
  77. });
  78. $scope.doRefresh = function () {
  79. getlistdata();
  80. }
  81. $scope.todetails = function (item) {
  82. $state.go('audit-detail', {
  83. QueryID: $scope.QueryID,
  84. BIL_ID: item.bil_id,
  85. BIL_NO: item.no,
  86. BIL_ITM: item.bil_itm,
  87. IsAuditCall: 'T',
  88. CheckInAudit: 'T'
  89. })
  90. }
  91. $scope.loadMore = function () {
  92. if ($scope.list != undefined && $scope.list.next != null) {
  93. Tool.get($scope.list.next).then(function (data) {
  94. $scope.list.Data = $scope.list.Data.concat(data.Data);
  95. $scope.list.next = data.next;
  96. $scope.list.previous = data.previous;
  97. }).finally(function () {
  98. $scope.$broadcast('scroll.infiniteScrollComplete');
  99. $scope.loading = false;
  100. });
  101. } else {
  102. $scope.$broadcast('scroll.infiniteScrollComplete');
  103. }
  104. }
  105. $scope.moreCanBeLoaded = function () {
  106. return $scope.list != undefined && $scope.list.next != null;
  107. }
  108. function getlistdata() {
  109. if (global.user.token != "") {
  110. if ($scope.list == undefined) {
  111. $scope.loading = true;
  112. }
  113. Audit.Audit('GetAuditLists').save({QueryID: $scope.QueryID, page: 1}, Audit.getFilter(), function (data) {
  114. $scope.list = data;
  115. }, function (err) {
  116. alert(JSON.stringify(err));
  117. }).$promise.finally(function () {
  118. $scope.$broadcast('scroll.refreshComplete');
  119. $scope.loading = false;
  120. });
  121. }
  122. }
  123. var ListDoRefresh = $rootScope.$on('ListDoRefresh', function (event ,data) {
  124. getlistdata();
  125. })
  126. $scope.$on('$destroy', function () {
  127. ListDoRefresh();
  128. })
  129. })
  130. .controller('DetailHeadCtrl', function ($rootScope, $scope, $state, $stateParams, $cordovaDialogs, $ionicModal, global, cfg, Audit, showPopup, formatFilter) {
  131. $scope.QueryID = $stateParams.QueryID;
  132. $scope.BIL_ID = $stateParams.BIL_ID;
  133. $scope.BIL_NO = $stateParams.BIL_NO;
  134. $scope.BIL_ITM = $stateParams.BIL_ITM;
  135. $scope.IsAuditCall = $stateParams.IsAuditCall;
  136. $scope.CheckInAudit = $stateParams.CheckInAudit;
  137. showPopup.modalTemplate('templates/modal-routeaudit.html', 'slide-in-right', $scope).then(function (modal) {
  138. $scope.route_audit_modal = modal;
  139. });
  140. showPopup.modalTemplate('templates/modal-imagepopover.html', 'slide-in-right', $scope).then(function (modal) {
  141. $scope.image_popover_modal = modal;
  142. });
  143. global.fetch_user().then(function () {
  144. getbilldata();
  145. });
  146. $scope.goBack = function () {
  147. global.goBack();
  148. }
  149. $scope.tobody = function (name) {
  150. if (name != 'BODY_COUNT')
  151. return;
  152. Audit.body = $scope.detail.body;
  153. $state.go('audit-detail-body');
  154. }
  155. $scope.audit = function (op) {
  156. $scope.data = {};
  157. if (op == 1 && $scope.QueryID == 1) {
  158. setPopup('同意', '请输入备注(选填)', op);
  159. } else if (op == 2 && $scope.QueryID == 1) {
  160. setPopup('驳回', '请输入驳回理由(必填)', op);
  161. } else if (op == 3 && $scope.QueryID == 2) {
  162. setPopup('反审批', '请输入备注(选填)', op);
  163. } else if (op == 4 && $scope.QueryID == 1) {
  164. postAudit($scope.data);
  165. }
  166. }
  167. $scope.doRefresh = function () {
  168. getbilldata();
  169. }
  170. $scope.showImages = function (index, event) {
  171. $scope.activeSlide = index;
  172. $scope.image_popover_modal.show();
  173. $rootScope.commons.modal = $scope.image_popover_modal;
  174. }
  175. function getbilldata() {
  176. if (global.user.token != "") {
  177. if ($scope.detail == undefined) {
  178. $scope.loading = true;
  179. }
  180. Audit.Bills('GetBilHeadDetails').get({
  181. QueryID: $scope.QueryID,
  182. BIL_ID: $scope.BIL_ID,
  183. BIL_NO: $scope.BIL_NO,
  184. BIL_ITM: $scope.BIL_ITM,
  185. IsAuditCall: $scope.IsAuditCall,
  186. CheckInAudit: $scope.CheckInAudit
  187. }, function (data) {
  188. $scope.detail = data;
  189. $scope.detail.group = _.values(_.groupBy(data.Data, function (item) {
  190. return item.GROUPID;
  191. }));
  192. getshlcdata();
  193. Audit.Bills('GetBilAttrFileList').get({BIL_ID: $scope.BIL_ID, BIL_NO: $scope.BIL_NO}, function (data) {
  194. $scope.detail.files = data;
  195. $scope.detail.imagefiles = _.filter($scope.detail.files.Data, function (item) {
  196. return item.FILE_TYPE == '.BMP' || item.FILE_TYPE == '.JPEG' || item.FILE_TYPE == '.JPG' || item.FILE_TYPE == '.GIF' || file.FILE_TYPE != '.PNG'
  197. });
  198. _.each($scope.detail.imagefiles, function (item) {
  199. item.url = formatFilter('{0}ext_erp/{1}', cfg.api, item.FILE_URL);
  200. })
  201. }, function (err) {
  202. alert(JSON.stringify(err));
  203. });
  204. Audit.Bills('GetBilBodyDetails').get({BIL_ID: $scope.BIL_ID, BIL_NO: $scope.BIL_NO, BIL_ITM: $scope.BIL_ITM}, function (data) {
  205. $scope.detail.body = data;
  206. }, function (err) {
  207. alert(JSON.stringify(err));
  208. });
  209. }, function (err) {
  210. alert(JSON.stringify(err));
  211. }).$promise.finally(function () {
  212. $scope.$broadcast('scroll.refreshComplete');
  213. $scope.loading = false;
  214. });
  215. }
  216. }
  217. function getshlcdata() {
  218. Audit.Audit('GetAuditSHLC').get({BIL_ID: $scope.BIL_ID, BIL_NO: $scope.BIL_NO, BIL_ITM: $scope.BIL_ITM}, function (data) {
  219. $scope.detail.shlc = data;
  220. }, function (err) {
  221. alert(JSON.stringify(err));
  222. });
  223. }
  224. function setPopup(title, placeholdertext, op) {
  225. $cordovaDialogs.prompt(placeholdertext, title, ['确定', '取消']).then(function (result) {
  226. var input = result.input1;
  227. var btnIndex = result.buttonIndex;
  228. if (btnIndex == 1) {
  229. if ( op == 2 && (input == '' || input == null)) {
  230. $cordovaDialogs.alert('请填写驳回理由', '提示', '确定');
  231. } else {
  232. $scope.data = {
  233. PROCID: op,
  234. BIL_ID: $scope.BIL_ID,
  235. BIL_NO: $scope.BIL_NO,
  236. BIL_ITM: $scope.BIL_ITM,
  237. REM_SH: input == '' || input == null ? null : input,
  238. NodeIndex: null
  239. }
  240. showPopup.showLoading(1, '正在提交');
  241. postAudit($scope.data);
  242. }
  243. }
  244. });
  245. }
  246. function postAudit(data) {
  247. Audit.Audit('ExecuteAudit').save(data, function (data) {
  248. $scope.nodeData = data.NodeData;
  249. if (data.hasExistsNode == 'T') {
  250. $scope.route_audit_modal.show();
  251. $rootScope.commons.modal = $scope.route_audit_modal;
  252. } else {
  253. $scope.$emit('ListDoRefresh');
  254. $scope.$emit('CountDoRefresh');
  255. getshlcdata();
  256. }
  257. }, function (err) {
  258. showPopup.PopupWindow(0, err.message)
  259. }).$promise.finally(function () {
  260. showPopup.hideLoading();
  261. })
  262. }
  263. $scope.$on('$destroy', function () {
  264. if ($rootScope.commons.modal)
  265. $rootScope.commons.modal = null;
  266. $scope.route_audit_modal.remove();
  267. })
  268. })
  269. .controller('DetailBodyCtrl', function ($scope, $state, Audit) {
  270. $scope.body = angular.copy(Audit.body);
  271. $scope.toitem = function (item) {
  272. Audit.bodyitem = item;
  273. $state.go('audit-body-data');
  274. }
  275. })
  276. .controller('BodyDataCtrl', function ($scope, Audit) {
  277. $scope.bodyitem = _.values(_.groupBy(angular.copy(Audit.bodyitem), function (item) {
  278. return item.GROUPID;
  279. }));
  280. })