|
|
@@ -0,0 +1,249 @@
|
|
|
+define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ui.router', 'ui.bootstrap' ], function() {
|
|
|
+ 'use strict';
|
|
|
+ var app = angular.module('myApp', ['ngAnimate', 'toaster', 'ui.router', 'common.services', 'PurcServices', 'ui.bootstrap' ]);
|
|
|
+ app.init = function() {
|
|
|
+ angular.bootstrap(document, [ 'myApp' ]);
|
|
|
+ };
|
|
|
+
|
|
|
+ app.config(function($stateProvider, $urlRouterProvider) {
|
|
|
+ $urlRouterProvider.otherwise('/index');
|
|
|
+ $stateProvider.state('index', {
|
|
|
+ url : "/index",
|
|
|
+ templateUrl : "static/tpl/index_mobile/storage/index.html"
|
|
|
+ }).state('input', {
|
|
|
+ url : "/input",
|
|
|
+ templateUrl : "static/tpl/index_mobile/storage/input.html"
|
|
|
+ }).state('inputOperation', {
|
|
|
+ url: '/input/:code',
|
|
|
+ templateUrl: 'static/tpl/index_mobile/storage/inputOperation.html'
|
|
|
+ }).state('upload', {
|
|
|
+ url: '/upload',
|
|
|
+ templateUrl: 'static/tpl/index_mobile/storage/needToUpload.html'
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ app.factory('Symbol', function(){//符号
|
|
|
+ return {
|
|
|
+ currency: function(cur) {//把币别转换成对应的符号
|
|
|
+ if(cur == 'RMB') return '¥';
|
|
|
+ else if(cur == 'USD') return '$';
|
|
|
+ else if(cur == 'EUR') return '€';
|
|
|
+ else return cur;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }).factory('Ring', function(){//响铃,直接调用
|
|
|
+ return {
|
|
|
+ success: function(){
|
|
|
+ document.getElementById('successRing').play();
|
|
|
+ }, error: function(){
|
|
|
+ document.getElementById('errorRing').play();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).factory('Online', function($rootScope){//在线状态,全局获取、设置
|
|
|
+ var status = {online: true};
|
|
|
+ return {
|
|
|
+ setOnline: function(value){
|
|
|
+ status.online = value;
|
|
|
+ $rootScope.$broadcast('online', value);
|
|
|
+ }, getOnline: function(){
|
|
|
+ return status.online;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ app.controller('IndexCtrl', function($scope, $rootScope){
|
|
|
+ //获取需要上传的数量
|
|
|
+ $scope.getNeedUpCount = function(){
|
|
|
+ var count = 0;
|
|
|
+ angular.forEach($rootScope.orders, function(value,key){
|
|
|
+ angular.forEach(value.orderItems, function(item, key){
|
|
|
+ if(item.replyCount) count += 1;//存在replyCount并且>0就需要上传
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return count;
|
|
|
+ };
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ app.controller('StatusCtrl', function($scope, $http, Online){
|
|
|
+ $scope.status = {online: true};
|
|
|
+
|
|
|
+ $scope.$watch('status.online', function(value){//检测用户手动切换在线状态
|
|
|
+ Online.setOnline(value);
|
|
|
+ });
|
|
|
+
|
|
|
+ $scope.$on('online', function(data){//监听Service中的状态变化
|
|
|
+ $scope.status.online = Online.getOnline();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ app.controller('InputCtrl', function($scope, $http, $rootScope, $location, toaster, PurcOrder, Ring, Online){
|
|
|
+ $scope.orders = $rootScope.orders || [];
|
|
|
+
|
|
|
+ var contains = function(array, element) {//根据ID判断数组是否包含某个元素
|
|
|
+ var result = false;
|
|
|
+ angular.forEach(array, function(value, key){
|
|
|
+ if(value.id == element.id) {//ID相等即包含
|
|
|
+ result = true;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.getOrder = function(code) {//根据输入的单据id号获取下载单据信息
|
|
|
+ $scope.selectedId = code;
|
|
|
+ console.log('online--' + Online.getOnline());
|
|
|
+ if(contains($scope.orders, {id: code})){//请求的单据id已经被下载在本地了
|
|
|
+
|
|
|
+ } else {//请求的单据id未被下载在本地了,向服务器发送请求获取数据
|
|
|
+ PurcOrder.get({id: code}, function(data) {//获取成功
|
|
|
+ $scope.getError = false;
|
|
|
+ $scope.orders.push(data);
|
|
|
+ $rootScope.orders = $scope.orders;
|
|
|
+ }, function(response){//获取失败处理
|
|
|
+ $scope.errorCode = code;
|
|
|
+ $scope.getError = true;
|
|
|
+ setTimeout(function(){//2s后取消错误提示,好像没用。。。
|
|
|
+ $scope.getError = false;
|
|
|
+ $scope.errorCode = code;
|
|
|
+ }, 2000);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ Ring.success();//提示成功响铃
|
|
|
+ $scope.batchCode = '';//重置输入框
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.search = function($event, batchCode){//enter键触发事件
|
|
|
+ if($event.keyCode == 13) {//Enter事件
|
|
|
+ $scope.getOrder(batchCode);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.totalQty = function(order) {//获取当前单据还未扫描的物料数量
|
|
|
+ var result = 0;
|
|
|
+ angular.forEach(order.orderItems, function(value, key){
|
|
|
+ result += value.qty - value.replyQty;
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.operate = function(order) {//跳转至对应的单据操作页面
|
|
|
+ $scope.selectedId = order.id;
|
|
|
+ $location.path('input/' + order.id);
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ app.controller('InputOperationCtrl', function($scope, $http, $stateParams, $rootScope, toaster, Ring, PurcOrderItem, Online){
|
|
|
+ var getOrder = function(code) {//根据路径中的id号获取对应的单据
|
|
|
+ var result = null;
|
|
|
+ angular.forEach($rootScope.orders, function(value, key){
|
|
|
+ if(value.id == code) {
|
|
|
+ result = value;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+ };
|
|
|
+
|
|
|
+ var containsProduct = function(id) {//判断物料Id是否包含于当前单据
|
|
|
+ var result = null;
|
|
|
+ angular.forEach($scope.order.orderItems, function(value, key){
|
|
|
+ if(value.product.id == id) {
|
|
|
+ result = value;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.order = getOrder($stateParams.code);
|
|
|
+ $scope.getOnline = Online.getOnline;
|
|
|
+
|
|
|
+ $scope.scan = function(id){//扫描事件
|
|
|
+ $scope.noProduct = false;
|
|
|
+ $scope.overError = false;
|
|
|
+ var item = containsProduct(id);
|
|
|
+ if(item){//是当前单据中对应的物料
|
|
|
+ if((item.replyQty||0) < item.qty){
|
|
|
+ Ring.success();
|
|
|
+ $scope.selectedId = item.id;
|
|
|
+ item.replyQty = item.replyQty || 0;
|
|
|
+ item.replyQty += 1;
|
|
|
+ if(Online.getOnline()){//有网络连接
|
|
|
+ //向后台交互
|
|
|
+ PurcOrderItem.reply({orderItemId: item.id}, {delivery: new Date().getTime(), qty: 1, remark: '测试扫描技术'},
|
|
|
+ function(data){}, function(response){//请求发生错误
|
|
|
+ if(response.status == 0) {//无网络错误
|
|
|
+ Online.setOnline(false);//修改网络状态
|
|
|
+ item.replyCount = item.replyCount || 0;
|
|
|
+ item.replyCount += 1;//添加属性并+1(作为需要上传的标志)
|
|
|
+ } else {//其他错误
|
|
|
+ console.log(response.data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {//无网络连接,如无网络错误操作
|
|
|
+ item.replyCount = item.replyCount || 0;
|
|
|
+ item.replyCount += 1;
|
|
|
+ }
|
|
|
+ } else {//不是当前的物料
|
|
|
+ $scope.overError = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Ring.error();
|
|
|
+ $scope.selectedId = 0;
|
|
|
+ $scope.noProduct = true;
|
|
|
+ }
|
|
|
+ $scope.productCode = '';
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.search = function($event, productCode){
|
|
|
+ if($event.keyCode == 13) {//Enter事件
|
|
|
+ $scope.scan(productCode);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.pecent = function(numerator, denominator){//输入分母分子获取对应的百分数
|
|
|
+ return ((numerator/denominator).toFixed(2) * 100);
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ 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;
|
|
|
+});
|