(function (app) {
    app.factory('carService', ['$http', 'config', "util", 'data', function ($http, config, util, data) {
        return {
            //发布车源信息
            addCar: function (model) {
                return $http({
                    url: config.server + 'api/messages',
                    method: "post",
                    data: model
                })
            },
            //车源列表
            listCars: function (model) {
                var condition = util.format("?include=user,truck&type={0}&begin_address={1}&end_address={2}&midway_address={3}&page={4}"
                  , model.type, model.begin_address ? model.begin_address : '', model.end_address ? model.end_address : '', model.midway_address ? model.midway_address : '', model.pageIndex);
                return $http({
                    url: config.server + 'api/messages/search' + condition,
                    method: "get",
                    data: model
                })
            },
            //我的车辆
            listTrucks:function () {
                return $http({
                    url: config.server + 'api/user/trucks',
                    method: "get" 
                })
               }
        };
    }]);
})(angular.module('app.services'));