Browse Source

Merge remote-tracking branch 'origin/dev-mysql' into dev-mysql

liusw 8 years ago
parent
commit
1ca97b0736

+ 48 - 11
src/main/webapp/resources/js/vendor/controllers/forstore/purchase_detail.js

@@ -486,27 +486,55 @@ define(['app/app'], function(app) {
 			 * 根据采购单编号ID获取采购单信息
 			 */
 		}
+
+		var onUnitPriceChange = function (data, price) {
+			if (angular.isNumber(price)) {
+				if (price >= 10000) {
+					data.currentTaxUnitPrice = Number(price.toString().substring(0, 4));
+				} else if (price.toString().indexOf('.') > -1) {
+					var arr = price.toString().split(".");
+					if (arr[0].length > 4) {
+						data.currentTaxUnitPrice = Number(arr[0].substring(0, 4) + '.' + arr[1]);
+					} else if (arr[1].length > 6) {
+						data.currentTaxUnitPrice = Number(arr[0] + '.' + arr[1].substring(0, 6));
+					}
+				}
+			}
+		};
+
+
 		$scope.updateTotal = function (data) {
+			onUnitPriceChange(data, data.currentTaxUnitPrice);
 			if (data.currentTaxUnitPrice == null){
-				data.currentTaxUnitPrice = 0.000001;
-				return;
+				data.currentTaxUnitPrice = "";
 			}
 			if (isNaN(data.currentTaxUnitPrice)){
-				data.currentTaxUnitPrice = 0.000001;
+				data.currentTaxUnitPrice = "";
 				toaster.pop('warning', '提示', '输入的价格必须是数字');
-				return ;
 			}
 			if (Number(data.currentTaxUnitPrice) < 0){
-				data.currentTaxUnitPrice = 0.000001;
+				data.currentTaxUnitPrice = "";
 			}
-			if (Number(data.currentTaxUnitPrice) > 100000){
-				data.currentTaxUnitPrice = 100000;
+			if (data.currentTaxUnitPrice.length == 0) {
+				data.detailTotal = "-";
+				$scope.purchase.currentTotal = "-";
+				return;
 			}
 			data.currentTaxUnitPrice = Number(NumberService.toCeil(data.currentTaxUnitPrice, 6));
+			data.detailTotal = data.currentTaxUnitPrice * data.number;
 			$scope.purchase.currentTotal = 0;
-			angular.forEach($scope.purchase.purchaseDetails, function (detail) {
-				$scope.purchase.currentTotal += detail.currentTaxUnitPrice * detail.number;
-			});
+			for (var i = 0; i < $scope.purchase.purchaseDetails.length; i++) {
+				if ($scope.purchase.purchaseDetails[i].detailTotal == '-') {
+					$scope.purchase.currentTotal = '-';
+					return;
+				}
+				var taxUnit = $scope.purchase.purchaseDetails[i].currentTaxUnitPrice;
+				var number = $scope.purchase.purchaseDetails[i].number;
+				$scope.purchase.currentTotal += NumberService.mul(taxUnit, number);
+			}
+			if ($scope.purchase.currentTotal == '-') {
+				return;
+			}
 			//加上运费
 			$scope.purchase.currentTotal = NumberService.add($scope.purchase.currentTotal, $scope.purchase.fare);
 			$scope.purchase.currentTotal = Number(NumberService.toCeil($scope.purchase.currentTotal, 2));
@@ -523,6 +551,7 @@ define(['app/app'], function(app) {
 			}
 			angular.forEach($scope.purchase.purchaseDetails, function (detail) {
 				detail.currentTaxUnitPrice = detail.taxUnitPrice;
+				detail.detailTotal = detail.taxUnitPrice * detail.number;
 			});
 			$scope.purchase.currentTotal = $scope.purchase.ensurePrice;
         };
@@ -542,12 +571,20 @@ define(['app/app'], function(app) {
                 var param = { };
                 param.detailid  = $scope.purchase.purchaseDetails[i].detailid;
                 param.modifyingUnitPrice = $scope.purchase.purchaseDetails[i].currentTaxUnitPrice;
-                if($scope.purchase.purchaseDetails[i].currentTaxUnitPrice < 0.000001){
+				if ($scope.purchase.purchaseDetails[i].detailTotal == '-'){
+					toaster.pop('info', '单价不能为空');
+					return;
+				}
+                if ($scope.purchase.purchaseDetails[i].currentTaxUnitPrice < 0.000001){
                     toaster.pop('info', '金额必须要大于0.000001');
                     return;
                 }
                 list.push(param);
 			}
+			if ($scope.purchase.currentTotal == '-') {
+				toaster.pop('info', '单价不能为空');
+				return;
+			}
             Purchase.savePurchasePrice({ }, list, function(response){
                 $scope.isChange = false;
                 Purchase.findPurchaseByPurchaseId({ purchaseId : $scope.purchaseId }, null, function (result) {

+ 1 - 1
src/main/webapp/resources/view/vendor/forstore/purchase_detail.html

@@ -521,7 +521,7 @@
 						</span>
 							<span style="width: 10%;" ng-bind="detail.number">100</span>
 							<span ng-show="!isChange" class="wd01 red" ng-bind="detail.taxUnitPrice * detail.number | formateNumber : 6 | currencySysmbol : detail.currencyName"></span>
-							<span ng-show="isChange" class="wd01 red" ng-bind="detail.currentTaxUnitPrice * detail.number | formateNumber : 6 | currencySysmbol : detail.currencyName"></span>
+							<span ng-show="isChange" class="wd01 red" ng-bind="detail.detailTotal | formateNumber : 6 | currencySysmbol : detail.currencyName"></span>
 							<!--物料编码-->
 							<span class="wd01" style="line-height: 18px;">
 								<em ng-if="!detail.goodsnumber">&nbsp;</em>