define([ 'angularAMD','toaster', 'ngTable', 'common/services', 'service/Purc','service/SupportServices', 'ui.router', 'ui.bootstrap','directive/SmartDirectives' ], function(angularAMD) { 'use strict'; var app = angular.module('myApp', ['ngAnimate', 'toaster','ngTable', 'ui.router', 'common.services', 'PurcServices', 'SupportServices','ui.bootstrap','SmartDirectives']); app.init = function() { angularAMD.bootstrap(app); }; app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise('/index'); $stateProvider.state('index', { url : "/index", templateUrl : "resources/tpl/index/index.html" }).state('inMakeMaterial',angularAMD.route({ url : "/inMakeMaterial", templateUrl : "resources/tpl/input/inMakeMaterial.html", controllerUrl : 'app/controllers/InputCtrl' })).state('inMMOperation', { url: '/inMMOperation/:code', templateUrl: 'resources/tpl/input/inMMOperation.html' }).state('inContents',angularAMD.route({ url:'/inContents', templateUrl:'resources/tpl/input/inContents.html', controllerUrl : 'app/controllers/InputCtrl' })).state('inMMWaitSubmit',{ url:'/inMMWaitSubmit/:ioNocode', templateUrl:'resources/tpl/input/inMMWaitSubmit.html' }).state('inFinishWaitSubmit',{ url:'/inFinishWaitSubmit/:ioNocode', templateUrl:'resources/tpl/input/inFinishWaitSubmit.html' }).state('inFinishOperation',{ url:'/inFinishOperation/:code', templateUrl:'resources/tpl/input/inFinishOperation.html' }).state('inFinish',angularAMD.route({ url:'/inFinish', templateUrl : 'resources/tpl/input/inFinish.html', controllerUrl : 'app/controllers/InFinishCtrl' })).state('outContents',angularAMD.route({ url:'/outContents', templateUrl : 'resources/tpl/output/outContents.html', controllerUrl : 'app/controllers/OutputCtrl' })).state('outMakeMaterial',angularAMD.route({ url:'/outMakeMaterial', templateUrl : 'resources/tpl/output/outMakeMaterial.html', controllerUrl : 'app/controllers/OutputCtrl' })).state('outMMOperation',angularAMD.route({ url:'/outMMOperation/:code', templateUrl : 'resources/tpl/output/outMMOperation.html', controllerUrl : 'app/controllers/OutMMOperationCtrl' })).state('outMMWaitSubmit',angularAMD.route({ url:'/outMMWaitSubmit/:ioNocode', templateUrl:'resources/tpl/output/outMMWaitSubmit.html', controllerUrl : 'app/controllers/OutMMwaitSubmitCtrl' })).state('outFinish',angularAMD.route({ url:'/outFinish', templateUrl:'resources/tpl/output/outFinish.html', controllerUrl : 'app/controllers/OutFinishCtrl' })).state('outFinishOprCtrl',angularAMD.route({ url:'/outFinishOperation/:code', templateUrl:'resources/tpl/output/outFinishOperation.html', controllerUrl : 'app/controllers/OutFinishOprCtrl' })).state('outFinWaitSubmit',angularAMD.route({ url:'/outFinWaitSubmit/:ioNocode', templateUrl:'resources/tpl/output/outFinWaitSubmit.html', controllerUrl : 'app/controllers/OutFinWaitSubmitCtrl' })).state('countingContents',{ url:'/countingContents', templateUrl:'resources/tpl/counting/countingContents.html' }).state('countingMM',{ url:'/countingMM', templateUrl:'resources/tpl/counting/countingMM.html' }).state('countingFinish',{ url:'/countingFinish', templateUrl:'resources/tpl/counting/countingFinish.html' }).state('countingMMWaitSub',{ url:'/countingMMWaitSub', templateUrl:'resources/tpl/counting/countingMMWaitSub.html' }).state('countingFinWaitSub',{ url:'/countingFinWaitSub', templateUrl:'resources/tpl/counting/countingFinWaitSub.html' }).state('checkContents',angularAMD.route({ url:'/checkContents', templateUrl:'resources/tpl/check/checkContents.html', controllerUrl : 'app/controllers/CheckCtrl' })).state('checkMM',angularAMD.route({ url:'/checkMM', templateUrl:'resources/tpl/check/checkMM.html', controllerUrl : 'app/controllers/CheckCtrl' })).state('checkBarcode',angularAMD.route({ url:'/checkBarcode', templateUrl:'resources/tpl/check/checkBarcode.html', controllerUrl : 'app/controllers/CheckCtrl' })).state('checkPackage',angularAMD.route({ url:'/checkPackage', templateUrl:'resources/tpl/check/checkPackage.html', controllerUrl : 'app/controllers/CheckCtrl' })).state('checkMakeFin',angularAMD.route({ url:'/checkMakeFin', templateUrl:'resources/tpl/check/checkMakeFin.html', controllerUrl : 'app/controllers/CheckCtrl' })).state('checkOrderFin',angularAMD.route({ url:'/checkOrderFin', templateUrl:'resources/tpl/check/checkOrderFin.html', controllerUrl : 'app/controllers/CheckCtrl' })).state('checkPO',angularAMD.route({ url:'/checkPO', templateUrl:'resources/tpl/check/checkPO.html', controllerUrl : 'app/controllers/CheckCtrl' })).state('locationTransfer',angularAMD.route({ url:'/locationTransfer', templateUrl:'resources/tpl/locationTransfer/locationTransfer.html', controllerUrl : 'app/controllers/LocationTransferCtrl' })).state('batchContents',{ url:'/batchContents', templateUrl:'resources/tpl/batch/batchContents.html' }).state('breakingBatch',{ url:'/breakingBatch', templateUrl:'resources/tpl/batch/breakingBatch.html' }).state('breakingPackage',{ url:'/breakingPackage', templateUrl:'resources/tpl/batch/breakingPackage.html' }).state('combineBatch',{ url:'/combineBatch', templateUrl:'resources/tpl/batch/combineBatch.html' }).state('settingContents',angularAMD.route({ url:'/settingContents', templateUrl:'resources/tpl/setting/settingContents.html', controllerUrl : 'app/controllers/SettingCtrl' })).state('haveSubmitList',angularAMD.route({ url:'/haveSubmitList/:pi_id/:inout/:pi_inoutno', templateUrl:'resources/tpl/input/haveSubmitList.html', controllerUrl : 'app/controllers/HaveSubmitListCtrl' })); }]); app.factory('Ring', function(){//响铃,直接调用 return { success: function(){ document.getElementById('successRing').play(); }, error: function(){ document.getElementById('errorRing').play(); } } }).factory('Online',['$rootScope', function($rootScope){//在线状态,全局获取、设置 var status = {online: true}; return { setOnline: function(value){ status.online = value; $rootScope.$broadcast('online', value); }, getOnline: function(){ return status.online; } } }]); app.directive('enterAsTab', function () { return function (scope, element, attrs) { element.bind("keyup", function (event) { if(event.which === 13) { var focusable = document.getElementsByTagName('input'); // Get the index of the currently focused element var currentIndex = Array.prototype.indexOf.call(focusable, event.target); // Find the next items in the list var nextIndex = currentIndex == focusable.length - 1 ? 0 : currentIndex + 1; // Focus the next element if(nextIndex >= 0 && nextIndex < focusable.length){ if(focusable[nextIndex].value == 0||focusable[nextIndex].value == '') focusable[nextIndex].focus(); } } }); }; }); app.controller('AuthCtrl',['$scope', '$rootScope','$window', 'AuthenticationService','Online','BaseService','SessionService', function($scope, $rootScope,$window, AuthenticationService,Online,BaseService,SessionService) { //控制手机浏览器全屏 找到支持的方法, 使用需要全屏的 element 调用 $rootScope.title = {}; /* function launchFullScreen(element) { if(element.requestFullscreen) { element.requestFullscreen(); } else if(element.mozRequestFullScreen) { element.mozRequestFullScreen(); } else if(element.webkitRequestFullscreen) { element.webkitRequestFullscreen(); } else if(element.msRequestFullscreen) { element.msRequestFullscreen(); } } //启动全屏 document.getElementById("full").addEventListener("click",function(){ launchFullScreen(document.documentElement); }); */ $scope.status = {online: true}; $scope.$watch('status.online', function(value){//检测用户手动切换在线状态 Online.setOnline(value); }); $scope.$on('online', function(data){//监听Service中的状态变化 $scope.status.online = Online.getOnline(); }); Online.setOnline(AuthenticationService.isAuthed()); $scope.userInfo = {}; AuthenticationService.getAuthentication().success(function(data) { $scope.userInfo = data; if (data == null || !data.em_code){ Online.setOnline(false); //$window.location.href = rootPath+'/jsps/PDAmobile/signin.html' } }); $scope.logout = function() {//注销 AuthenticationService.logout().success(function() { var rootPath= BaseService.getRootPath(); $window.location.href = rootPath+'/jsps/PDAmobile/signin.html'; }); }; }]); app.factory('StatusCode', function(){ var statusConfig = { '101' : '已采集', '102' : '未采集', '103' : '采集中' }; return { get: function(code) { return statusConfig[code]; } }; }).filter('status',['StatusCode', function(StatusCode){ return function(data) { return StatusCode.get(data); } }]); app.controller('IndexCtrl',['$scope','$rootScope', function($scope, $rootScope){ }]); app.controller('ModalInstanceCtrl',['$scope', '$modalInstance', 'items','SessionService','Print','toaster',function($scope, $modalInstance, items,SessionService,Print,toaster) { $scope.items = items; $scope.colors = [//可以选择的颜色 { id: 'red', name: '红色' } ] $scope.defaultWhcode = SessionService.getCookie('defaultWhcode'); $scope.ok = function(selectValue) { $modalInstance.close(selectValue.PD_WHCODE); }; $scope.selectBill = function(item){ $modalInstance.close(item); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; $scope.confirmWhcode = function(items){//设置默认仓库 $modalInstance.close(items); }; $scope.search = function ($event,items){//搜索物料 if($event == 13){ $modalInstance.close(items); } }; $scope.setStyle = function(){//设置样式 $modalInstance.close($scope.items); }; $scope.confirmPrint = function(items){//设置默认打印机 $modalInstance.close(items); }; $scope.returnBatching = function(item){//返回继续拆分 $modalInstance.close(items); } $scope.print = function (){//打印 if(confirm('确认打印')){ Print.get({data:angular.fromJson($scope.items)},function(data){ if(data.exceptionInfo){ toaster.pop('error', data.exceptionInfo); }else if(data.message){ toaster.pop('error', data.message); }else { toaster.pop('success', "打印成功!"); } },function(res){ if(res.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); } }); } }; }]); app.controller('InMMOperationCtrl',['$scope','$http','$modal', '$stateParams', '$rootScope','$filter','$location', 'ngTableParams','toaster', 'Ring', 'PurcOrderItem','SupportUtil', 'Online', function($scope, $http,$modal, $stateParams, $rootScope,$filter,$location, ngTableParams,toaster, Ring, PurcOrderItem,SupportUtil, Online){ $scope.grid = $rootScope.grid||[]; $scope.getOnline = Online.getOnline; setTimeout( function(){ try{ document.getElementById("bi_barcode").focus(); var labels = document.getElementsByName("required-label"); /*for(var n in labels){ labels[n].style.color = 'red'; }*/ var inputs = document.getElementsByTagName("input"); for(var n in inputs){ if(typeof inputs[n].getAttribute("required") === "string"){ console.log('true'); } if(typeof inputs[n].getAttribute("required") === "string"){ inputs[n].labels[0].style.color = 'red'; } } } catch(e){} }, 100); var getOrder = function(code) {//根据路径中的id号获取对应的单据 var result = null; angular.forEach($rootScope.orders, function(value, key){ if(value.PI_INOUTNO == code) { result = value; return result; } }); return result; }; $scope.changeSelection = function(item) {//table with row selection,表格选中列操作 document.getElementById("bi_barcode").focus(); $scope.ordercode = item.PD_ORDERCODE; $scope.bi_prodcode = item.PD_PRODCODE; $scope.bi_prodid = item.PR_ID; $scope.bi_inoutno = $scope.order.PI_INOUTNO; $scope.bi_inqty = item.PR_ZXBZS || $scope.bi_inqty; $scope.pr_fbzs = item.PD_INQTY; $scope.detno = item.PD_PDNO; $scope.pd_id = item.PD_ID; $scope.bi_prodname = item.PR_DETAIL; $scope.bi_location = item.PR_LOCATION || $scope.bi_location; $scope.pr_detail = item.PR_DETAIL+item.PR_SPEC; $scope.ifbarcodecheck = item.PR_IFBARCODECHECK; $scope.pr_id = item.PR_ID; } $scope.order = getOrder($stateParams.code); $rootScope.title.pi_inoutno =$scope.order.PI_INOUTNO +' '+$scope.order.PI_WHCODE; if($scope.order){ var keepGoing = true; angular.forEach($scope.order.product, function(value, key){ if( keepGoing ){ if(value.PD_INQTY == 0 && $scope.order.product[key+1]){ if($scope.order.product[key+1].PD_INQTY != 0){ $scope.changeSelection($scope.order.product[key+1]); keepGoing = false ; } }else if(value.PD_INQTY != 0) { $scope.changeSelection($scope.order.product[key]); keepGoing = false; } } }); $scope.tableParams = new ngTableParams({//未完成料号名称规格及剩余数量表格 page: 1, count: 10, filter: { }, sorting: { } }, { total: $scope.order.product.length, getData: function ($defer, params) { var filteredData = params.filter() ? $filter('filter')($scope.order.product, params.filter()) : data; var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : data; params.total(orderedData.length); // set total for recalc pagination $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); } }); } //进入界面,表单值默认为grid中的第一行 var check = function (productCode){ //校验:1、物料编号存在, 2、数量不超过剩余数量,3、条码号唯一性 //条码储位不允许为空 var reg = /^[0-9]*[1-9][0-9]*$/;  if(!$scope.bi_barcode){ //alert("请输入条码!"); document.getElementById("bi_barcode").focus(); return ; }/*else if(!$scope.bi_location){ //alert("请输入储位!"); document.getElementById("bi_location").focus(); return ; }*/else if(!reg.test($scope.bi_inqty)){ Ring.error(); alert("数量格式不正确!"); document.getElementById("bi_inqty").focus(); return ; } var item = SupportUtil.contains(JSON.stringify($scope.order.product),productCode,"PD_PRODCODE"); if(item){ //是否条码校验 if($scope.ifbarcodecheck == '1'){ var pr_idlen =$scope.order.barcodeset.BS_LENPRID; //比较物料ID的前几位是否等于条码号的前几位 var pr_id = new String($scope.pr_id); var bar_code = new String($scope.bi_barcode); if (SupportUtil.lapAft(pr_id,pr_idlen) != SupportUtil.lapFor(bar_code,pr_idlen)){ Ring.error(); $scope.bi_barcode =''; toaster.pop('error',"条码校验错误,该条码与物料不匹配"); return false; } } if($scope.bi_inqty !=0 && $scope.bi_inqty >0 && ($scope.bi_inqty < $scope.pr_fbzs || $scope.bi_inqty == $scope.pr_fbzs) && $scope.pr_fbzs > -1 ){ if($rootScope.grid){ if(!(SupportUtil.contains(JSON.stringify($rootScope.grid) ,$scope.bi_barcode,"bi_barcode"))){ return true; }else{ Ring.error(); toaster.pop('error', '条码号重复'); $scope.bi_barcode =''; document.getElementById("bi_barcode").focus(); return false; } }else{ return true; } }else { Ring.error(); $scope.bi_inqty = ''; document.getElementById("bi_inqty").focus(); alert("数量不能大于剩余数量或者为空"); return false; } }else { alert("物料不存在"); Ring.error(); return false; } } $scope.message = {}; $scope.scan = function(){//确认按钮事件 if(check($scope.bi_prodcode)){ $scope.barcodes = {}; $scope.barcodes.bi_barcode = $scope.bi_barcode; $scope.barcodes.bi_prodcode = $scope.bi_prodcode ; $scope.barcodes.bi_prodid = $scope.bi_prodid ; $scope.barcodes.bi_inoutno = $scope.bi_inoutno; $scope.barcodes.bi_inqty = $scope.bi_inqty; $scope.barcodes.bi_location = $scope.bi_location; $scope.barcodes.bi_whcode = $scope.order.PI_WHCODE; $scope.barcodes.bi_prodname = $scope.bi_prodname; $scope.barcodes.bi_pdno = $scope.detno; $scope.barcodes.bi_pdid = $scope.pd_id; $scope.barcodes.bi_piid = $scope.order.PI_ID; //插入数据到待提交缓存列表中grid(barcode,prodcode,inqty,location) $scope.grid.push($scope.barcodes); $rootScope.grid = $scope.grid; $scope.pr_fbzs -= $scope.barcodes.bi_inqty; $scope.bi_barcode =''; document.getElementById("bi_barcode").focus(); Ring.success(); angular.forEach($scope.order.product, function(value, key){ if(value.PD_ID == $scope.pd_id) { value.PD_INQTY = $scope.pr_fbzs ; $scope.tableParams.reload(); if(value.PD_INQTY == 0 && $scope.order.product[key+1] ){ $scope.changeSelection($scope.order.product[key+1]); } } }); var keepGoing = true; angular.forEach($scope.order.product, function(value, key){ if(keepGoing){ if(value.PD_INQTY != 0 ){ keepGoing = false ; } } }); if(keepGoing){ if(confirm("已完成,请提交采集")){ $location.path('inMMWaitSubmit/' + $scope.order.PI_INOUTNO); } } } }; $scope.enter = function (event){ SupportUtil.nextFocus(event); }; $scope.submitGet = function(){//提交采集操作,与后台交互 if($scope.grid.length != 0){ PurcOrderItem.saveBarcode({}, JSON.stringify($scope.grid),function(data) {//获取成功 if(data.exceptionInfo){ toaster.pop('error', '提交失败',data.exceptionInfo); Ring.error(); }else{ $rootScope.grid = $scope.grid =''; Ring.success(); toaster.pop('success', '提交成功'); } }, function(response){//获取失败处理 if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', '提交失败',"网络连接不可用,请稍后再试"); }else { Ring.error(); toaster.pop('error', '提交失败',response.data.exceptionInfo); } }); }else { Ring.error(); toaster.pop('error', '无数据'); } }; $scope.getList = function(argOrder){//点击 if(argOrder){ $location.path('inMMWaitSubmit/' + argOrder); } }; $scope.returnInput = function(){//当前单据有未提交的,提示先提交。 if($scope.grid.length != 0){ if(confirm("返回将清空未提交数据,确认返回?")){ angular.forEach($scope.order.product, function(value, key){ for (var gs in $scope.grid){ if (value.PD_ID == $scope.grid[gs].bi_pdid) { value.PD_INQTY = eval($scope.grid[gs].bi_inqty+"+"+value.PD_INQTY); } } }); $rootScope.grid = $scope.grid =''; $location.path('inMakeMaterial'); } }else{ var status = '101'; angular.forEach($scope.order.product, function(value, key){ if(value.PD_INQTY !=0) { status = '102' } }); if(status == '101'){//修改采集状态 $scope.order.ENAUDITSTATUS='101'; } $location.path('inMakeMaterial'); } } $scope.findProdcode = function (){ var modalInstance = $modal.open({ templateUrl: 'prodModalContent.html', controller: 'ProdModalInstanceCtrl', resolve: { items: function () { return $scope.order.product; } } }); modalInstance.result.then(function(selectedItem) { $scope.changeSelection(selectedItem); }, function() { /*$log.info('Modal dismissed at: ' + new Date());*/ }); } }]); app.controller('ProdModalInstanceCtrl',['$scope', '$modalInstance', 'items',function($scope, $modalInstance, items) { $scope.items = items; $scope.wh = {}; $scope.selectPrCode = function(selectValue) { $modalInstance.close(selectValue); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; }]); app.controller('InMMwaitSubmitCtrl',['$scope','$rootScope','$stateParams','$filter', 'ngTableParams','Online','PurcOrderItem','toaster','Ring', function($scope, $rootScope,$stateParams,$filter, ngTableParams,Online,PurcOrderItem,toaster,Ring){ $scope.grid = $rootScope.grid; var getOrder = function(code) {//根据路径中的id号获取对应的单据 var result = null; angular.forEach($rootScope.orders, function(value, key){ if(value.PI_INOUTNO == code) { result = value; return result; } }); return result; }; $scope.order = getOrder($stateParams.ioNocode); if($scope.grid){ $scope.tableParams = new ngTableParams({//未完成料号名称规格及剩余数量表格 page: 1, count: 10, filter: { }, sorting: { } }, { total: $scope.grid.length, getData: function ($defer, params) { var filteredData = params.filter() ? $filter('filter')($scope.grid, params.filter()) : data; var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : data; params.total(orderedData.length); // set total for recalc pagination $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); } }); } $scope.deleteAll = function (){//全部删除 if(confirm("确定删除全部?")){ angular.forEach($rootScope.orders, function(value, key) {//反写剩余数 if (value.PI_INOUTNO == $scope.order.PI_INOUTNO) { for (var n in value.product) { for (var gs in $scope.grid){ if (value.product[n].PD_ID == $scope.grid[gs].bi_pdid) { value.product[n].PD_INQTY = eval($scope.grid[gs].bi_inqty+"+"+value.product[n].PD_INQTY); } } } } }); $rootScope.grid = $scope.grid =''; $scope.tableParams.reload(); toaster.pop('success', '删除成功'); } } $scope.deleteWaitSubmitItem = function (s){ angular.forEach($rootScope.orders, function(value, key) { if (value.PI_INOUTNO == $scope.order.PI_INOUTNO) { for (var n in value.product) { if (value.product[n].PD_ID == s.bi_pdid) { value.product[n].PD_INQTY = eval(s.bi_inqty+"+"+value.product[n].PD_INQTY); } } } }); for (var n in $scope.grid){ if($scope.grid[n].bi_barcode == s.bi_barcode){ $scope.grid.splice(n,1); } } $rootScope.grid = $scope.grid; $scope.tableParams.reload(); }; $scope.submitGet = function(){//提交采集操作,与后台交互 if($scope.grid.length !=0){ PurcOrderItem.saveBarcode({}, JSON.stringify($scope.grid),function(data) {//获取成功 if(data.exceptionInfo){ toaster.pop('error', '提交失败',data.exceptionInfo); Ring.error(); }else{ $rootScope.grid = $scope.grid =''; Ring.success(); toaster.pop('success', '提交成功'); } }, function(response){//获取失败处理 if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', '提交失败',"网络连接不可用,请稍后再试"); } else { Ring.error(); toaster.pop('error', '提交失败',response.data.exceptionInfo); } }); }else{ Ring.error(); toaster.pop('error', '无数据'); } }; }]); app.controller('InFinishOprCtrl',['$scope', '$http', '$stateParams', '$rootScope','$filter','$location','$modal', 'ngTableParams','toaster', 'Ring', 'PurcOrderItem','SupportUtil', 'Online','$q', function($scope, $http, $stateParams, $rootScope,$filter,$location,$modal, ngTableParams,toaster, Ring, PurcOrderItem,SupportUtil, Online,$q){ $scope.grid = $rootScope.fisgrid||[]; $scope.getOnline = Online.getOnline; setTimeout( function(){ try{ document.getElementById("bi_barcode").focus(); } catch(e){} }, 200); var getOrder = function(code) {//根据路径中的id号获取对应的单据 var result = null; angular.forEach($rootScope.fisOrders, function(value, key){ if(value.PI_INOUTNO == code) { result = value; return result; } }); return result; }; $scope.changeSelection = function(item) {//table with row selection,表格选中列操作 document.getElementById("bi_barcode").focus(); $scope.ordercode = item.PD_ORDERCODE; $scope.bi_prodcode = item.PD_PRODCODE; $scope.bi_prodid = item.PR_ID; $scope.bi_prodspec = item.PD_PRODCODE+item.PR_DETAIL; $scope.bi_inoutno = $scope.order.PI_INOUTNO; $scope.bi_inqty = item.PR_ZXBZS|| $scope.bi_inqty; $scope.pr_fbzs = item.PD_INQTY; $scope.bi_location =item.PR_LOCATION; $scope.bi_prodname = item.PR_DETAIL; $scope.detno = item.PD_PDNO; $scope.pd_id = item.PD_ID; $scope.pr_id = item.PR_ID; } $scope.order = getOrder($stateParams.code); $rootScope.title = {}; $rootScope.title.pi_inoutno = $scope.order.PI_INOUTNO +' '+$scope.order.PI_WHCODE; if($scope.order){ $scope.tableParams = new ngTableParams({//已经采集完成的列表 page: 1, count: 10, filter: { }, sorting: { } }, { total: $scope.order.product.length, getData: function ($defer, params) { var filteredData = params.filter() ? $filter('filter')($scope.order.product, params.filter()) : data; var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : data; params.total(orderedData.length); // set total for recalc pagination $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); } }); var keepGoing = true; angular.forEach($scope.order.product, function(value, key){ if( keepGoing ){ if(value.PD_INQTY == 0 && $scope.order.product[key+1].PD_INQTY != 0){ $scope.changeSelection($scope.order.product[key+1]); keepGoing = false ; }else { $scope.changeSelection($scope.order.product[key]); keepGoing = false; } } }); }; var checkOutbox = function(defer){ //包装箱号,则根据包装表packageDetail获取所有序列号和总数, //如果外包装不止一层可能存在递归,如果总数不超过剩余数则执行插入到grid。 PurcOrderItem.getPackageCode({pr_fqty:$scope.pr_fbzs,pa_outboxcode:$scope.bi_outboxcode}, {},function(data){ if(data.exceptionInfo){ defer.reject(data.exceptionInfo); }else{ defer.resolve(data.message); } },function(response){ document.getElementById("bi_outboxcode").focus(); Ring.error(); defer.reject(response.data.exceptionInfo); }); }; var checkMakeSerial = function (defer){ //如果有设定的归属工单,必须序列号归属于选定的工单(关联MakeSerial表判断), //5、如果该序列号已经存在库存(barcode表remain>0 ),不允许重复入库。 if($scope.makeSerial){ PurcOrderItem.checkMakeSerial({ms_sncode:$scope.bi_barcode,makeCode:$scope.makeSerial,whcode:$scope.order.PI_WHCODE}, {},function(data){ if(data.exceptionInfo){ defer.reject(data.exceptionInfo); }else defer.resolve(data.message); },function(response){ document.getElementById("makeSerial").focus(); Ring.error(); defer.reject(response.data.exceptionInfo); }); }else{ defer.resolve(''); } } var check = function (){ //校验:1、物料编号存在, 2、数量不超过剩余数量,3、条码号唯一性 //条码储位不允许为空 var defer = $q.defer(); var reg = /^[0-9]*[1-9][0-9]*$/;  if(!$scope.bi_barcode && !$scope.bi_outboxcode){ document.getElementById("bi_barcode").focus(); Ring.error(); defer.reject("请输入序列号或者包装箱号!"); }else if(!$scope.bi_location){ document.getElementById("bi_location").focus(); Ring.error(); defer.reject("请输入储位!"); }else if(!reg.test($scope.bi_inqty)){ document.getElementById("bi_inqty").focus(); Ring.error(); defer.reject("数量格式不正确!"); }else{ var item = SupportUtil.contains(JSON.stringify($scope.order.product),$scope.bi_prodcode,"PD_PRODCODE"); if(item){ /*//是否条码校验 if($scope.ifbarcodecheck == '1'){ var pr_idlen =$scope.order.barcodeset.BS_LENPRID; //比较物料ID的前几位是否等于条码号的前几位 var pr_id = new String($scope.pr_id); var bar_code = new String($scope.bi_barcode); if (SupportUtil.lap(pr_id,pr_idlen) != SupportUtil.lap(bar_code,pr_idlen)){ Ring.error(); $scope.bi_barcode =''; defer.reject("条码校验错误,该条码与物料不匹配") } } */ if($scope.bi_inqty !=0 && $scope.bi_inqty >0 && ($scope.bi_inqty < $scope.pr_fbzs || $scope.bi_inqty == $scope.pr_fbzs) && $scope.pr_fbzs > -1 ){ if($scope.bi_barcode){ if($rootScope.fisgrid && SupportUtil.contains(JSON.stringify($rootScope.fisgrid) ,$scope.bi_barcode,"bi_barcode")){ document.getElementById("bi_barcode").focus(); Ring.error(); defer.reject("序列号重复"); }else checkMakeSerial(defer); }else{ if($rootScope.fisgrid && $scope.bi_outboxcode && SupportUtil.contains(JSON.stringify($rootScope.fisgrid) ,$scope.bi_outboxcode,"bi_outboxcode")){ Ring.error(); defer.reject("包装箱号重复"); }else{ checkOutbox(defer); } } }else { Ring.error(); defer.reject("数量不能大于剩余数量或者为空"); } }else { defer.reject("物料不存在"); Ring.error(); } } return defer.promise; }; $scope.scan = function(){//确认按钮事件 var q = check(); q.then(function(message){ $scope.barcodes = {}; $scope.barcodes.bi_barcode = $scope.bi_barcode; $scope.barcodes.bi_prodcode = $scope.bi_prodcode ; $scope.barcodes.bi_prodid = $scope.bi_prodid ; $scope.barcodes.bi_inoutno = $scope.bi_inoutno; $scope.barcodes.bi_inqty = $scope.bi_inqty; $scope.barcodes.bi_location = $scope.bi_location; $scope.barcodes.bi_whcode = $scope.order.PI_WHCODE; $scope.barcodes.bi_outboxcode = $scope.bi_outboxcode ; $scope.barcodes.bi_prodname = $scope.bi_prodname; $scope.barcodes.bi_pdno = $scope.detno; $scope.barcodes.bi_pdid = $scope.pd_id; $scope.barcodes.bi_piid = $scope.order.PI_ID; //插入数据到待提交缓存列表中grid(barcode,prodcode,inqty,location) $scope.grid.push($scope.barcodes); $rootScope.fisgrid = $scope.grid; $scope.pr_fbzs -= $scope.barcodes.bi_inqty; $scope.bi_barcode =''; Ring.success(); angular.forEach($scope.order.product, function(value, key){ if(value.PD_ID == $scope.pd_id) { value.PD_INQTY = $scope.pr_fbzs ; $scope.tableParams.reload(); if(value.PD_INQTY == 0 && $scope.order.product[key+1] ){ $scope.changeSelection($scope.order.product[key+1]); } } }); var keepGoing = true; angular.forEach($scope.order.product, function(value, key){ if(keepGoing){ if(value.PD_INQTY != 0 ){ keepGoing = false ; } } }); if(keepGoing){ if(confirm("已完成,请提交采集")){ $location.path('inFinishWaitSubmit/' + $scope.order.PI_INOUTNO); } } }, function(error){ Ring.error(); toaster.pop('error', '错误',error); }); }; $scope.enter = function (event){ SupportUtil.nextFocus(event); }; $scope.submitGet = function(){//提交采集操作,与后台交互 if($scope.grid.length >0){ PurcOrderItem.saveBarcode({},JSON.stringify($scope.grid),function(data) {//获取成功 if(data.exceptionInfo){ toaster.pop('error', '提交失败',data.exceptionInfo); Ring.error(); }else if(data.message){ Ring.error(); toaster.pop('error', '提交失败',data.message); }else{ Ring.success(); toaster.pop('success', '提交成功'); $rootScope.fisgrid = $scope.grid =''; } }, function(response){//获取失败处理 if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', '提交失败',"网络连接不可用,请稍后再试"); }else { Ring.error(); toaster.pop('error', '提交失败',response.data.exceptionInfo); } }); }else{ Ring.error(); toaster.pop('error', '没有需要提交的数据'); } }; $scope.getList = function(argOrder){//点击 if(argOrder){ $location.path('inFinishWaitSubmit/' + argOrder); } }; $scope.returnInput = function(){//当前单据有未提交的,提示先提交。 if($scope.grid.length != 0){ if(confirm("返回将清空未提交数据,确认返回?")){ angular.forEach($scope.order.product, function(value, key){ for (var gs in $scope.grid){ if (value.PD_ID == $scope.grid[gs].bi_pdid) { value.PD_INQTY = eval($scope.grid[gs].bi_inqty+"+"+value.PD_INQTY); } } }); $rootScope.fisgrid = $scope.grid =''; $location.path('inFinish'); } }else{ var status = '101'; angular.forEach($scope.order.product, function(value, key){ if(value.PD_INQTY !=0) { status = '102' } }); if(status == '101'){//修改采集状态 $scope.order.ENAUDITSTATUS='101'; } $location.path('inFinish'); } } $scope.findProdcode = function (){ var modalInstance = $modal.open({ templateUrl: 'prodModalContent.html', controller: 'ProdModalInstanceCtrl', resolve: { items: function () { return $scope.order.product; } } }); modalInstance.result.then(function(selectedItem) { $scope.changeSelection(selectedItem); }); } }]); app.controller('InfinishWaitSubmitCtrl',['$scope', '$rootScope','$stateParams','$filter', 'ngTableParams','Online','PurcOrderItem','toaster','Ring', function($scope, $rootScope,$stateParams,$filter, ngTableParams,Online,PurcOrderItem,toaster,Ring){ $scope.grid = $rootScope.fisgrid||[]; var getOrder = function(code) {//根据路径中的id号获取对应的单据 var result = null; angular.forEach($rootScope.fisOrders, function(value, key){ if(value.PI_INOUTNO == code) { result = value; return result; } }); return result; }; $scope.order = getOrder($stateParams.ioNocode); if($scope.grid){ $scope.tableParams = new ngTableParams({//未完成料号名称规格及剩余数量表格 page: 1, count: 10, filter: { }, sorting: { } }, { total: $scope.grid.length, getData: function ($defer, params) { var filteredData = params.filter() ? $filter('filter')($scope.grid, params.filter()) : data; var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : data; params.total(orderedData.length); // set total for recalc pagination $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); } }); }; $scope.deleteAll = function (){//全部删除 if(confirm("确定删除全部?")){ angular.forEach($rootScope.fisOrders, function(value, key) {//反写剩余数 if (value.PI_INOUTNO == $scope.order.PI_INOUTNO) { for (var n in value.product) { for (var gs in $scope.grid){ if (value.product[n].PD_ID == $scope.grid[gs].bi_pdid) { value.product[n].PD_INQTY = eval($scope.grid[gs].bi_inqty+"+"+value.product[n].PD_INQTY); } } } } }); $rootScope.fisgrid = $scope.grid =''; $scope.tableParams.reload(); toaster.pop('success', '删除成功'); } }; $scope.deleteWaitSubmitItem = function (s){ angular.forEach($rootScope.fisOrders, function(value, key) { if (value.PI_INOUTNO == $scope.order.PI_INOUTNO) { for (var n in value.product) { if (value.product[n].PD_ID == s.bi_pdid) { value.product[n].PD_INQTY = eval(s.bi_inqty+"+"+value.product[n].PD_INQTY); } } } }); for (var n in $scope.grid){ if($scope.grid[n].bi_barcode == s.bi_barcode){ $scope.grid.splice(n,1); } } $rootScope.fisgrid = $scope.grid; $scope.tableParams.reload(); }; $scope.submitGet = function(){//提交采集操作,与后台交互 PurcOrderItem.saveBarcode({}, JSON.stringify($scope.grid),function(data) {//获取成功 if(data.exceptionInfo){ toaster.pop('error', '提交失败',data.exceptionInfo); Ring.error(); }else{ Ring.success(); toaster.pop('success', '提交成功'); } }, function(response){//获取失败处理 if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', '提交失败',"网络连接不可用,请稍后再试"); } else { Ring.error(); toaster.pop('error', '提交失败',response.data.exceptionInfo); } }); }; }]); app.controller('CountingCtrl',['$scope', '$http', '$stateParams', '$rootScope','$filter','$location', 'ngTableParams','toaster', 'Ring', 'SupportUtil','CountingOper', 'Online','SessionService',function($scope, $http, $stateParams, $rootScope,$filter,$location, ngTableParams,toaster, Ring, SupportUtil,CountingOper, Online,SessionService){ $scope.stocking = $rootScope.stocking||''; $scope.st_whcode = SessionService.getCookie('defaultWhcode'); $scope.find = function(event,st_code){ if(event.keyCode === 13){ $scope.search(st_code); } } $scope.search = function(st_code){ if(st_code){ CountingOper.get({st_code:st_code},function(data){ if(data.exceptionInfo){ toaster.pop('error', '查询失败',data.exceptionInfo); Ring.error(); }else if(data.target && data.totalCount > 0){ var or = new Object(); or = data.target; $scope.stocking = data.target[0]; $rootScope.stocking = $scope.stocking; $scope.st_whcode = $scope.stocking.ST_WHCODE; } },function(response){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); }else{ toaster.pop('error', '查询失败',response.data.exceptionInfo); Ring.error(); } }); }else{ alert("请输入盘点底稿编号!"); document.getElementById("st_code").focus() } } $scope.confirm = function(){ if($scope.Counting == 'makeMaterial'){ $location.path("countingMM"); }else{ $location.path("countingFinish"); } } }]); app.controller('CountingMMCtrl',['$scope', '$http', '$stateParams', '$rootScope','$filter','$location', 'ngTableParams','toaster', 'Ring', 'SupportUtil','CountingOper', 'Online',function($scope, $http, $stateParams, $rootScope,$filter,$location, ngTableParams,toaster, Ring, SupportUtil,CountingOper, Online){ $scope.stocking = $rootScope.stocking||''; $scope.grid = $rootScope.cmGrid||[]; var check = function(){//条码号不为空;2、数量大于0;3、条码不存在于已采集列表 if(!$scope.barcodes.stb_barcode){ document.getElementById("bi_barcode").focus(); Ring.error(); alert("条码号不为空"); return false; }else if(SupportUtil.contains(JSON.stringify($scope.grid),$scope.barcodes.stb_barcode,"stb_barcode")){ alert("条码编号重复!"); Ring.error(); document.getElementById("bi_barcode").focus(); document.getElementById("bi_barcode").select(); return false; }else if($scope.barcodes.stb_qty <=0){ alert ("数量必须大于0"); Ring.error(); return false; }else { return true; } } $scope.barcodes = {}; $scope.search = function($event,bi_barcode){ if($event.keyCode == 13) {//Enter事件 if(check()){ CountingOper.getBarData({bar_code:bi_barcode,bar_whcode:$scope.stocking.ST_WHCODE,st_code:$scope.stocking.ST_CODE},{},function(data){ if(data.exceptionInfo){ toaster.pop('error', '条码号错误',data.exceptionInfo); Ring.error(); }else { $scope.barcodes.stb_barcode = data.data.BAR_CODE; $scope.barcodes.stb_vendcode = data.data.BAR_VENDCODE; $scope.barcodes.stb_prodcode = data.data.BAR_PRODCODE; $scope.barcodes.stb_barid = data.data.BAR_ID; $scope.barcodes.stb_qty = data.data.BAR_REMAIN; $scope.barcodes.stb_stid = $scope.stocking.ST_ID; $scope.barcodes.stb_stcode = $scope.stocking.ST_CODE; $scope.barcodes.pr_detail = data.data.PR_DETAIL; } },function(response){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); }else{ toaster.pop('error', '条码号错误',response.data.exceptionInfo); Ring.error(); } }) } } } $scope.confirm = function(){ if(check()){ $scope.show = true; $scope.grid.push($scope.barcodes); $scope.shows = $scope.barcodes; $scope.barcodes =''; document.getElementById("bi_barcode").focus(); } $rootScope.cmGrid = $scope.grid ; }; $scope.returnCC = function (){ if($scope.grid.length>0){ if(confirm("返回,将删除已采集未提交的数据?")){ $scope.grid = $rootScope.cfGrid = ''; $location.path("countingContents"); } }else{ $location.path("countingContents"); } }; $scope.submitGet = function(){//提交盘点数据 if($scope.grid.length>0){ CountingOper.saveBarcode({},JSON.stringify($scope.grid),function(data){ if(data.exceptionInfo){ toaster.pop('error', '提交失败',data.exceptionInfo); Ring.error(); }else { $scope.grid = $rootScope.cmGrid = ''; toaster.pop('success', '提交成功'); Ring.success(); } },function(response){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', '提交失败',"网络连接不可用,请稍后再试"); }else{ toaster.pop('error', '提交失败',response.data.exceptionInfo); Ring.error(); } }); }else{ Ring.error(); alert("没有需要提交的数据!"); } } if($scope.grid){ $scope.tableParams = new ngTableParams({//盘点料号名称规格及剩余数量表格【待提交的】 page: 1, count: 10, filter: { }, sorting: { } }, { total: $scope.grid.length, getData: function ($defer, params) { params.total($scope.grid.length); // set total for recalc pagination $defer.resolve($scope.grid.slice((params.page() - 1) * params.count(), params.page() * params.count())); } }); }; $scope.deleteAll = function(){//全部删除 if(confirm("确定删除全部?")){ $scope.grid = $rootScope.cmGrid = ''; Ring.success(); toaster.pop('success', '删除成功'); $scope.tableParams.reload(); } } $scope.deleteWaitSubmitItem = function(s){//单行删除 for (var n in $scope.grid){ if($scope.grid[n].stb_barcode == s.stb_barcode){ $scope.grid.splice(n,1); } } $rootScope.cmGrid = $scope.grid; $scope.tableParams.reload(); }; }]); app.controller('CountingFinishCtrl',['$scope', '$http', '$stateParams', '$rootScope','$filter','$location', 'ngTableParams','toaster', 'Ring', 'SupportUtil','CountingOper', 'Online',function($scope, $http, $stateParams, $rootScope,$filter,$location, ngTableParams,toaster, Ring, SupportUtil,CountingOper, Online){ $scope.stocking = $rootScope.stocking||''; $scope.grid = $rootScope.cfGrid||[]; var checkSerialSearch = function(serial_code){ if(SupportUtil.contains(JSON.stringify($scope.grid),serial_code,"stb_barcode")){ Ring.error(); alert("序列号重复!"); document.getElementById("serial_code").focus().select(); return ; }else{ CountingOper.serialSearch({code:serial_code,whcode:$scope.stocking.ST_WHCODE,st_code:$scope.stocking.ST_CODE},{},function(data){ if(data.exceptionInfo){ toaster.pop('error', '序列号不存在',data.exceptionInfo); Ring.error(); }else { $scope.serialMessage = data.message; $scope.makeCode = $scope.serialMessage.MA_CODE; $scope.prodcode = $scope.serialMessage.stb_prodcode; } },function(response){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); }else{ Ring.error(); toaster.pop('error', '序列号不存在',response.data.exceptionInfo); } }); } } $scope.serialSearch = function ($event,serial_code){//序列号enter事件 if($event.keyCode == 13 && serial_code){ checkSerialSearch(serial_code); } }; var checkOutboxSearch = function (boxcode){ if(SupportUtil.contains(JSON.stringify($scope.grid),serial_code,"stb_barcode")){ alert("包装箱号重复"); Ring.error(); return ; }else { CountingOper.outboxSearch({code:boxcode,whcode:$scope.stocking.ST_WHCODE,st_code:$scope.stocking.ST_CODE},{},function(data){ if(data.exceptionInfo){ toaster.pop('error', '包装箱号不存在',data.exceptionInfo); Ring.error(); }else{ $scope.outboxMessage = data.message; $scope.totalqty = $scope.outboxMessage.stb_qty; $scope.prodcode = $scope.outboxMessage.stb_prodcode;} },function(response){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); } Ring.error(); toaster.pop('error', '包装箱号不存在',response.data.exceptionInfo); }); } }; $scope.outboxSearch = function($event,boxcode){//包装箱号enter事件 if($event.keyCode == 13 && boxcode){ checkOutboxSearch(boxcode); } } $scope.confirm = function(){ if(!$scope.serial){ alert("请选择包装箱号或者序列号"); return ; }else if($scope.serial == 'outbox' && !$scope.boxcode){ alert("请输入包装箱号"); return; }else if($scope.serial == 'serial' && !$scope.serial_code){ alert("请输入序列号"); return ; }else if($scope.serial == 'serial' && $scope.serial_code ){//选择序列号执行确认 checkSerialSearch($scope.serial_code); $scope.serialMessage.stb_stcode = $scope.stocking.ST_CODE; $scope.serialMessage.stb_stid = $scope.stocking.ST_ID; $scope.grid.push($scope.serialMessage); $scope.serial_code = $scope.makeCode =''; document.getElementById("serial_code").focus(); Ring.success(); }else if($scope.serial == 'outbox' && $scope.boxcode ){ checkOutboxSearch($scope.boxcode); $scope.outboxMessage.stb_stcode = $scope.stocking.ST_CODE; $scope.outboxMessage.stb_stid = $scope.stocking.ST_ID; $scope.grid.push($scope.outboxMessage); $scope.boxcode = $scope.totalqty =''; document.getElementById("boxcode").focus(); Ring.success(); } $rootScope.cfGrid = $scope.grid; $scope.shows= $scope.grid[$scope.grid.length-1]; }; $scope.returnCC = function (){ if($scope.grid.length>0){ if(confirm("返回,将删除已采集未提交的数据?")){ $scope.grid = $rootScope.cfGrid = ''; $location.path("countingContents"); } }else $location.path("countingContents"); } $scope.submitGet = function(){ if($scope.grid.length>0){ CountingOper.saveBarcode({data:JSON.stringify($scope.grid)},{},function(data){ if(data.exceptionInfo){ toaster.pop('error', '提交失败',data.exceptionInfo); Ring.error(); }else{ $scope.grid = $rootScope.cfGrid = ''; toaster.pop('success', '提交成功'); Ring.success(); } },function(response){ toaster.pop('error', '提交失败',response.data.exceptionInfo); Ring.error(); }); }else{ Ring.error(); alert("没有需要提交的数据!"); } }; if($scope.grid){ $scope.tableParams = new ngTableParams({//盘点料号名称规格及剩余数量表格【待提交的】 page: 1, count: 10, filter: { }, sorting: { } }, { total: $scope.grid.length, getData: function ($defer, params) { params.total($scope.grid.length); // set total for recalc pagination $defer.resolve($scope.grid.slice((params.page() - 1) * params.count(), params.page() * params.count())); } }); }; $scope.deleteWaitSubmitItem = function( s){ for (var n in $scope.grid){ if($scope.grid[n].stb_barcode == s.stb_barcode){ $scope.grid.splice(n,1); } } $rootScope.cfGrid = $scope.grid; $scope.tableParams.reload(); }; $scope.deleteAll = function(){ if(confirm("确定删除全部?")){ $scope.grid = $rootScope.cfGrid = ''; Ring.success(); toaster.pop('success', '删除成功'); $scope.tableParams.reload(); } } }]); app.controller('BatchCtrl',['$scope', '$http', '$stateParams', '$rootScope','$filter','$location', 'BatchOper','ngTableParams','toaster', 'Ring', 'SupportUtil', 'Online','SessionService',function($scope, $http, $stateParams, $rootScope,$filter,$location, BatchOper,ngTableParams,toaster, Ring, SupportUtil, Online,SessionService){ $scope.batchclick = function(choose){ $location.path(choose); }; }]); app.controller('BreakingBatchCtrl',['$scope', '$http', '$stateParams', '$rootScope','$filter','$location', 'BatchOper','ngTableParams','toaster', 'Ring', 'SupportUtil', 'Online','$modal',function($scope, $http, $stateParams, $rootScope,$filter,$location, BatchOper,ngTableParams,toaster, Ring, SupportUtil, Online,$modal){ $scope.grid = []; $scope.btnInvalid = true; if($scope.grid){ $scope.tableParams = new ngTableParams({//批次合并 page: 1, count: 10, filter: { }, sorting: { } }, { total: $scope.grid.length, getData: function ($defer, params) { params.total($scope.grid.length); // set total for recalc pagination $defer.resolve($scope.grid.slice((params.page() - 1) * params.count(), params.page() * params.count())); } }); }; $scope.search = function($event,barcode,type){//根据输入的条码编号查询相关信息 if($scope.grid.length >0 && type !='breaking'){//条码拆分不需要判断是否重复 if(SupportUtil.contains(JSON.stringify($scope.grid),barcode,"bar_code")){ Ring.error(); alert("条码重复!"); return ; } } if($event.keyCode == 13){ BatchOper.get({code:barcode},function(data){ if(data.exceptionInfo){ toaster.pop('error',data.exceptionInfo); Ring.error(); document.getElementById("or_barcode").focus(); }else{ $scope.barData = data.message; $scope.grid.push($scope.barData); $scope.tableParams.reload(); $scope.bar_prodcode = $scope.barData.bar_prodcode $scope.pr_detail = $scope.barData.pr_detail; $scope.barcode.or_remain = $scope.barData.bar_remain; Ring.success(); } },function(response){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); }else{ Ring.error(); toaster.pop('error', response.data.exceptionInfo); document.getElementById("or_barcode").focus(); } }); } }; $scope.confirm = function(barcode,type){ var event = new Object(); event.keyCode = 13; $scope.search(event,barcode,type); } $scope.breaking = function(){//分拆 if($scope.btnInvalid){ //分拆之前判断定,拆分数量必须小于批数量大于0 $scope.btnInvalid = false; if( $scope.barcode.bar_remain < 0 || $scope.barcode.bar_remain >= $scope.barcode.or_remain || $scope.barcode.bar_remain == 0 || $scope.barcode.bar_remain =='0'){ Ring.error(); toaster.pop('error', '拆分数量必须在大于0,小于批数量'); document.getElementById("bar_remain").focus(); $scope.btnInvalid = true; return ; } BatchOper.breakingBatch({},angular.fromJson($scope.barcode),function(data){ $scope.btnInvalid = true; if(data.exceptionInfo){ toaster.pop('error', '拆分失败',data.exceptionInfo); Ring.error(); }else{ Ring.success(); toaster.pop('success', '分拆成功'); modal(data.message); } },function(response){ $scope.btnInvalid = true; if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); }else{ Ring.error(); toaster.pop('error',"拆分失败",response.data.exceptionInfo); } }); } }, $scope.GetTotalRemain = function () { var sum = 0; for (var i = 0; i < $scope.grid.length; i++) { sum += parseFloat($scope.grid[i].bar_remain); } return sum; } $scope.combine = function(){//合并 //合并之前进行判断物料号一致、仓库一致、储位一致 if($scope.grid.length>1){ //有两条或者以上的数据才进行合并 BatchOper.combineBatch({total_remain:$scope.GetTotalRemain()},angular.fromJson($scope.grid),function(data){ if(data.exceptionInfo){ toaster.pop('error', '合并失败',data.exceptionInfo); Ring.error(); }else{ modal(data.message); Ring.success(); $scope.grid ='';//清空 toaster.pop('success', '合并成功'); } },function(res){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); }else{ Ring.error(); toaster.pop('error',"合并失败",response.data.exceptionInfo); } }); } }; // var modal= function(data){ var modalInstance = $modal.open({ templateUrl: 'myModalContent.html', controller: 'ModalInstanceCtrl', resolve: { items: function () { return data; } } }); modalInstance.result.then(function(items) { if(items != null){//继续分拆获取数据 $scope.confirm($scope.barcode.or_barcode,'breaking'); $scope.barcode.bar_remain=''; document.getElementById("bar_remain").focus(); } },function() { $scope.barcode = $scope.pr_detail = $scope.bar_prodcode = '';//清空 document.getElementById("or_barcode").focus(); }); }; }]); app.controller('BreakingPackageCtrl',['$scope', '$http', '$stateParams', '$rootScope','$filter','$location', 'BatchOper','ngTableParams','toaster', 'Ring', 'SupportUtil', 'Online','$modal',function($scope, $http, $stateParams, $rootScope,$filter,$location, BatchOper,ngTableParams,toaster, Ring, SupportUtil, Online,$modal){ $scope.grid = []; $scope.barcode = {}; $scope.bar = {}; $scope.bar.new_qty = 0; $scope.bar.new_packageqty = 0; if($scope.grid){ $scope.tableParams = new ngTableParams({//批次合并 page: 1, count: 10, filter: { }, sorting: { } }, { total: $scope.grid.length, getData: function ($defer, params) { params.total($scope.grid.length); // set total for recalc pagination $defer.resolve($scope.grid.slice((params.page() - 1) * params.count(), params.page() * params.count())); } }); }; $scope.search = function(){//根据外箱号,内箱号,或者序列号获取相关数据 if(!$scope.barcode.inner){ Ring.error(); alert("请选择拆分内箱号或者序列号!"); return ; } if($scope.barcode.inner == 'inner' && !$scope.barcode.innerBox){ Ring.error(); alert("请输入拆分内箱号!"); return ; }else if($scope.barcode.inner == 'serial' && !$scope.barcode.innerSerial){ Ring.error(); alert("请输入拆分序列号!"); return ; } if($scope.grid.length > 0){ if($scope.barcode.or_outbox != $scope.grid[0].pa_outboxcode){ Ring.error(); alert("只能对同一外箱号进行拆分操作!"); return ; } if($scope.barcode.inner == 'serial' && $scope.barcode.innerSerial){ if(SupportUtil.contains(JSON.stringify($scope.grid),$scope.barcode.innerSerial,"pd_barcode")){ Ring.error(); alert("拆分序列号重复!"); return ; } }else if($scope.barcode.inner == 'inner' && $scope.barcode.innerBox){ if(SupportUtil.contains(JSON.stringify($scope.grid),$scope.barcode.innerBox,"pa_outboxcode")){ Ring.error(); alert("拆分箱号重复!"); return ; } } } BatchOper.searchPackageData({},angular.fromJson($scope.barcode),function(data){ if(data.exceptionInfo){ toaster.pop('error', data.exceptionInfo); Ring.error(); }else{ $scope.grid.push(data.data); $scope.bar.new_qty ++; //件数 $scope.bar.newOr_qty = data.data.pa_totalqty-$scope.bar.new_qty;//件数 $scope.packageqty = data.data.pd_innerqty;//箱内数量 $scope.bar.new_packageqty += $scope.packageqty; //新箱内总数 $scope.bar.newOr_packageqty = data.data.pa_packageqty-$scope.bar.new_packageqty;//原箱总数 $scope.tableParams.reload(); } },function(response){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); }else{ Ring.error(); toaster.pop('error',response.data.exceptionInfo); } }); }; $scope.breakingoutBox = function(){//确认拆分 BatchOper.breakingPackage({param:$scope.bar},angular.fromJson($scope.grid),function(data){ if(data.exceptionInfo){ toaster.pop('error', data.exceptionInfo); Ring.error(); }else{ $scope.bar.new_qty = $scope.bar.new_packageqty = 0; modal(data.message); Ring.success(); } toaster.pop('success',"拆分成功"); },function(response){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); }else{ } }); } $scope.getoutbox1 = function (){//获取原始拆分 新箱号 BatchOper.getOutboxCode({pr_code:$scope.grid[0].pa_prodcode},{},function(data){ if(data.exceptionInfo){ toaster.pop('error', data.exceptionInfo); Ring.error(); }else $scope.bar.newOr_outbox = data.data; },function(response){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); } }); }; $scope.getoutbox2 = function (){//获取拆分箱号 BatchOper.getOutboxCode({pr_code:$scope.grid[0].pa_prodcode},{},function(data){ if(data.exceptionInfo){ toaster.pop('error', data.exceptionInfo); Ring.error(); }else $scope.bar.new_outbox = data.data; },function(response){ if(response.status == 0){ //无网络错误 Online.setOnline(false);//修改网络状态 Ring.error(); toaster.pop('error', "网络连接不可用,请稍后再试"); } }); } $scope.deleteB = function(item){//删除明细 angular.forEach($scope.grid, function(value,key){ if(item.pd_innerboxcode == value.pd_innerboxcode){ $scope.grid.splice(key,1); } }); }; var modal= function(data){ var modalInstance = $modal.open({ templateUrl: 'myModalContent.html', controller: 'ModalInstanceCtrl', resolve: { items: function () { return data; } } }); }; }]); app.controller('UploadCtrl', function($scope, $rootScope, PurcOrderItem, Online){ $scope.upLoadItems = []; angular.forEach($rootScope.orders, function(value,key){//先去获取需要上传的Item(明细) angular.forEach(value.orderItems, function(item, key){ if(item.replyCount) $scope.upLoadItems.push(item); }); }); $scope.upload = function(){//一键上传操作 $scope.netError = false; angular.forEach($scope.upLoadItems, function(item, key){ if(Online.getOnline()) {//判断是否有网 item.loading = 'fa fa-spinner fa-spin';//正在上传 //上传回复,replyCount作为回复数 PurcOrderItem.reply({orderItemId: item.id}, {delivery: new Date().getTime(), qty: item.replyCount, remark: '测试离线后上传'}, function(data){ item.loading = 'fa fa-check-square';//上传成功 item.uploadOk = true; item.replyCount = 0; }, function(response){//请求发生错误 item.loading = 'fa fa-exclamation-triangle text-danger';//上传失败 if(response.status == 0) {//无网络错误 Online.setOnline(false);//修改网络状态 $scope.netError = true; } else {//其他错误 console.log(response.data); } }); } else { $scope.netError = true;//断网提示 return; } }); }; }); return app; });