Ben 9 年 前
コミット
bb13e3670d

+ 5 - 1
wl/www/js/controllers/car.js

xqd
@@ -114,8 +114,12 @@
             });
         }
     }]);
-    app.controller('carDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', function ($scope, $stateParams, msg, orderService, $state) {
+    app.controller('carDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', 'userService',
+        function ($scope, $stateParams, msg, orderService, $state, userService) {
         $scope.vm = $stateParams.item;
+        userService.getMapPic($scope.vm.begin_address).then(function (result) {
+            $scope.vm.picUrl = result;
+        });
         //下单
         $scope.bill = function () {
             msg.confirm('下单提示', '确定下单?').then(function (res) {

+ 5 - 2
wl/www/js/controllers/goods.js

xqd
@@ -98,9 +98,12 @@
             });
         }
     }]);
-    app.controller('goodsDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', function ($scope, $stateParams, msg, orderService, $state) {
+    app.controller('goodsDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', 'userService'
+        , function ($scope, $stateParams, msg, orderService, $state, userService) {
         $scope.vm = $stateParams.item;
-        
+        userService.getMapPic($scope.vm.begin_address).then(function (result) {
+            $scope.vm.picUrl = result;
+        });
         //下单
         $scope.bill = function () {
             msg.confirm('下单提示', '确定下单?').then(function (res) {

+ 0 - 37
wl/www/js/filters/filter.js

xqd
@@ -52,41 +52,4 @@
             return input.replace(',','--');
         };
     });
-    module.filter('mapPic', ["$http", function ($http) {
-        return function (input) {
-
-            if (!input) return "img/demo/defaultmap.png";
-            var arr = input.split(',');
-            var key = '9f832e163baac0a04d437a52dd3e5d29';
-            var keywords = arr[arr.length - 1];
-            
-            var url = 'http://restapi.amap.com/v3/place/text?key=' + key + '&keywords=' + keywords + "&callback=JSON_CALLBACK";
-           
-           // http://restapi.amap.com/v3/staticmap?location=116.481485,39.990464&zoom=10&size=750*300&markers=mid,,A:116.481485,39.990464&key=9f832e163baac0a04d437a52dd3e5d29
-            //$http({
-            //    url: 'http://restapi.amap.com/v3/place/text?key=' + key + '&keywords=' + keywords,
-            //    method: "get",
-            //    withCredentials: true,
-            //    headers: {
-            //        common: { Authorization: undefined },
-            //        'Content-Type': 'application/json; charset=utf-8'
-            //    }
-            //}).then(function (result) {
-            //    debugger;
-            //});
-            var map = '';
-            $http.jsonp(url).success(function (result) {
-                var p = result.pois[0];
-                if (p) {
-                    var l = result.pois[0].location;
-                    map = "http://restapi.amap.com/v3/staticmap?location=" + l + "&zoom=9&size=360*160&markers=mid,,A:" + l + "&key=" + key;
-                    debugger;
-                } else {
-                    map="img/demo/defaultmap.png";
-                }
-           });
-            debugger;
-            return map;
-        };
-    }]);
 })(angular.module('app.filters'));

+ 24 - 1
wl/www/js/services/userservice.js

xqd xqd
@@ -1,5 +1,5 @@
 (function (app) {
-    app.factory('userService', ['$http', 'config', "util",'data', function ($http, config, util,data) {
+    app.factory('userService', ['$http', 'config', "util", 'data', '$q', function ($http, config, util, data, $q) {
         return {
             login:function (username,password) {
                 return $http({
@@ -47,6 +47,29 @@
                 return new Promise(function (resolve, reject) {
                     resolve('ok');
                 });
+            },
+            //获取高德地图图片
+            getMapPic: function (input) {
+                var deferred = $q.defer();
+                var defaultPath = "img/demo/defaultmap.png";
+                if (!input) return defaultPath;
+                var arr = input.split(',');
+                var key = '9f832e163baac0a04d437a52dd3e5d29';
+                var keywords = arr[arr.length - 1];
+                var url = 'http://restapi.amap.com/v3/place/text?key=' + key + '&keywords=' + keywords + "&callback=JSON_CALLBACK";
+                $http.jsonp(url).then(function (result) {
+                    var p = result.data.pois[0];
+                    if (p) {
+                        var l = p.location;
+                        var m="http://restapi.amap.com/v3/staticmap?location=" + l + "&zoom=9&size=360*160&markers=mid,,A:" + l + "&key=" + key;
+                        deferred.resolve(m);
+                    } else {
+                        deferred.resolve(defaultPath);
+                    }
+                }, function (erro) {
+                    deferred.reject(erro);
+                });
+                return deferred.promise;
             }
         };
     }]);

+ 1 - 0
wl/www/templates/car/detail.html

xqd
@@ -1,6 +1,7 @@
 <ion-view view-title="车源信息">
     <ion-content>
         <div class="list">
+            <img ng-src="{{vm.picUrl}}" style="width:100%;" />
             <div class="list card">
                 <div class="item item-avatar">
                     <img ng-src="{{user.data.avatar | avator}}"/>

+ 1 - 1
wl/www/templates/goods/detail.html

xqd
@@ -1,7 +1,7 @@
 <ion-view view-title="货源信息">
     <ion-content>
         <div class="list">
-            <img  ng-src="{{vm.begin_address | mapPic}}"/>
+            <img  ng-src="{{vm.picUrl}}" style="width:100%;"/>
             <div class="list card">
                 <div class="item item-avatar">
                     <img ng-src="{{user.data.avatar | avator}}" />