app.controller('failedCardCtrl', ['$scope', '$rootScope', '$http', '$state', '$filter', '$localStorage', 'HttpService', 'ngDialog', function ($scope, $rootScope, $http, $state, $filter, $localStorage, HttpService, ngDialog) {
    if($rootScope.loginData.login === false){
        $state.go("signin")
    }else {
        $state.go("layout.searchSpecialCard")
    }
    $scope.goBack = function(){
        $state.go("layout.cycleSheet")
    }

    $scope.userState=$rootScope.loginData.state;
    var getNowFormatDate = function () {
        var date = new Date();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + "/" + month +"/"+ strDate;
        return currentdate;
    }
    $scope.today = function() {
        $scope.dt = getNowFormatDate();
    };
    $scope.today();

    $scope.clear = function () {
        $scope.dt = null;
    };
    $scope.disabled = function(date, mode) {
        return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
    };

    $scope.toggleMin = function() {
        $scope.minDate = $scope.minDate ? null : new Date();
    };
    $scope.toggleMin();

    $scope.open = function($event) {
        $event.preventDefault();
        $event.stopPropagation();

        $scope.opened = true;
    };

    $scope.dateOptions = {
        formatYear: 'yy',
        startingDay: 1,
        class: 'datepicker'
    };

    $scope.initDate = new Date('2016-15-20');
    $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
    $scope.format = $scope.formats[1];
    $scope.task_click = function(){
        console.log($rootScope.loginData.state,"----测试-----",$scope.dt,"====");
    }

    $scope.createCycleSheet = function (groupState, acceptNo, type) {
        $("#addBtn").attr("disabled", true);
        var arr = [];
        var json = {};
        json.acceptNo = acceptNo;
        json.type = type;
        arr.push(json);
        if (groupState == '新组' || groupState == '正在审核') {
            MessageService.showAlert("未核验的组不能添加特证！");
            $("#addBtn").removeAttr("disabled");
        } else {
            console.log(arr)
            HttpService.saveSpecialCycle(arr, function (data) {
                console.log(data)
                console.log("------------")
                if (data.respData.string == 1) {
                    MessageService.showAlert("加入特证成功。")
                    console.log($rootScope.searchInput)
                    HttpService.querySpecialCardInfo($rootScope.searchInput, function (data) {
                        if (data != null) {
                            $rootScope.specialCardInfo = data.respData;
                            console.log("搜索结果")
                            console.log(data.respData)
                        }
                    })
                } else {
                    MessageService.showAlert("添加特证失败。");
                }

            })
        }

    }
    $scope.returnCard = function (acceptNo) {
        $("#returnBtn").attr("disabled", true);
        HttpService.createSpecailCardPkg(cardid, function (data) {
            MessageService.showAlert("退证成功。")
        })
    }


}]);