Browse Source

结算中心日期验证

hulh 8 years ago
parent
commit
5bc404c586

+ 45 - 2
src/main/webapp/resources/js/vendor/controllers/forstore/vendor_pay_ctrl.js

@@ -159,9 +159,52 @@ define(['app/app'], function(app) {
             item[openParam] = !item[openParam];
         };
 
-        $scope.onDateCondition = function () {
+        $scope.onDateCondition = function (bool) {
+            if (!$scope.startDate){
+                $scope.startDate = null;
+                toaster.pop("info", "请输入正确的日期格式");
+                return;
+            }
+            console.log(bool);
+            if (bool){
+                console.log($scope.startDate);
+            }else {
+                console.log($scope.endDate);
+            }
+            // if (bool){
+            //     //验证开始日期格式
+            //     if(!validateDate($scope.startDate)){
+            //         $scope.startDate = null;
+            //         toaster.pop("info", "请输入正确的日期格式");
+            //     }
+            // }else {
+            //     //验证结束日期格式
+            //     if(!validateDate($scope.endDate)){
+            //         $scope.endDate = null;
+            //         toaster.pop("info", "请输入正确的日期格式");
+            //     }
+            // }
+        };
+
+        /**
+         * 验证日期格式是否正确
+         * @param value
+         * @returns {boolean}
+         */
+        var validateDate = function (value) {
             console.log($scope.startDate);
-            console.log($scope.endDate);
+            if (value instanceof Date){
+                console.log(value.getFullYear() + "=" + (value.getMonth() + 1) + "=" + value.getDate());
+                return true;
+            }
+            alert(typeof (value));
+            var date = value;
+            var result = date.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
+
+            if (result == null)
+                return false;
+            var d = new Date(result[1], result[3] - 1, result[4]);
+            return (d.getFullYear() == result[1] && (d.getMonth() + 1) == result[3] && d.getDate() == result[4]);
         };
 
         // 文件上传成功之后