Selaa lähdekoodia

修改时间选择问题

yangc 7 vuotta sitten
vanhempi
commit
955aacbe10

+ 13 - 43
src/main/webapp/resources/js/usercenter/controllers/forstore/pay_center_ctrl.js

@@ -166,51 +166,21 @@ define(['app/app'], function(app) {
 		};
 
 		$scope.onDateCondition = function (bool) {
-			// var text = '';
-			// var datePattern = /^(\d{4})-(\d{2})-(\d{2})$/;
-			if (bool == 1){
-				// text = document.getElementById("start").value;
-				// if (text != '' && !datePattern.test(text)){
-				// 	toaster.pop("info", "请输入正确开始时间格式");
-				// 	return;
-				// }
-				// if (text != '' && !validateDate(text)){
-				// 	toaster.pop("info", "请输入正确开始时间格式");
-				// 	return;
-				// }
-				// if (!$scope.startDate && text != ''){
-				// 	$scope.startDate = convertTextToDate(text);
-				// }
-				if ($scope.startDate && !$scope.endDate){
-					var nowTime = new Date();
-					$scope.endDate = new Date(nowTime.getFullYear(), nowTime.getMonth(), nowTime.getDate());
-				}
-				if ($scope.startDate && $scope.endDate){
-					if ($scope.startDate.getTime() > $scope.endDate.getTime()){
-						$scope.endDate = new Date($scope.startDate.getTime() + 86400000);
-					}
-				}
-			}else {
-				// text = document.getElementById("end").value;
-				// if (text != '' && !datePattern.test(text)){
-				// 	// $scope.endDate = text;
-				// 	toaster.pop("info", "请输入正确结束时间格式");
-				// 	return;
-				// }
-				// if (text != '' && !validateDate(text)){
-				// 	// $scope.endDate = text;
-				// 	toaster.pop("info", "请输入正确结束时间格式");
-				// 	return;
-				// }
-				// if (!$scope.endDate && text != ''){
-				// 	$scope.endDate = convertTextToDate(text);
-				// }
-				if ($scope.startDate && $scope.endDate){
-					if ($scope.startDate.getTime() > $scope.endDate.getTime()){
-						$scope.startDate = new Date($scope.endDate.getTime() - 86400000);
-					}
+			var startTime = $scope.startDate ? $scope.startDate.getTime() : null;
+			var endTime = $scope.endDate ? $scope.endDate.getTime() : null;
+			if (startTime && endTime && startTime > endTime) {
+				if (bool == 1) {
+					toaster.pop('info', '起始时间不能大于结束时间');
+					$scope.startDate = null;
+				} else {
+					toaster.pop('info', '结束时间不能小于起始时间');
+					$scope.endDate = null;
 				}
 			}
+			if ($scope.endDate && bool == 2) {
+				$scope.endDate = new Date($scope.endDate.getFullYear(), $scope.endDate.getMonth(), $scope.endDate.getDate())
+				$scope.endDate = new Date($scope.endDate.getTime() + 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000);
+			}
 			loadPayHistory();
 		};
 

+ 13 - 45
src/main/webapp/resources/js/vendor/controllers/forstore/pay_center_ctrl.js

@@ -277,53 +277,21 @@ define(['app/app'], function(app) {
         };
 
         $scope.onDateCondition = function (bool) {
-            // var text = '';
-            // var datePattern = /^(\d{4})-(\d{2})-(\d{2})$/;
-            if (bool == 1){
-                // text = document.getElementById("start").value;
-                // if (text != '' && !datePattern.test(text)){
-                //     // $scope.startDate = text;
-                //     toaster.pop("info", "请输入正确开始时间格式");
-                //     return;
-                // }
-                // if (text != '' && !validateDate(text)){
-                //     // $scope.startDate = text;
-                //     toaster.pop("info", "请输入正确开始时间格式");
-                //     return;
-                // }
-                // if (!$scope.startDate && text != ''){
-                //     $scope.startDate = convertTextToDate(text);
-                // }
-                if ($scope.startDate && !$scope.endDate){
-                    var nowTime = new Date();
-                    $scope.endDate = new Date(nowTime.getFullYear(), nowTime.getMonth(), nowTime.getDate());
-                }
-                if ($scope.startDate && $scope.endDate){
-                    if ($scope.startDate.getTime() > $scope.endDate.getTime()){
-                        $scope.endDate = new Date($scope.startDate.getTime() + 86400000);
-                    }
-                }
-            }else {
-                // text = document.getElementById("end").value;
-                // if (text != '' && !datePattern.test(text)){
-                //     // $scope.endDate = text;
-                //     toaster.pop("info", "请输入正确结束时间格式");
-                //     return;
-                // }
-                // if (text != '' && !validateDate(text)){
-                //     // $scope.endDate = text;
-                //     toaster.pop("info", "请输入正确结束时间格式");
-                //     return;
-                // }
-                // if (!$scope.endDate && text != ''){
-                //     $scope.endDate = convertTextToDate(text);
-                // }
-                if ($scope.startDate && $scope.endDate){
-                    if ($scope.startDate.getTime() > $scope.endDate.getTime()){
-                        $scope.startDate = new Date($scope.endDate.getTime() - 86400000);
-                    }
+            var startTime = $scope.startDate ? $scope.startDate.getTime() : null;
+            var endTime = $scope.endDate ? $scope.endDate.getTime() : null;
+            if (startTime && endTime && startTime > endTime) {
+                if (bool == 1) {
+                    toaster.pop('info', '起始时间不能大于结束时间');
+                    $scope.startDate = null;
+                } else {
+                    toaster.pop('info', '结束时间不能小于起始时间');
+                    $scope.endDate = null;
                 }
             }
+            if ($scope.endDate && bool == 2) {
+                $scope.endDate = new Date($scope.endDate.getFullYear(), $scope.endDate.getMonth(), $scope.endDate.getDate())
+                $scope.endDate = new Date($scope.endDate.getTime() + 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000);
+            }
             loadHistory();
         };