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.failedCard")
    }
    $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.cardType = 0;
    $scope.check_type = function (typeCode) {
        cardType = typeCode;
        console.log($rootScope.loginData.state, "----测试-----", $scope.dt, "====", typeCode, "+++++++++++++");
    }
    // // 查询废证列表
    // var getFailedCardListData = function (state,workshop) {
    //     HttpService.findFailedinfo(1,workshop,function (data) {
    //         $scope.failedCardList = data.respData;
    //         console.log("---制证类型--数据源:")
    //         console.log(data.respData)
    //
    //     })
    // }
    // getFailedCardListData($rootScope.loginData.state,$rootScope.loginData.workshop);

    $scope.failedCardList = [
        {
            "acceptNo": "201802",
            "failedCardReason": "切废",
            failedCardId: 201811205,
            taskID: 201811203,
            positionDate: "20181108",
            finishDate: "20181109",
            allotDate: "20181203",
            printDate: "20181204",
            state: 2
        },
        {
            "acceptNo": "2018035",
            "failedCardReason": "电写入废",
            failedCardId: 201811206,
            taskID: 201811204,
            positionDate: "20181108",
            finishDate: "20181109",
            allotDate: "20181203",
            printDate: "20181204",
            state: 2
        },
        {
            "acceptNo": "2018036",
            "failedCardReason": "冲切废",
            failedCardId: 201811207,
            taskID: 201811205,
            positionDate: "20181108",
            finishDate: "20181109",
            allotDate: "20181203",
            printDate: "20181204",
            state: 2
        }
    ]


    $scope.finishClick = function (taskId, userState) {
        HttpService.updateProductionTask(taskId, userState, function (data) {
            //点击确认成功后  再次废证列表
            getFailedCardListData($rootScope.loginData.state, $rootScope.loginData.workshop);
        })
    }

    $scope.folds = [
        {
            id: 1, name: '普通证', count: 10000, filter: '', isActive: true, dataTable: {
                "aaData": [
                    {
                        "engine": "Trident",
                        "browser": "Internet Explorer 4.0",
                        "platform": "Win 95+",
                        "version": "4",
                        "grade": "X"
                    },
                    {
                        "engine": "Trident",
                        "browser": "Internet Explorer 5.0",
                        "platform": "Win 95+",
                        "version": "5",
                        "grade": "C"
                    }]
            }
        },
        {
            id: 2, name: '邮寄证', count: 20000, filter: 'starred', dataTable: {
                "aaData": [
                    {
                        "engine": "Trident",
                        "browser": "Internet Explorer 5.5",
                        "platform": "Win 95+",
                        "version": "5.5",
                        "grade": "A"
                    },
                    {
                        "engine": "Trident",
                        "browser": "Internet Explorer 6",
                        "platform": "Win 98+",
                        "version": "6",
                        "grade": "A"
                    },
                    {
                        "engine": "Trident",
                        "browser": "Internet Explorer 7",
                        "platform": "Win XP SP2+",
                        "version": "7",
                        "grade": "A"
                    }]
            }
        },
        {
            id: 3, name: '军人证', count: 32000, filter: 'sent', dataTable: {
                "aaData": [
                    {
                        "engine": "Trident",
                        "browser": "Internet Explorer 5.5",
                        "platform": "Win 95+",
                        "version": "5.5",
                        "grade": "A"
                    }]
            }
        },
        {
            id: 4, name: '快证', count: 40, filter: 'important', dataTable: {
                "aaData": [
                    {
                        "engine": "Webkit",
                        "browser": "Safari 1.3",
                        "platform": "OSX.3",
                        "version": "312.8",
                        "grade": "A"
                    },
                    {
                        "engine": "Webkit",
                        "browser": "Safari 2.0",
                        "platform": "OSX.4+",
                        "version": "419.3",
                        "grade": "A"
                    },
                    {
                        "engine": "Webkit",
                        "browser": "Safari 3.0",
                        "platform": "OSX.4+",
                        "version": "522.1",
                        "grade": "A"
                    },
                    {
                        "engine": "Webkit",
                        "browser": "OmniWeb 5.5",
                        "platform": "OSX.4+",
                        "version": "420",
                        "grade": "A"
                    },
                    {
                        "engine": "Webkit",
                        "browser": "iPod Touch / iPhone",
                        "platform": "iPod",
                        "version": "420.1",
                        "grade": "A"
                    }]
            }
        }
    ];

    $scope.currentTab = 1;
    $scope.func = function (id) {
        for (var i = 0; i < $scope.folds.length; i++) {
            if (id == $scope.folds[i].id) {
                $scope.folds[i].isActive = true;
            } else {
                $scope.folds[i].isActive = false;
            }
        }
        $scope.currentTab = id;
    }

}]);