/**
 * Created by liz on 2015/7/24.
 */
requirejs.config({
    paths:{
        angular:"/js/angular.min",
        jquery:'http://cdn.bootcss.com/jquery/1.11.2/jquery.min',
        angularResource: "/js/angular-resource.min",
        angularSanitize:"/js/angular-sanitize.min",
        angularRoute:"/js/angular-route.min"
    },
    shim:{
        jquery: { exports: '$' },
        angular: { exports: 'angular',deps:['jquery']},
        angularResource: ['angular'],
        angularSanitize:['angular'],
        angularRoute:['angular']
    }
});
requirejs(['../testDrive','jquery','../directive/icBaiduMapTrack'], function(module, $){
    module.controller('printCtrl',function($scope,$resource,$location){
        var pathname = 'testDrive';
            var apiReport = $resource('/'+pathname+'/api/testDrive/:tdriveId/report/:reportId');  //获取所有报告 get
            var apiTrack = $resource('/'+pathname+'/api/testDrive/:tdriveId/report/:reportId/track');
            var apiTestDrive = $resource('/'+pathname+'/api/testDrive/:tdriveId');

            var urls = $location.absUrl().split("?")[1].split("&");
            var rid = urls[0].split("=")[1];
            var sid = urls[1].split("=")[1];
            $scope.postData ={
                tdriveId:sid,
                reportId:rid
            };
            apiReport.get($scope.postData,function(data){
                 $scope.report = data;
                if($scope.report.oilUsed == null){
                    $scope.report.oilUsed = 0;
                }else{
                    $scope.report.oilUsed = $scope.report.oilUsed.toFixed(3);
                }
                 $scope.report.tm_start = $scope.report.tm_start.substr(0,16);
                 $scope.report.tm_end = $scope.report.tm_end.substr(0,16);
            },function(err){
               console.log(err);
            });

            apiTrack.get($scope.postData,function(data){
                var data_path = [];
                var fact ={};
                fact.points = [];
                console.log(data.tracks);
                angular.forEach(data.tracks,function(path){
                    fact.points.push(path);
                });
                data_path.push(fact);
                console.log(fact);
                $scope.data_path = data_path;
                $scope.data_path.flag =  true;
                $scope.data_path.speedColor = true; //true:显示轨迹速度颜色，false：默认为一条蓝色的线
            },function(err){
                console.log(err);
            })

            //获取试乘试驾店相关信息
            apiTestDrive.get({tdriveId:sid},function(data){
                $scope.testDriveInfo = data;
            })
    });
        angular.bootstrap(document, ['testDrive']);
  });

