Browse Source

卖家改价调整

hulh 8 years ago
parent
commit
4363b500b5

+ 41 - 7
src/main/webapp/resources/js/vendor/controllers/forstore/purchase_detail.js

@@ -486,7 +486,25 @@ 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 = "";
 			}
@@ -497,19 +515,26 @@ define(['app/app'], function(app) {
 			if (Number(data.currentTaxUnitPrice) < 0){
 				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 += NumberService.mul(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));
@@ -526,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;
         };
@@ -545,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) {