Просмотр исходного кода

买卖家支付记录日期调整

hulh 8 лет назад
Родитель
Сommit
6b24f4eaae

+ 84 - 5
src/main/webapp/resources/js/usercenter/controllers/forstore/buyer_pay_ctrl.js

@@ -120,10 +120,15 @@ define(['app/app'], function(app) {
 			}
 		});
 
-		$scope.condition = {
-			startDateOpen: false,
-			endDateOpen: false
+		$scope.condition = [];
+		var start = {
+			open : false
 		};
+		var end = {
+			open : false
+		};
+		$scope.condition.push(start);
+		$scope.condition.push(end);
 
 		// 打开日期选择框
 		$scope.openDatePicker = function($event, item, openParam, status) {
@@ -141,7 +146,81 @@ define(['app/app'], function(app) {
 			}
 			$event.preventDefault();
 			$event.stopPropagation();
-			item[openParam] = !item[openParam];
+			openParam == 0 ? $scope.condition[1].open = false : $scope.condition[0].open = false;
+			item[openParam].open = !item[openParam].open;
+		};
+
+		$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.endDate && $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 (!validateDate(text)){
+					// $scope.endDate = text;
+					toaster.pop("info", "请输入正确结束时间格式");
+					return;
+				}
+				if (!$scope.endDate && text != ''){
+					$scope.endDate = convertTextToDate(text);
+				}
+				if ($scope.startDate && $scope.startDate.getTime() > $scope.endDate.getTime()){
+					$scope.startDate = new Date($scope.endDate.getTime() - 86400000);
+				}
+			}
+		};
+
+		/**
+		 * 将文本转化为日期
+		 * @param value
+		 * @returns {Date}
+		 */
+		var convertTextToDate = function (value) {
+			var date = value;
+			var result = date.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
+
+			return new Date(result[1], result[3] - 1, result[4]);
+		};
+
+		/**
+		 * 验证日期格式是否正确
+		 * @param value
+		 * @returns {boolean}
+		 */
+		var validateDate = function (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]);
 		};
 
 		var loadAccountData = function() {
@@ -503,7 +582,7 @@ define(['app/app'], function(app) {
 		};
 
 		$rootScope.$on('$stateChangeStart',function(event,toState,toParams,fromState,fromParams){
-			if(fromState.name == 'pay_center'){
+			if(fromState.name == 'pay_center' || toState.name == 'pay_center'){
 				SessionService.removeCookie("buyCenter");
 			}
 		});

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

@@ -191,7 +191,7 @@ define(['app/app'], function(app) {
                     toaster.pop("info", "请输入正确开始时间格式");
                     return;
                 }
-                if (!validateDate(text)){
+                if (text != '' && !validateDate(text)){
                     // $scope.startDate = text;
                     toaster.pop("info", "请输入正确开始时间格式");
                     return;
@@ -679,7 +679,7 @@ define(['app/app'], function(app) {
         };
 
         $rootScope.$on('$stateChangeStart',function(event,toState,toParams,fromState,fromParams){
-            if(fromState.name == 'pay_center'){
+            if(fromState.name == 'pay_center' || toState.name == 'pay_center'){
                 SessionService.removeCookie("vendorCenter");
             }
         });

+ 10 - 10
src/main/webapp/resources/view/usercenter/forstore/pay_center.html

@@ -432,28 +432,28 @@
 					<div class="sreach fr">
 						<div class="date fl">
 							<div class="data-input">
-								<input type="text" ng-model="startDate"
+								<input id="start" type="text" ng-model="startDate"
 									   class="form-control select-adder" placeholder="起始时间"
 									   datepicker-popup="yyyy-MM-dd"
-									   is-open="condition.startDateOpen"
+									   is-open="condition[0].open"
 									   max-date="endDate" current-text="今天" clear-text="清除" close-text="关闭"
 									   datepicker-options="{formatDayTitle: 'yyyy年M月', formatMonth: 'M月', showWeeks: false}"
-									   ng-click="openDatePicker($event, condition, 'startDateOpen',1)"
-									   ng-change="onDateCondition(true)"/>
-								<button class="open" ng-click="openDatePicker($event, condition, 'startDateOpen')"></button>
+									   ng-click="openDatePicker($event, condition, 0,1)"
+									   ng-blur="onDateCondition(1)"/>
+								<button class="open" ng-click="openDatePicker($event, condition, 0)"></button>
 							</div>
 
 							<em>–</em>
 							<div class="data-input">
-								<input type="text" ng-model="endDate"
+								<input id="end" type="text" ng-model="endDate"
 									   class="form-control select-adder" placeholder="结束时间"
 									   datepicker-popup="yyyy-MM-dd"
-									   is-open="condition.endDateOpen"
+									   is-open="condition[1].open"
 									   min-date="startDate" current-text="今天" clear-text="清除" close-text="关闭"
 									   datepicker-options="{formatDayTitle: 'yyyy年M月', formatMonth: 'M月', showWeeks: false}"
-									   ng-click="openDatePicker($event, condition, 'endDateOpen',2)"
-									   ng-change="onDateCondition(false)"/>
-								<button class="open" ng-click="openDatePicker($event, condition, 'endDateOpen')"></button>
+									   ng-click="openDatePicker($event, condition, 1, 2)"
+									   ng-change="onDateCondition(2)"/>
+								<button class="open" ng-click="openDatePicker($event, condition, 1)"></button>
 							</div>
 						</div>
 						<div class="sreach-input fr">