价格 if ($scope.order.orderType == 0) { $scope.order.deliveryPrice = 0; $scope.order.factoryPrice = 0; $scope.order.totalPrice = 0; angular.forEach($scope.order.orderItems, function(item, index) { item.deliveryPrice = 0; item.factoryPrice = 0; item.totalPrice = 0; item.totalPrice = item.price * item.quantity; $scope.order.totalPrice += item.totalPrice; }); } else { // 获取价格 OrderService.getPrice({ order: $scope.order }, function(data) { $scope.order.deliveryPrice = data.deliveryPrice; $scope.order.factoryPrice = data.factoryPrice; $scope.order.totalPrice = data.totalPrice; angular.forEach($scope.order.orderItems, function(item, index) { item.deliveryPrice = data.orderItems[index].deliveryPrice; item.factoryPrice = data.orderItems[index].factoryPrice; item.totalPrice = data.orderItems[index].totalPrice; }); }); } };

		// 更新订单
		$scope.update = function() {
			// 验证
			if (!validate()) {
				return;
			}
			// 手术订单验证
			if (!validateOrderItems()) {
				return;
			}
			// 获取价格
			if ($scope.order.orderType == 0) {
				$scope.order.deliveryPrice = 0;
				$scope.order.factoryPrice = 0;
				$scope.order.totalPrice = 0;
				angular.forEach($scope.order.orderItems, function(item, index) {
					item.deliveryPrice = 0;
					item.factoryPrice = 0;
					item.totalPrice = 0;
					item.totalPrice = item.price * item.quantity;
					$scope.order.totalPrice += item.totalPrice;
				});
			} else {
				// 获取价格
				OrderService.getPrice({
					order: $scope.order
				}, function(data) {
					$scope.order.deliveryPrice = data.deliveryPrice;
					$scope.order.factoryPrice = data.factoryPrice;
					$scope.order.totalPrice = data.totalPrice;
					angular.forEach($scope.order.orderItems, function(item, index) {
						item.deliveryPrice = data.orderItems[index].deliveryPrice;
						item.factoryPrice = data.orderItems[index].factoryPrice;
						item.totalPrice = data.orderItems[index].totalPrice;
					});
					// 更新订单
					OrderService.update({
						order: $scope.order
					}, function(data) {
						$scope.showSuccess('更新订单成功!');
					});
				});
			}
		};

		// 验证
		var validate = function() {
			if (!$scope.order.orderType) {
				$scope.showError('请选择订单类型!');
				return false;
			}
			if (!$scope.order.name) {
				$scope.showError('请填写收件人姓名!');
				return false;
			}
			if (!$scope.order.phone) {
				$scope.showError('请填写收件人电话!');
				return false;
			}
			if (!$scope.order.address) {
				$scope.showError('请填写收件人地址!');
				return false;
			}
			if (!$scope.order.orderItems || $scope.order.orderItems.length == 0) {
				$scope.showError('订单至少需要一个订单项!');
				return false;
			}
			return true;
		};

		// 手术订单验证
		var validateOrderItems = function() {
			if ($scope.order.orderType == 0) {
				for (var i = 0; i < $scope.order.orderItems.length; i++) {
					if (!$scope.order.orderItems[i].name) {
						$scope.showError('请填写订单项名称!');
						return false;
					}
					if ($scope.order.orderItems[i].price === undefined || $scope.order.orderItems[i].price === null) {
						$scope.showError('请填写订单项价格!');
						return false;
					}
					if ($scope.order.orderItems[i].quantity === undefined || $scope.order.orderItems[i].quantity === null) {
						$scope.showError('请填写订单项数量!');
						return false;
					}
					if ($scope.order.orderItems[i].quantity <= 0) {
						$scope.showError('订单项数量必须大于0!');
						return false;
					}
				}
			}
			return true;
		};

		// 添加订单项
		$scope.addOrderItem = function() {
			$scope.order.orderItems.push({
				name: '',
				description: '',
				price: '',
				quantity: 0
			});
		};

		// 删除订单项
取钢板手术价格 - 在线查询手术费用

原文地址: https://www.cveoy.top/t/topic/lnUN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录