InputCtrl.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. define([ 'app/app','common/services','service/Purc','service/SupportServices' ], function(app) {
  2. app.register.controller('InputCtrl',['$scope', '$http', '$rootScope', '$location', '$filter','$stateParams','$modal','toaster', 'PurcOrder', 'Ring','SupportUtil', 'Online','ngTableParams','SessionService', '$document', 'smartySuggestor', '$window', '$timeout',function($scope, $http, $rootScope, $location, $filter,$stateParams,$modal,toaster, PurcOrder, Ring,SupportUtil, Online,ngTableParams,SessionService,$document, smartySuggestor, $window, $timeout){
  3. $scope.orders = $rootScope.orders || [];
  4. $rootScope.title = {};
  5. $scope.whcode = SessionService.getCookie('defaultWhcode');
  6. $scope.tableParams = new ngTableParams({
  7. page : 1,
  8. count : 10,
  9. sorting : {
  10. enDate: 'ASC'
  11. },
  12. filter : {}
  13. }, {
  14. total: $scope.orders.length,
  15. getData : function($defer, params) {
  16. var orderedData = params.sorting() ?
  17. $filter('orderBy')($scope.orders, params.orderBy()) :
  18. $scope.orders;
  19. orderedData = params.filter() ?
  20. $filter('filter')(orderedData, params.filter()) :
  21. orderedData;
  22. params.total(orderedData.length);
  23. $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
  24. }
  25. });
  26. setTimeout( function(){
  27. try{
  28. document.getElementById("batchCode").focus();
  29. } catch(e){}
  30. }, 200);
  31. var getProdcode = function(code,whcode,pi_id){
  32. PurcOrder.get({inoutNo: code,whcode:whcode,pi_id:pi_id}, function(data) {//获取成功
  33. if(data.target && data.totalCount > 0){
  34. var or = new Object();
  35. or = data.target;
  36. // $scope.whcode = or[0].PI_WHCODE ;
  37. $scope.orders.push(or[0]) ;
  38. $rootScope.orders = $scope.orders;
  39. $scope.tableParams.reload();
  40. Ring.success();//提示成功响铃
  41. $scope.batchCode = '';//重置输入框
  42. }
  43. if(data.exceptionInfo){
  44. toaster.pop('error', '查询失败',data.exceptionInfo);
  45. Ring.error();
  46. }
  47. }, function(response){//获取失败处理
  48. toaster.pop('error', '查询失败',response.data.exceptionInfo);
  49. Ring.error();
  50. });
  51. };
  52. var getWhcode = function(code,whcode,pi_id){
  53. PurcOrder.getWhcode({inoutNo:code,whcode:whcode,condition:"pd_inqty",pi_id:pi_id},{},function(data){
  54. if(data.exceptionInfo){
  55. toaster.pop('error', '查询失败',data.exceptionInfo);
  56. Ring.error();
  57. } else if(data.data.length > 1 && data.data[0].PI_INOUTNO){ //弹出选择框,选择出入库单号,类型
  58. $scope.items = data.data;
  59. var modalInstance = $modal.open({
  60. templateUrl: 'billModalContent.html',
  61. controller: 'ModalInstanceCtrl',
  62. resolve: {
  63. items: function () {
  64. return $scope.items;
  65. }
  66. }
  67. });
  68. modalInstance.result.then(function(selectedItem) {
  69. $scope.selected = selectedItem;
  70. getWhcode($scope.selected.PI_INOUTNO,whcode,$scope.selected.PI_ID);
  71. });
  72. }else if(data.data.length > 1 && data.data[0].PD_WHCODE){
  73. //弹出选择框,选择仓库
  74. $scope.items = data.data;
  75. var modalInstance = $modal.open({
  76. templateUrl: 'myModalContent.html',
  77. controller: 'ModalInstanceCtrl',
  78. resolve: {
  79. items: function () {
  80. return $scope.items;
  81. }
  82. }
  83. });
  84. modalInstance.result.then(function(selectedItem) {
  85. $scope.selected = selectedItem;
  86. getProdcode($scope.batchCode,$scope.selected,data.data[0].PI_ID);
  87. }, function() {
  88. //$log.info('Modal dismissed at: ' + new Date());
  89. });
  90. }else{
  91. getProdcode(code,data.data[0].PD_WHCODE,data.data[0].PI_ID);
  92. }
  93. },function (response){
  94. Ring.error();
  95. toaster.pop('error', '查询失败',response.data.exceptionInfo);
  96. });
  97. };
  98. $scope.getOrder = function(code,whcode) {//根据输入的单据id号获取下载单据信息
  99. if(SupportUtil.contains(JSON.stringify($scope.orders),code,"PI_INOUTNO") || SupportUtil.contains(JSON.stringify($scope.orders),code,"PI_ID")){//请求的单据id或者单号已经被下载在本地了
  100. Ring.error();
  101. toaster.pop('error', '单据重复',"请勿重复采集");
  102. } else {//请求的单据id或者单号未被下载在本地了,向服务器发送请求获取数据
  103. if(!whcode){
  104. whcode = '';
  105. }
  106. if(!code){
  107. alert("请输入入库单号!");
  108. return ;
  109. }
  110. getWhcode(code,whcode);
  111. }
  112. };
  113. $scope.search = function($event, batchCode,whcode){//enter键触发事件
  114. if($event.keyCode == 13) {//Enter事件
  115. $scope.getOrder(batchCode,whcode);
  116. }
  117. };
  118. $scope.operate = function(order) {//跳转至对应的单据操作页面
  119. if(! $scope.again){
  120. $scope.selectedId = order.PI_INOUTNO;
  121. $location.path('inMMOperation/' + order.PI_INOUTNO);
  122. }
  123. $scope.again = false;
  124. };
  125. var getClearAgain = function(order){
  126. var grid = $rootScope.grid;
  127. angular.forEach(grid, function(value, key){
  128. if(value.bi_inoutno == order.PI_INOUTNO) {//出入库单号相等删除
  129. $rootScope.grid.splice(key,1);
  130. }
  131. });
  132. angular.forEach($scope.orders, function(value, key){
  133. if(value.PI_ID == order.PI_ID) {//修改状态
  134. $scope.orders.splice(key,1);
  135. }
  136. });
  137. $rootScope.orders = $scope.orders ;
  138. getWhcode(order.PI_INOUTNO,order.PI_WHCODE,order.PI_ID);
  139. }
  140. $scope.getAgain = function (order){//重新采集
  141. if(confirm("确认重新采集,将会清空所有已采集数据包含已提交的数据")){
  142. PurcOrder.clearGet({no:order.PI_ID,whcode:order.PI_WHCODE},{},function(data){
  143. if(data.exceptionInfo){
  144. var str = data.exceptionInfo;
  145. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  146. str = str.replace('AFTERSUCCESS', '');
  147. getClearAgain(order);
  148. toaster.pop('success',str);
  149. }else{
  150. toaster.pop('error',data.exceptionInfo);
  151. Ring.error();
  152. }
  153. }else{
  154. getClearAgain(order);
  155. Ring.success();
  156. toaster.pop('success', '已清空采集数据'); }
  157. },function(response){
  158. Ring.error();
  159. toaster.pop('error', '清空失败');
  160. });
  161. }
  162. $scope.again = true;
  163. };
  164. $scope.deleteDe = function (order){
  165. if(confirm("确认删除?")){
  166. angular.forEach($scope.orders, function(value, key){
  167. if(value.PI_ID == order.PI_ID) {//修改状态
  168. $scope.orders.splice(key,1);
  169. }
  170. });
  171. $rootScope.orders = $scope.orders ;
  172. $scope.tableParams.reload();
  173. Ring.success();
  174. toaster.pop('success', '删除成功');
  175. }
  176. };
  177. //模糊查询
  178. $scope.suggestions = function(val){
  179. if (val == "" || angular.isUndefined(val) || val.length < 3) {
  180. return null ;
  181. }else{
  182. return smartySuggestor.getSmartySuggestions(val,'pd_inqty').then(function(res) {
  183. if(res.data != null && res.data.length > 0){
  184. return $filter("limitTo")(res.data, 5).map(function(item) {
  185. return item.PI_INOUTNO;
  186. });
  187. }
  188. });
  189. }
  190. };
  191. }]);
  192. });