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

后台管理-数据中心 时间筛选问题

yangc 7 лет назад
Родитель
Сommit
a103ed6a11

+ 11 - 6
src/main/webapp/resources/js/admin/controllers/statsDataCtrl.js

@@ -64,8 +64,8 @@ define([ 'app/app' ], function(app) {
             if (val != 'autoMonth') {
                 initData();
             } else {
-                $scope.startDate = null;
-                $scope.endDate = null;
+                // $scope.startDate = '';
+                // $scope.endDate = '';
             }
         };
 
@@ -86,7 +86,12 @@ define([ 'app/app' ], function(app) {
             item[openParam].open = !item[openParam].open;
         };
 
-        $scope.onDateCondition = function (bool) {
+        $scope.onDateCondition = function (bool, date) {
+            if (bool == 1) {
+                $scope.startDate = date;
+            } else {
+                $scope.endDate = date;
+            }
             var startTime = $scope.startDate ? $scope.startDate.getTime() : null;
             var endTime = $scope.endDate ? $scope.endDate.getTime() : null;
             if (startTime && endTime && startTime > endTime) {
@@ -174,7 +179,7 @@ define([ 'app/app' ], function(app) {
         var getProductData = function () {
             // 上传产品个数
             var defer = $q.defer();
-            Goods.getProductsCmp({fromDate: $scope.startDate.getTime(), toDate: $scope.endDate.getTime()}, function (data) {
+            Goods.getProductsCmp({fromDate: $scope.startDate && $scope.startDate.getTime(), toDate: $scope.endDate && $scope.endDate.getTime()}, function (data) {
                 defer.resolve(data.data);
             }, function (err) {
                 defer.reject(err);
@@ -205,8 +210,8 @@ define([ 'app/app' ], function(app) {
         };
         // 获取不同时间阶段的相关数据
         var initData = function () {
-            var addStartDate = new Date($scope.startDate.getTime() + 24 * 60 * 60 * 1000),
-            addEndDate = new Date($scope.endDate.getTime() + 24 * 60 * 60 * 1000);
+            var addStartDate = $scope.startDate && new Date($scope.startDate.getTime() + 24 * 60 * 60 * 1000),
+            addEndDate = $scope.endDate && new Date($scope.endDate.getTime() + 24 * 60 * 60 * 1000);
             $scope.addStartFormatDate = _formatDate(addStartDate, 'yyyy-MM-dd');
             $scope.addEndFormatDate = _formatDate(addEndDate, 'yyyy-MM-dd');
             $scope.startFormatDate = _formatDate($scope.startDate, 'yyyy-MM-dd');

+ 2 - 2
src/main/webapp/resources/view/admin/stats_data.html

@@ -341,7 +341,7 @@
                                    current-text="今天" clear-text="清除" close-text="关闭"
                                    datepicker-options="{formatDayTitle: 'yyyy年M月', formatMonth: 'M月', showWeeks: false}"
                                    ng-click="openDatePicker($event, condition, 0,1)"
-                                   ng-change="onDateCondition(1)"/>
+                                   ng-change="onDateCondition(1, startDate)"/>
                             <button class="open" ng-click="openDatePicker($event, condition, 0)"></button>
                         </div>
                         <strong>–</strong>
@@ -353,7 +353,7 @@
                                    current-text="今天" clear-text="清除" close-text="关闭"
                                    datepicker-options="{formatDayTitle: 'yyyy年M月', formatMonth: 'M月', showWeeks: false}"
                                    ng-click="openDatePicker($event, condition, 1, 2)"
-                                   ng-change="onDateCondition(2)"/>
+                                   ng-change="onDateCondition(2, endDate)"/>
                             <button class="open" ng-click="openDatePicker($event, condition, 1)"></button>
                         </div>
                     </div>