app.controller('cycleSheetCtrl', ['$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.cycleSheet")
    }
    $scope.userState = $rootScope.loginData.state;
    // $scope.userState=5;

    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;
    };

    // Disable weekend selection
    $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 getTypeListData = function (state) {
    //     HttpService.getTypeListByTaskStateId(1,function (data) {
    //         $scope.typeList = data.respData;
    //         console.log("---制证类型--数据源:")
    //         console.log(data.respData)
    //
    //     })
    // }
    // getTypeListData($rootScope.loginData.state);

    // $scope.nowType == $scope.getCityListData[$scope.currentTab].typeCode? $scope.currentTab=$scope.currentTab:$scope.currentTab= -1;
    // for (var i = 0; i < $scope.getCityListData.length; i++) {
    //
    //     if (i == $scope.currentTab) {
    //         $scope.getCityListData[i].isActive = true;
    //     } else {
    //         $scope.getCityListData[i].isActive = false;
    //     }
    // }

    // // 查询城市列表
    // var getCityListData = function (cardType,state) {
    //     HttpService.getCityListByCardType(cardType,1,function (data) {
    //         $scope.cityList = data.respData;
    //         console.log("---城市列表--数据源:")
    //         console.log(data.respData)
    //
    //     })
    // }
    // getCityListData(cardType,$rootScope.loginData.state);

    // // 查询组号列表
    // var getGroupListData = function (taskId) {
    //     HttpService.getGroupNoByTaskListId(taskId,function (data) {
    //         $scope.groupList = data.respData;
    //         console.log("---查询组号列表--数据源:")
    //         console.log(data.respData)
    //
    //     })
    // }


    // // 查询区县列表
    // var getCountyListData = function (taskId) {
    //     HttpService.getCountyListByTaskListId(taskId,function (data) {
    //         $scope.countyList = data.respData;
    //         console.log("---查询区县列表--数据源:")
    //         console.log(data.respData)
    //
    //     })
    // }

    $scope.typeList = [
        {typeCode: 0, typeCount: 5000, typeName: '普通证'},
        {typeCode: 1, typeCount: 5000, typeName: '邮寄证'},
        {typeCode: 2, typeCount: 5000, typeName: '特殊证'},
        {typeCode: 9, typeCount: 5000, typeName: '异地证'},
    ]
    $scope.cityList = [
        {
            "card_Type": 1,
            "citycode": "410300",
            cityName: "郑州",
            groupCount: 10,
            groupSum: 1500,
            groupInvailedSum: 15,
            groupNO: "1-25",
            "download_Date": null,
            "exception_Information": "",
            "in_Storage_Date": null,
            "is_Exception": 0,
            "issued_Date": null,
            "old_Card_Type": 1,
            "out_Storage_Date": null,
            "out_Workshop_Date": null,
            "position_Date": null,
            "print_Out_Date": null,
            "print_State": 0,
            "printer_Id": 0,
            "quality_People_Name": "",
            "quality_Test_Date": null,
            "submit_Date": {
                "date": 20,
                "day": 2,
                "hours": 11,
                "minutes": 20,
                "month": 10,
                "seconds": 53,
                "time": 1542684053000,
                "timezoneOffset": -480,
                "year": 118
            },
            "task_Id": 201811203,
            "task_State_Id": 1
        },
        {
            "card_Type": 1,
            "citycode": "410400",
            cityName: "驻马店",
            groupCount: 10,
            groupSum: 2500,
            groupInvailedSum: 16,
            groupNO: "26-45",
            "download_Date": null,
            "exception_Information": "",
            "in_Storage_Date": null,
            "is_Exception": 0,
            "issued_Date": null,
            "old_Card_Type": 1,
            "out_Storage_Date": null,
            "out_Workshop_Date": null,
            "position_Date": null,
            "print_Out_Date": null,
            "print_State": 0,
            "printer_Id": 0,
            "quality_People_Name": "",
            "quality_Test_Date": null,
            "submit_Date": {
                "date": 20,
                "day": 2,
                "hours": 11,
                "minutes": 20,
                "month": 10,
                "seconds": 53,
                "time": 1542684053000,
                "timezoneOffset": -480,
                "year": 118
            },
            "task_Id": 201811204,
            "task_State_Id": 1
        },
        {
            "card_Type": 1,
            "citycode": "410500",
            cityName: "新乡",
            groupCount: 10,
            groupSum: 3500,
            groupInvailedSum: 17,
            groupNO: "46",
            "download_Date": null,
            "exception_Information": "",
            "in_Storage_Date": null,
            "is_Exception": 0,
            "issued_Date": null,
            "old_Card_Type": 1,
            "out_Storage_Date": null,
            "out_Workshop_Date": null,
            "position_Date": null,
            "print_Out_Date": null,
            "print_State": 0,
            "printer_Id": 0,
            "quality_People_Name": "",
            "quality_Test_Date": null,
            "submit_Date": {
                "date": 20,
                "day": 2,
                "hours": 11,
                "minutes": 20,
                "month": 10,
                "seconds": 53,
                "time": 1542684053000,
                "timezoneOffset": -480,
                "year": 118
            },
            "task_Id": 201811205,
            "task_State_Id": 1
        },
        {
            "card_Type": 1,
            "citycode": "410600",
            cityName: "周口",
            groupCount: 10,
            groupSum: 3500,
            groupInvailedSum: 18,
            groupNO: "48-52,53-55",
            "download_Date": null,
            "exception_Information": "",
            "in_Storage_Date": null,
            "is_Exception": 0,
            "issued_Date": null,
            "old_Card_Type": 1,
            "out_Storage_Date": null,
            "out_Workshop_Date": null,
            "position_Date": null,
            "print_Out_Date": null,
            "print_State": 0,
            "printer_Id": 0,
            "quality_People_Name": "",
            "quality_Test_Date": null,
            "submit_Date": {
                "date": 20,
                "day": 2,
                "hours": 11,
                "minutes": 20,
                "month": 10,
                "seconds": 53,
                "time": 1542684053000,
                "timezoneOffset": -480,
                "year": 118
            },
            "task_Id": 201811206,
            "task_State_Id": 1
        },
    ]

    $scope.groupList = [
        {
            "groupNO": 45,
            "vaildCount": 45,
            invaildCount: 25,
            specialCardCount: 5,
            specialCardList: [{acceptNo: 20180401, specialType: 1}, {acceptNo: 20180401, specialType: 1}]
        },
        {
            "groupNO": 45,
            "vaildCount": 45,
            invaildCount: 25,
            specialCardCount: 5,
            specialCardList: [{acceptNo: 20180401, specialType: 1}, {acceptNo: 20180401, specialType: 1}]
        },
        {
            "groupNO": 45,
            "vaildCount": 45,
            invaildCount: 25,
            specialCardCount: 5,
            specialCardList: [{acceptNo: 20180401, specialType: 1}, {acceptNo: 20180401, specialType: 1}]
        }
    ]
    $scope.countyList = [
        {
            "countyName": "许昌县",
            county_Code: "411023",
            downloadCount: 240,
            electric_writerCount: 240,
            in_Storage_Count: 240,
            out_Storage_Count: 240,
            finish_Count: 240
        },
        {
            "countyName": "禹州",
            county_Code: "411081",
            downloadCount: 210,
            electric_writerCount: 210,
            in_Storage_Count: 210,
            out_Storage_Count: 210,
            finish_Count: 210
        },
        {
            "countyName": "长葛",
            county_Code: "411082",
            downloadCount: 243,
            electric_writerCount: 243,
            in_Storage_Count: 243,
            out_Storage_Count: 243,
            finish_Count: 243
        }
    ]

    $scope.showtable = -1;
    $scope.showTable = function (taskID) {
        if ($scope.showtable != taskID) {
            $scope.showtable = taskID;
        } else {
            $scope.showtable = -1;
        }
    }

    $scope.showTableGroup = function (specialCardList) {
        ngDialog.open({
            template: 'dialogs/specialCardList.html' + urlTimeStamp(),
            width: 800,
            cache: false,
            controller: ['$scope', 'HttpService', '$rootScope', function ($scope, HttpService, $rootScope) {
                $scope.specialCardList = specialCardList;
            }]

        })
    }

    $scope.finishClick = function (taskId, userState) {
        HttpService.updateProductionTask(taskId, userState, function (data) {
            //点击确认成功后  再次查询城市列表
            getCityListData(cardType, $rootScope.loginData.state);
        })
    }

    $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;
    }

}]);