'use strict';

angular.module('app').controller('ChartController', ['$scope', '$state', '$filter', '$http', function($scope, $state, $filter, $http) {

    $scope.now = new Date(); //控制器中使用 
    $scope.nowDate = $filter("date")($scope.now, "yyyy-MM-dd");
    $scope.sdate = $scope.nowDate;
    $scope.checkId = false;

    $scope.currentPage = 1; //初始当前页
    $scope.maxSize = 5; //最多显示7页其他的用···代替
    $scope.search = function() {
        $http({
                method: 'POST',
                url: '/getSMSCount',
                data: $.param({ name: $scope.inval, checkId: $scope.checkId, year: $scope.sdate.substring(0, 4), month: $scope.sdate.substring(5, 7), date: $scope.sdate }), // pass in data as strings
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
            })
            .success(function(data) {
                if (data) {
                    // if not successful, bind errors to error variables
                    console.log(JSON.stringify(data));
                    $scope.allitem = []; //存放所有页
                    $scope.addr = data;
                    var num = $scope.addr.length;
                    $scope.totalItems = num; //共有多少条数据
                    for (var i = 0; i < num; i += 10) {
                        $scope.allitem.push($scope.addr.slice(i, i + 10));
                    } //此方法可以将一个数组分成多个数组并且放在了一个大数组里面，按每个数组10条数据【因为组件默认为10条数据一页】存放，假如41条数据的话我们将分成5页
                } else if (data == "") {
                    alert("登录名不存在");
                }
            });
    };

    $scope.infoView = function(data) {
        $scope.userInfo = data;
        $scope.userInfo.FirstTime = $scope.userInfo.SendTime.substring(0, 10);
        $scope.userInfo.LastTime = $scope.userInfo.SendTime.substring(11, 19);
        console.log($scope.userInfo);
    };

}]);