/**
 * Created by wh on 2015/7/20.
 */
define(['../testDrive', 'jquery','prevload'],function(module, $){
    //initCopyRight(); //版权信息位置调整
    function cloneJSON(para){
        var rePara = null;
        var type = Object.prototype.toString.call(para);
        if(type.indexOf("Object") > -1){
            rePara = jQuery.extend(true, {}, para);
        }else if(type.indexOf("Array") > 0){
            rePara = [];
            jQuery.each(para, function(index, obj){
                rePara.push(jQuery.cloneJSON(obj));
            });
        }else{
            rePara = para;
        }
        return rePara;
    }
    var config_sta={
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: ''
        },
        tooltip: {
            //formatter: function() {
            //    //返回实际数据
            //    return '<b>'+ this.point.name +'</b> 出车次数: '+ Highcharts.numberFormat(this.y, 0, ',') ;
            //}
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    //formatter: function() {
                    //    return '<b>'+ this.point.name +'</b> 出车次数: '+ Highcharts.numberFormat(this.y, 0, ',') ;
                    //}
                    format: '<b>{point.name}</b>'
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                ['Chrome',12.8],
                //{
                //    name: 'Chrome',
                //    y: 12.8,
                //    sliced: true,
                //    selected: true
                //},
                ['Safari',    8.5],
                ['Opera',     6.2],
                ['Others',   0.7]
            ]
        }]
    };
    function showChart(id,config)
    {
        $("#container"+id).highcharts(config);
    }


    module.controller("analysisCtrl",function($scope,$resource,$location,$filter,$timeout,$routeParams,testDriveService){

        var pathname = 'testDrive';
        $scope.tdriveId = $routeParams.tdriveId;
        $scope.containerflag = true; //显示全部饼状图

        //车辆
        var apiDrivingTimes = $resource('/'+pathname+'/api/testDrive/:tdriveId/drivingTimes');   //出车次数
        var apiStaMileage = $resource('/'+pathname+'/api/testDrive/:tdriveId/statistics/mileage');  //里程
        var apiStaSpeedMax = $resource('/'+pathname+'/api/testDrive/:tdriveId/statistics/speedmax');  //最大速度
        var apiStaSpeedUpDown = $resource('/'+pathname+'/api/testDrive/:tdriveId/statistics/speedupdown');  //急加减速
        var apiStaOilUsed = $resource('/'+pathname+'/api/testDrive/:tdriveId/statistics/oilused');  //油耗
        var apiStaStartTimes = $resource('/'+pathname+'/api/testDrive/:tdriveId/statistics/starttimes');  //启动次数


        //-------------------------------------------------------------------------------------------------
        //司机
        var apiStaffDrivingTimes = $resource('/'+pathname+'/api/testDrive/:tdriveId/staffDrivingTimes'); //出车次数
        var apiStaffStaMileage = $resource('/'+pathname+'/api/testDrive/:tdriveId/statistics/staffMileage'); //里程
        var apiStaffStaSpeedMax = $resource('/'+pathname+'/api/testDrive/:tdriveId/statistics/staffSpeedmax');//最大速度
        var apiStaffStaSpeedUpDown = $resource('/'+pathname+'/api/testDrive/:tdriveId/statistics/staffSpeedupdown'); //急加减速
        var apiStaffStaOilUsed = $resource('/'+pathname+'/api/testDrive/:tdriveId/statistics/staffOilused');//油耗
        var apiStaffStaStartTimes = $resource('/'+pathname+'/api/testDrive/:tdriveId/statistics/staffStarttimes');//启动次数


        //销售员
        var apiSPDrivingTimes = $resource('/'+pathname+'/api/testDrive/:tdriveId/salespersonDrivingTimes'); //出车次数


        $scope.sta = {};
        $scope.currentPage = 1;//车辆主页默认当前页
        $scope.pageRecord = 5; //分页记录数


        $scope.staFlag ="vehicle";
        $scope.allShow = true;
        $scope.testShow = true;  //区分销售员的试驾次数
        //读取地址栏的数据
        testDriveService.delQueryUrl("_s",function(data){
            $scope.sta.tm_start = data;
        });
        testDriveService.delQueryUrl("_e",function(data){
            $scope.sta.tm_end = data;
        });
        testDriveService.delQueryUrl("_n",function(data){
            $scope.staFlag = data;
        });

        //查询路径
        $scope.changePath = function(index) {
            if(index == 'vehicle'){
                $scope.staFlag = 'vehicle';
                $scope.vehicleStatistics();
            }else if(index == 'staff'){
                $scope.staFlag = 'staff';
                $scope.staffStatistics();
            }else if(index == 'salesperson'){
                $scope.staFlag = 'salesperson';
                $scope.salespersonStatistics();
            }
            var hash = "";
            if(($scope.sta.tm_start && $scope.sta.tm_end) && ($scope.sta.tm_start < $scope.sta.tm_end)){
                hash +="&_s="+$scope.sta.tm_start+"&_e="+$scope.sta.tm_end+"&_n="+$scope.staFlag;
                $location.path($location.path()).search(hash);
            }else if(!$scope.sta.tm_start && !$scope.sta.tm_end){
                $location.path($location.path()).search(hash);
            }else{
                $scope.sta = {};
                //resultOper("error","请输入正确的查询日期！~",1500);
            }
        };

        //出车次数分页
        $scope.changeStaPath = function(currentPage,name,index){
            if(name =='dispatch'){
                $scope.changeDispatchPage(currentPage,index);
            }else if(name =='mileage'){
                $scope.changeMileagePage(currentPage,index);
            }else if(name =='speedMax'){
                $scope.changeSpeedMaxPage(currentPage,index);
            }else if(name =='speedUpDown'){
                $scope.changeSpeedUpDownPage(currentPage,index);
            }else if(name =='oilUsed'){
                $scope.changeOilUsedPage(currentPage,index);
            }else if(name =='startTimes'){
                $scope.changeStartTimesPage(currentPage,index);
            }
        };

        testDriveService.changeDatePicker("date",["datepicker_1","datepicker_2"]);

        //出车次数
        $scope.changeDispatchPage = function(currentPage,index){
            if(!currentPage) $scope.currentPage = 1;
            else $scope.currentPage = currentPage;
            $scope.postData = {tdriveId:$scope.tdriveId};
            if($scope.sta.tm_start && $scope.sta.tm_end){
                $scope.postData.tm_start =$scope.sta.tm_start;
                $scope.postData.tm_end = $scope.sta.tm_end;
            }
            $scope.postData.isChart = false;
            if(index == 'vehicle'){
                $scope.testShow = true;
                $scope.allShow = true;
                apiDrivingTimes.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allDispatchTimes = data.allTestDrivingTimes;
                        $scope.pagingDispatchTimes =[];
                        if($scope.allDispatchTimes.length == 0)
                            //$('#nodataDialog').modal('show');
                            alert("没有分析数据！");
                        else{
                            //$('#dispatchDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allDispatchTimes.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allDispatchTimes,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingDispatchTimes.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }else if(index == 'staff'){
                $scope.testShow = true;
                $scope.allShow = false;
                apiStaffDrivingTimes.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allDispatchTimes = data.allTestDrivingTimes;
                        $scope.pagingDispatchTimes =[];
                        if($scope.allDispatchTimes.length == 0)
                            alert("没有分析数据！");
                            //$('#nodataDialog').modal('show');
                        else{
                            //$('#dispatchDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allDispatchTimes.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allDispatchTimes,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingDispatchTimes.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }else{
                $scope.testShow = false;
                apiSPDrivingTimes.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allDispatchTimes = data.allTestDrivingTimes;
                        $scope.pagingDispatchTimes =[];
                        if($scope.allDispatchTimes.length == 0)
                            alert("没有分析数据！");
                            //$('#nodataDialog').modal('show');
                        else{
                            //$('#dispatchDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allDispatchTimes.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allDispatchTimes,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingDispatchTimes.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }
        };

        //启动次数
        $scope.changeStartTimesPage = function(currentPage,index){
            if(!currentPage) $scope.currentPage = 1;
            else $scope.currentPage = currentPage;
            $scope.postData = {tdriveId:$scope.tdriveId};
            if($scope.sta.tm_start && $scope.sta.tm_end){
                $scope.postData.tm_start =$scope.sta.tm_start;
                $scope.postData.tm_end = $scope.sta.tm_end;
            }
            $scope.postData.isChart = false;
            if(index == 'vehicle'){
                $scope.allShow = true;
                apiStaStartTimes.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.startTimes = data.allStartTimes;
                        $scope.pagingStartTimes =[];
                        if($scope.startTimes.length == 0)
                            alert("没有分析数据！");
                        //$('#nodataDialog').modal('show');
                        else{
                            //$('#startTimesDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.startTimes.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.startTimes,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingStartTimes.push(times);
                                    m++;
                                }
                                i++;
                            });
                            //console.log(JSON.stringify($scope.pagingStartTimes));
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }else{
                $scope.allShow = false;
                apiStaffStaStartTimes.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.startTimes = data.allStartTimes;
                        $scope.pagingStartTimes =[];
                        if($scope.startTimes.length == 0)
                            alert("没有分析数据！");
                        //$('#nodataDialog').modal('show');
                        else{
                            //$('#startTimesDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.startTimes.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.startTimes,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingStartTimes.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }
        };




        //里程
        $scope.changeMileagePage = function(currentPage,index){
            if(!currentPage) $scope.currentPage = 1;
            else $scope.currentPage = currentPage;
            $scope.postData = {tdriveId:$scope.tdriveId};
            if($scope.sta.tm_start && $scope.sta.tm_end){
                $scope.postData.tm_start =$scope.sta.tm_start;
                $scope.postData.tm_end = $scope.sta.tm_end;
            }
            $scope.postData.isChart = false;
            if(index == 'vehicle'){
                $scope.allShow = true;
                apiStaMileage.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allMileage = data.allMileage;
                        $scope.pagingMileage =[];
                        if($scope.allMileage.length == 0)
                            alert("没有分析数据！");
                            //$('#nodataDialog').modal('show');
                        else{
                            //$('#mileageDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allMileage.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allMileage,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingMileage.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }else{
                $scope.allShow = false;
                apiStaffStaMileage.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allMileage = data.allMileage;
                        $scope.pagingMileage =[];
                        if($scope.allMileage.length == 0)
                            alert("没有分析数据！");
                            //$('#nodataDialog').modal('show');
                        else{
                            //$('#mileageDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allMileage.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allMileage,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingMileage.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }
        };


        //急加减速
        $scope.changeSpeedUpDownPage = function(currentPage,index){
            if(!currentPage) $scope.currentPage = 1;
            else $scope.currentPage = currentPage;
            $scope.postData = {tdriveId:$scope.tdriveId};
            if($scope.sta.tm_start && $scope.sta.tm_end){
                $scope.postData.tm_start =$scope.sta.tm_start;
                $scope.postData.tm_end = $scope.sta.tm_end;
            }
            $scope.postData.isChart = false;
            if(index == 'vehicle'){
                $scope.allShow = true;
                apiStaSpeedUpDown.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allSpeedUpDown = data.allSpeedUpDown;
                        $scope.pagingSpeedUpDown =[];
                        if($scope.allSpeedUpDown.length == 0)
                            alert("没有分析数据！");
                        //$('#nodataDialog').modal('show');
                        else{
                            //$('#speedUpDownDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allSpeedUpDown.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allSpeedUpDown,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingSpeedUpDown.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }else{
                $scope.allShow = false;
                apiStaffStaSpeedUpDown.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allSpeedUpDown = data.allSpeedUpDown;
                        $scope.pagingSpeedUpDown =[];
                        if($scope.allSpeedUpDown.length == 0)
                            alert("没有分析数据！");
                        //$('#nodataDialog').modal('show');
                        else{
                            //$('#speedUpDownDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allSpeedUpDown.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allSpeedUpDown,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingSpeedUpDown.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }
        };


        //超速
        $scope.changeSpeedMaxPage = function(currentPage,index){
            if(!currentPage) $scope.currentPage = 1;
            else $scope.currentPage = currentPage;
            $scope.postData = {tdriveId:$scope.tdriveId};
            if($scope.sta.tm_start && $scope.sta.tm_end){
                $scope.postData.tm_start =$scope.sta.tm_start;
                $scope.postData.tm_end = $scope.sta.tm_end;
            }
            $scope.postData.isChart = false;
            if(index == 'vehicle'){
                $scope.allShow = true;
                apiStaSpeedMax.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allSpeedMax = data.allSpeedMax;
                        $scope.pagingSpeedMax =[];
                        if($scope.allSpeedMax.length == 0)
                            alert("没有分析数据！");
                            //$('#nodataDialog').modal('show');
                        else{
                            //$('#speedMaxDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allSpeedMax.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allSpeedMax,function(times){
                                if(i >= start && i< num){

                                    $scope.pagingSpeedMax.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }else{
                $scope.allShow=false;
                apiStaffStaSpeedMax.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allSpeedMax = data.allSpeedMax;
                        $scope.pagingSpeedMax =[];
                        if($scope.allSpeedMax.length == 0)
                            alert("没有分析数据！");
                            //$('#nodataDialog').modal('show');
                        else{
                            //$('#speedMaxDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allSpeedMax.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allSpeedMax,function(times){
                                if(i >= start && i< num){

                                    $scope.pagingSpeedMax.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }
        };


        //油耗
        $scope.changeOilUsedPage = function(currentPage,index){
            if(!currentPage) $scope.currentPage = 1;
            else $scope.currentPage = currentPage;
            $scope.postData = {tdriveId:$scope.tdriveId};
            if($scope.sta.tm_start && $scope.sta.tm_end){
                $scope.postData.tm_start =$scope.sta.tm_start;
                $scope.postData.tm_end = $scope.sta.tm_end;
            }
            $scope.postData.isChart = false;
            if(index == 'vehicle'){
                $scope.allShow = true;
                apiStaOilUsed.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allOilUsed = data.allOilUsed;
                        $scope.pagingOilUsed =[];
                        if($scope.allOilUsed.length == 0)
                            alert("没有分析数据！");
                            //$('#nodataDialog').modal('show');
                        else{
                            //$('#oilUsedDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allOilUsed.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allOilUsed,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingOilUsed.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }else{
                $scope.allShow = false;
                apiStaffStaOilUsed.get($scope.postData,function(data){
                    if(data.status =='ok'){
                        $scope.allOilUsed = data.allOilUsed;
                        $scope.pagingOilUsed =[];
                        if($scope.allOilUsed.length == 0)
                            alert("没有分析数据！");
                            //$('#nodataDialog').modal('show');
                        else{
                            //$('#oilUsedDialog').modal('show');
                            var i = 1;
                            var m = 0;
                            var start = ($scope.currentPage-1) * $scope.pageRecord +1;
                            var num = parseInt(start) + parseInt($scope.pageRecord);
                            PagingInfo($scope.allOilUsed.length);//分页

                            //获取具体分页的数据
                            angular.forEach($scope.allOilUsed,function(times){
                                if(i >= start && i< num){
                                    $scope.pagingOilUsed.push(times);
                                    m++;
                                }
                                i++;
                            });
                            $scope.currentPage = (start - 1) / $scope.pageRecord + 1;
                        }
                    }else{
                        //resultOper("warn","网速不给力,请稍后再试！~",1500);
                    }
                },function(error){
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                })
            }
        };

        //查看全部数据
        $scope.operStatistics = function(operType,index){
            $scope.currentPage = 1;//车辆主页默认当前页
            if(operType =='dispatchDialog' ){
                $scope.changeDispatchPage($scope.currentPage,index);
            }else if(operType =='mileageDialog'){
                $scope.changeMileagePage($scope.currentPage,index);
            }else if(operType =='speedMaxDialog'){
                $scope.changeSpeedMaxPage($scope.currentPage,index);
            }else if(operType =='speedUpDownDialog'){
                $scope.changeSpeedUpDownPage($scope.currentPage,index);
            }else if(operType =='oilUsedDialog'){
                $scope.changeOilUsedPage($scope.currentPage,index);
            }else if(operType =='startDialog') {
                $scope.changeStartTimesPage($scope.currentPage,index);
            }
        };


        //分页数据处理方法
        function PagingInfo(totalCount) {
            $scope.totalCount = totalCount;
            $scope.totalPage = Math.ceil($scope.totalCount / $scope.pageRecord);
            $scope.totalOption = [{}];
            for (var i = 0; i < $scope.totalPage; i++) {
                $scope.totalOption[i] = {size: i + 1};
            }
        }


        //车辆分析
        $scope.vehicleStatistics = function(){
            //获取出车次数
            apiDrivingTimes.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.dispatch = data.statisticsData;
                    if($scope.dispatch.length>0){
                        $scope.disFlag = true;
                        var dispatchTime = [];
                        var i=0;
                        angular.forEach($scope.dispatch,function(data){
                            dispatchTime.push([data.license+"："+data.times+"次",data.times]);
                            i+=data.times;
                        });
                        if(data.total-i !=0) {
                            dispatchTime.push(["其它"+"："+(data.total - i)+"次", data.total - i]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:dispatchTime}]; //最高车速
                        showChart(1,newConfig);
                    }else{
                        $scope.disFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });

            //获取出车次数
            apiStaStartTimes.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.startTimes = data.statisticsData;
                    if($scope.startTimes.length>0){
                        $scope.startFlag = true;
                        var startTimes = [];
                        var i=0;
                        angular.forEach($scope.startTimes,function(data){
                            startTimes.push([data.license+"："+data.startTimes+"次",data.startTimes]);
                            i+=data.startTimes;
                        });
                        if(data.total-i !=0) {
                            startTimes.push(["其它"+"："+(data.total - i)+"次", data.total - i]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:startTimes}]; //最高车速
                        showChart(2,newConfig);
                    }else{
                        $scope.startFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });

            //获取里程
            apiStaMileage.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.mileage = data.statisticsData;
                    if($scope.mileage.length>0){
                        $scope.milFlag = true;
                        var mileage = [];
                        var i=0;
                        angular.forEach($scope.mileage,function(data){
                            mileage.push([data.license+"："+parseFloat(data.totalMileage)+"KM",parseFloat(data.totalMileage)]);
                            i+=parseFloat(data.totalMileage);
                        });
                        var others = parseFloat((data.total-i.toFixed(2)).toFixed(2));
                        if( others != 0){
                            mileage.push(["其它"+"："+others+"KM",others]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:mileage}]; //里程
                        showChart(3,newConfig);
                    }else{
                        $scope.milFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });

            //急加减
            apiStaSpeedUpDown.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.speedUpDown = data.statisticsData;
                    if($scope.speedUpDown.length>0){
                        $scope.UDFlag = true;
                        var speedUpDown = [];
                        var i=0;
                        angular.forEach($scope.speedUpDown,function(data){
                            speedUpDown.push([data.license+"："+data.times+"次",data.times]);
                            i+=data.times;
                        });
                        if(data.total-i !=0){
                            speedUpDown.push(["其它"+"："+(data.total-i)+"次",data.total-i]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:speedUpDown}]; //最高车速
                        showChart(4,newConfig);
                    }
                    else{
                        $scope.UDFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });

            //最高车速分析
            apiStaSpeedMax.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.speedMax = data.statisticsData;
                    if($scope.speedMax.length>0){
                        $scope.SOFlag = true;

                        var speedMax = [];
                        var i=0;
                        angular.forEach($scope.speedMax,function(data){
                            speedMax.push([data.license+"："+data.times+"次",data.times]);
                            i+=data.times;
                        });
                        if(data.total-i !=0){
                            speedMax.push(["其它"+"："+(data.total-i)+"次",data.total-i]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:speedMax}]; //最高车速
                        showChart(5,newConfig);
                    }
                    else{
                        $scope.SOFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });

            //油耗
            apiStaOilUsed.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.oilFlag = true;
                    $scope.oilused = data.statisticsData;
                    if($scope.oilused.length>0){
                        var oilused = [];
                        var i=0;
                        angular.forEach($scope.oilused,function(data){
                            oilused.push([data.license+"："+parseFloat(data.oilUsed)+"L",parseFloat(data.oilUsed)]);
                            i+=parseFloat(data.oilUsed);
                        });
                        var others = parseFloat((data.total-i.toFixed(2)).toFixed(2));
                        if(others !=0){
                            oilused.push(["其它"+"："+others+"L",others]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:oilused}]; //最高车速
                        showChart(6,newConfig);
                    }else{
                        $scope.oilFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });
        };

        //司机分析
        $scope.staffStatistics = function(){
            //获取出车次数
            apiStaffDrivingTimes.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.dispatch = data.statisticsData;
                    if($scope.dispatch.length>0){
                        $scope.disFlag = true;
                        var dispatchTime = [];
                        var i=0;
                        angular.forEach($scope.dispatch,function(data){
                            dispatchTime.push([data.name+"："+data.times+"次",data.times]);
                            i+=data.times;
                        });
                        if(data.total-i !=0) {
                            dispatchTime.push(["其它"+"："+(data.total - i)+"次", data.total - i]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:dispatchTime}]; //最高车速
                        showChart(1,newConfig);
                    }else{
                        $scope.disFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });

            //获取启动次数
            apiStaffStaStartTimes.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.startTimes = data.statisticsData;
                    if($scope.startTimes.length>0){
                        $scope.startFlag = true;
                        var startTimes = [];
                        var i=0;
                        angular.forEach($scope.startTimes,function(data){
                            startTimes.push([data.name+"："+data.startTimes+"次",data.startTimes]);
                            i+=data.startTimes;
                        });
                        if(data.total-i !=0) {
                            startTimes.push(["其它"+"："+(data.total - i)+"次", data.total - i]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:startTimes}]; //最高车速
                        showChart(2,newConfig);
                    }else{
                        $scope.startFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });

            //获取里程
            apiStaffStaMileage.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.mileage = data.statisticsData;
                    if($scope.mileage.length>0){
                        $scope.milFlag = true;
                        var mileage = [];
                        var i=0;
                        angular.forEach($scope.mileage,function(data){
                            mileage.push([data.name+"："+parseFloat(data.totalMileage)+"KM",parseFloat(data.totalMileage)]);
                            i+=parseFloat(data.totalMileage);
                        });
                        var others = parseFloat((data.total-i.toFixed(2)).toFixed(2));
                        if(others != 0){
                            mileage.push(["其它"+"："+others+"KM",others]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:mileage}]; //里程
                        showChart(3,newConfig);
                    }else{
                        $scope.milFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });


            //急加减
            apiStaffStaSpeedUpDown.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.speedUpDown = data.statisticsData;
                    if($scope.speedUpDown.length>0){
                        $scope.UDFlag = true;
                        var speedUpDown = [];
                        var i=0;
                        angular.forEach($scope.speedUpDown,function(data){
                            speedUpDown.push([data.name+"："+data.times+"次",data.times]);
                            i+=data.times;
                        });
                        if(data.total-i !=0){
                            speedUpDown.push(["其它"+"："+(data.total-i)+"次",data.total-i]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:speedUpDown}]; //最高车速
                        showChart(4,newConfig);
                    }
                    else{
                        $scope.UDFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });


            //获取超速
            apiStaffStaSpeedMax.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.speedMax = data.statisticsData;
                    if($scope.speedMax.length>0){
                        $scope.SOFlag = true;

                        var speedMax = [];
                        var i=0;
                        angular.forEach($scope.speedMax,function(data){
                            speedMax.push([data.name+"："+data.times+"次",data.times]);
                            i+=data.times;
                        });
                        if(data.total-i !=0){
                            speedMax.push(["其它"+"："+(data.total-i)+"次",data.total-i]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:speedMax}]; //最高车速
                        showChart(5,newConfig);
                    }
                    else{
                        $scope.SOFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });


            //油耗
            apiStaffStaOilUsed.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.oilFlag = true;
                    $scope.oilused = data.statisticsData;
                    if($scope.oilused.length>0){
                        var oilused = [];
                        var i=0;
                        angular.forEach($scope.oilused,function(data){
                            oilused.push([data.name+"："+parseFloat(data.oilUsed)+"L",parseFloat(data.oilUsed)]);
                            i+=parseFloat(data.oilUsed);
                        });
                        var others = parseFloat((data.total-i.toFixed(2)).toFixed(2));
                        if(others !=0){
                            oilused.push(["其它"+"："+others+"L",others]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:oilused}]; //最高车速
                        showChart(6,newConfig);
                    }else{
                        $scope.oilFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });
        };

        //销售员分析
        $scope.salespersonStatistics = function(){
            //获取出车次数
            apiSPDrivingTimes.get({tdriveId:$scope.tdriveId,tm_start:$scope.sta.tm_start,tm_end:$scope.sta.tm_end,isChart:true},function(data){
                if(data.status == "ok"){
                    $scope.dispatch = data.statisticsData;
                    if($scope.dispatch.length>0){
                        $scope.disFlag = true;
                        var dispatchTime = [];
                        var i=0;
                        angular.forEach($scope.dispatch,function(data){
                            dispatchTime.push([data.name+"："+data.times+"次",data.times]);
                            i+=data.times;
                        });
                        if(data.total-i !=0) {
                            dispatchTime.push(["其它"+"："+(data.total - i)+"次", data.total - i]);
                        }
                        //fleetService.changeBodyH();
                        var newConfig = cloneJSON(config_sta);
                        newConfig.series=[{type: 'pie',name:"占",data:dispatchTime}]; //最高车速
                        showChart(1,newConfig);
                    }else{
                        $scope.disFlag = false;
                    }
                }else{
                    //resultOper("warn","网速不给力,请稍后再试！~",1500);
                }
            },function(error){
                //resultOper("warn","网速不给力,请稍后再试！~",1500);
            });
        };


        if($scope.staFlag == 'staff'){
            $scope.staffStatistics();
        }else if($scope.staFlag == 'vehicle'){
            $scope.vehicleStatistics();
        }else if($scope.staFlag == 'salesperson'){
            $scope.containerflag = false;
            $scope.salespersonStatistics();
        }

        //
        ////发送请求结果显示
        //function resultOper(level,tips,second,flag){
        //    $scope.tipsLevel = level;
        //    $scope.operResult = tips;
        //    $scope.resultShow = true;
        //    $timeout(function(){
        //        $scope.resultShow = false;
        //        if(flag) window.location="/login.html";
        //    },second)
        //}




    });
});