baimeng 9 年 前
コミット
1607552cc5

+ 1 - 1
wl/www/index.html

xqd
@@ -40,6 +40,6 @@
 <script src="js/services/goodsservice.js"></script>
 <script src="js/services/orderservice.js"></script>
 <script src="js/services/myservice.js"></script>
-<script src="js/services/nativeservices.js"></script>
+<script src="js/services/mapservice.js"></script>
 <!--filters-->
 <script src="js/filters/filter.js"></script>

+ 9 - 3
wl/www/js/app.js

xqd xqd
@@ -42,8 +42,8 @@
      $httpProvider.interceptors.push('myHttpInterceptor');
      
  }])
-.run(["$ionicPlatform", "$location", "msg", "$rootScope", "$timeout", "$ionicHistory", "userService", "$state", "$http",
-    function ($ionicPlatform, $location, msg, $rootScope, $timeout, $ionicHistory, userService, $state, $http) {
+.run(["$ionicPlatform", "$location", "msg", "$rootScope", "$timeout", "$ionicHistory", "userService", "$state", "$http", "map",
+    function ($ionicPlatform, $location, msg, $rootScope, $timeout, $ionicHistory, userService, $state, $http, map) {
     $ionicPlatform.registerBackButtonAction(function (e) {
         if ($location.path().indexOf("wl/") != -1) {
             if ($rootScope.backButtonPressedOnceToExit) {
@@ -71,9 +71,15 @@
         if (window.StatusBar) {
             StatusBar.styleDefault();
         }
+   
+        if (!$rootScope.location) {
+            map.getLocation().then(function (result) {
+                $rootScope.location = result;
+            });
+        }
         if (!userService.isLogin()) {
             $state.go('login');
-        } 
+        }
     });
 }]);
  angular.module("app.controllers", []);

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

xqd xqd xqd
@@ -1,5 +1,5 @@
 (function (app) {
-    app.controller('carCtrl', ["$scope", "$ionicSideMenuDelegate", "$state", 'carService', 'msg', function ($scope, $ionicSideMenuDelegate, $state, carService, msg) {
+    app.controller('carCtrl', ["$scope", "$ionicSideMenuDelegate", "$state", 'carService', 'msg', '$rootScope', function ($scope, $ionicSideMenuDelegate, $state, carService, msg, $rootScope) {
         $scope.filter = {
             hasMore: false,
             pageIndex: 0,
@@ -12,11 +12,14 @@
         $scope.items = [];
         $scope.load = function (init) {
             if (init) {
+             
                 $scope.filter.pageIndex = 1;
                 $scope.items = [];
+                if ($rootScope.location) {
+                    $scope.filter.begin_address = $rootScope.location.city;
+                }
             }
             carService.listCars($scope.filter).then(function (result) {
-             
                 $scope.filter.pageIndex++;
                 var more = (result.data.data.length >= $scope.filter.pageSize);
                 $scope.filter.hasMore = more;
@@ -114,10 +117,10 @@
             });
         }
     }]);
-    app.controller('carDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', 'userService',
-        function ($scope, $stateParams, msg, orderService, $state, userService) {
+    app.controller('carDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', 'map',
+        function ($scope, $stateParams, msg, orderService, $state, map) {
         $scope.vm = $stateParams.item;
-        userService.getMapPic($scope.vm.begin_address).then(function (result) {
+        map.getMapPic($scope.vm.begin_address).then(function (result) {
             $scope.vm.picUrl = result;
         });
         //下单

+ 12 - 64
wl/www/js/controllers/goods.js

xqd xqd xqd xqd
@@ -1,6 +1,6 @@
 (function (app) {
-    app.controller('goodsCtrl', ["$scope", "$state", 'goodsService', '$ionicSideMenuDelegate', 'msg', function ($scope, $state, goodsService, $ionicSideMenuDelegate, msg) {
-
+    app.controller('goodsCtrl', ["$scope", "$state", 'goodsService', '$ionicSideMenuDelegate', 'msg'
+        ,function ($scope, $state, goodsService, $ionicSideMenuDelegate, msg) {
         $scope.filter = {
             hasMore: false,
             pageIndex: 0,
@@ -15,7 +15,11 @@
             if (init) {
                 $scope.filter.pageIndex = 1;
                 $scope.items = [];
+                if ($rootScope.location) {
+                    $scope.filter.begin_address = $rootScope.location.city;
+                }
             }
+          
             goodsService.listGoods($scope.filter).then(function (result) {
                  
                 $scope.filter.pageIndex++;
@@ -46,66 +50,10 @@
         }
         $scope.load(true); 
         $scope.getLocation = function () {
-            //http://lbs.amap.com/api/javascript-api/reference/plugin/#m_AMap.Geolocation
-            debugger;
-           //var mapObj = new AMap.Map('iCenter');
-           // mapObj.plugin('AMap.Geolocation', function () {
-           //     geolocation = new AMap.Geolocation({
-           //         enableHighAccuracy: true,//是否使用高精度定位,默认:true
-           //         timeout: 10000,          //超过10秒后停止定位,默认:无穷大
-           //         maximumAge: 0,           //定位结果缓存0毫秒,默认:0
-           //         convert: true,           //自动偏移坐标,偏移后的坐标为高德坐标,默认:true
-           //         showButton: true,        //显示定位按钮,默认:true
-           //         buttonPosition: 'LB',    //定位按钮停靠位置,默认:'LB',左下角
-           //         buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
-           //         showMarker: true,        //定位成功后在定位到的位置显示点标记,默认:true
-           //         showCircle: true,        //定位成功后用圆圈表示定位精度范围,默认:true
-           //         panToLocation: true,     //定位成功后将定位到的位置作为地图中心点,默认:true
-           //         zoomToAccuracy: true      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
-           //     });
-           //     mapObj.addControl(geolocation);
-           //     AMap.event.addListener(geolocation, 'complete', function (result) {
-           //         alert('sucess:' + JSON.stringify(result));
-           //     });//返回定位信息
-           //     AMap.event.addListener(geolocation, 'error', function (error) {
-           //         alert('error:' + JSON.stringify(error));
-           //     });      //返回定位出错信息
-            // });
-            var map, geolocation;
-            //加载地图,调用浏览器定位服务
-            map = new AMap.Map('container', {
-                resizeEnable: true
-            });
-           
-            map.plugin('AMap.Geolocation', function () {
-                geolocation = new AMap.Geolocation({
-                    enableHighAccuracy: true,//是否使用高精度定位,默认:true
-                    timeout: 10000,          //超过10秒后停止定位,默认:无穷大
-                    buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
-                    zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
-                    buttonPosition: 'RB'
-                });
-                map.addControl(geolocation);
-                geolocation.getCurrentPosition();
-                AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
-                AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
-            });
-        }
-        //解析定位结果
-        function onComplete(data) {
-           
-            var str = ['定位成功'];
-            str.push('经度:' + data.position.getLng());
-            str.push('纬度:' + data.position.getLat());
-            str.push('精度:' + data.accuracy + ' 米');
-            str.push('是否经过偏移:' + (data.isConverted ? '是' : '否'));
-         
-        }
-        //解析定位错误信息
-        function onError(data) {
-        
+          
         }
-       $scope.getLocation();
+    
+       
     }]);
     app.controller('goodsAddCtrl', ["$scope", "$state", "goodsService", "msg", function ($scope, $state, goodsService, msg) {
 
@@ -160,10 +108,10 @@
             });
         }
     }]);
-    app.controller('goodsDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', 'userService'
-        , function ($scope, $stateParams, msg, orderService, $state, userService) {
+    app.controller('goodsDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', 'map'
+        , function ($scope, $stateParams, msg, orderService, $state, map) {
         $scope.vm = $stateParams.item;
-        userService.getMapPic($scope.vm.begin_address).then(function (result) {
+        map.getMapPic($scope.vm.begin_address).then(function (result) {
             $scope.vm.picUrl = result;
         });
         //下单

+ 9 - 8
wl/www/js/controllers/my.js

xqd
@@ -320,14 +320,15 @@
         }
         $scope.pay = function (item,$event) {
             $event.stopPropagation();
-            var price = item.message.data.price;
-            window.alipay.pay({
-                tradeNo: new Date().getTime(),
-                subject: "测试标题",
-                body: "我是测试内容",
-                price: price,
-                notifyUrl: "http://your.server.notify.url"
-            }, function (successResults) { alert(successResults) }, function (errorResults) { alert(errorResults) });
+            msg.text('支付尚未开通,敬请期待');
+            //var price = item.message.data.price;
+            //window.alipay.pay({
+            //    tradeNo: new Date().getTime(),
+            //    subject: "测试标题",
+            //    body: "我是测试内容",
+            //    price: price,
+            //    notifyUrl: "http://your.server.notify.url"
+            //}, function (successResults) { alert(successResults) }, function (errorResults) { alert(errorResults) });
             //to do 
         }
         $scope.delete = function (item,$event) {

+ 73 - 0
wl/www/js/services/mapservice.js

xqd
@@ -0,0 +1,73 @@
+(function (app) {
+    app.factory("map", ["$q", "$http", function ($q, $http) {
+        var key = '9f832e163baac0a04d437a52dd3e5d29';
+        return {
+            //获取高德地图图片
+            getMapPic: function (input) {
+                var deferred = $q.defer();
+                var defaultPath = "img/demo/defaultmap.png";
+                if (!input) return defaultPath;
+                var arr = input.split(',');
+               
+                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;
+            },
+            //通过ip获取地址
+            getLocation: function () {
+                
+                //http://restapi.amap.com/v3/ip?key=9f832e163baac0a04d437a52dd3e5d29
+                var deferred = $q.defer();
+                var url = "http://restapi.amap.com/v3/ip?key=" + key + "&callback=JSON_CALLBACK";
+                $http.jsonp(url).then(function (result) {
+                    deferred.resolve(result.data);
+                }, function (erro) {
+                    deferred.reject(erro);
+                });
+                ////http://lbs.amap.com/api/javascript-api/reference/plugin/#m_AMap.Geolocation
+                //var map, geolocation;
+                ////加载地图,调用浏览器定位服务
+                //map = new AMap.Map('container', {
+                //    resizeEnable: true
+                //});
+                //map.plugin('AMap.Geolocation', function () {
+                //    geolocation = new AMap.Geolocation({
+                //        enableHighAccuracy: true,//是否使用高精度定位,默认:true
+                //       // timeout: 10000,          //超过10秒后停止定位,默认:无穷大
+                //        buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
+                //        zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
+                //        buttonPosition: 'RB'
+                //    });
+                //    map.addControl(geolocation);
+                //    geolocation.getCurrentPosition();
+                //    AMap.event.addListener(geolocation, 'complete', function (data) {
+                //        debugger;
+                //        //返回定位信息
+                //        var str = ['定位成功'];
+                //        str.push('经度:' + data.position.getLng());
+                //        str.push('纬度:' + data.position.getLat());
+                //        str.push('精度:' + data.accuracy + ' 米');
+                //        str.push('是否经过偏移:' + (data.isConverted ? '是' : '否'));
+                //        deferred.resolve(str);
+                //    });
+                //    AMap.event.addListener(geolocation, 'error', function (erro) {  //返回定位出错信息
+                //        deferred.reject(erro);
+                //    });
+                //});
+                return deferred.promise;
+            }
+        }
+    }]);
+})(angular.module('app.services'));

+ 0 - 66
wl/www/js/services/nativeservices.js

xqd
@@ -1,66 +0,0 @@
-(function (app) {
-     
-    app.factory("camera", ["$window",'msg', function ($window,msg) {
-        return {
-            chooseImage: function (cameraOptions) {
-                var q = $q.defer();
-                if (ionic.Platform.platforms[0] === "browser") {
-                    msg.text('不支持该操作');
-                }
-                var defaultOptions = {
-                    quality: 100,
-                    destinationType: 1,//0:Return base64 encoded string,1:Return file uri (content://media/external/images/media/2 for Android),2:Return native uri (eg. asset-library://... for iOS)
-                    sourceType: 1,//0:Choose image from picture library (same as SAVEDPHOTOALBUM for Android),1:Take picture from camera,2:Choose image from picture library (same as PHOTOLIBRARY for Android)
-                    allowEdit: false,
-                    encodingType: 0,//0为jpg,1为png
-                    //targetWidth: 1920,
-                    //targetHeight: 1080,
-                    saveToPhotoAlbum: false,
-                    maximumImagesCount: 10  //选择图片时用的
-                };
-                var options = angular.extend(defaultCameraOptions, cameraOptions);
-                var sheetOptions = {
-                    title: '选择拍照方式',
-                    buttonLabels: ['拍摄照片', '从图库选择'],
-                    addCancelButtonWithLabel: '取消',
-                    androidEnableCancelButton: true
-                };
-                $cordovaActionSheet.show(sheetOptions)
-                    .then(function (index) {
-
-                        switch (index) {
-
-                            case 1: //拍摄图片
-                                {
-                                    options.sourceType = 1;
-                                    navigator.camera.getPicture(options).then(function (imageURI) {
-
-                                        q.resolve([imageURI]);
-
-                                    }, function (error) {
-
-                                        q.reject(error);
-                                    });
-                                }
-                                break;
-
-                            case 2:
-                                {
-                                    window.plugins.imagePicker.getPictures(function (results) {
-                                        q.resolve(results);
-                                    }, function (error) {
-                                        q.reject(error);
-                                    }, options);
-                                }
-                                break;
-                            default:
-
-                                q.reslove([]);
-                                break;
-                        }
-                    });
-                return q.promise;
-            } 
-        };
-    }]);
-})(angular.module('app.services'));

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

xqd
@@ -47,30 +47,7 @@
                 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;
-            }
+            } 
         };
     }]);
 })(angular.module('app.services'));

+ 0 - 1
wl/www/templates/goods/index.html

xqd
@@ -8,7 +8,6 @@
                 <!--下拉刷新-->
                 <ion-refresher pulling-text="下拉刷新" on-refresh="load(true)">
                 </ion-refresher>
-                <div id='container'></div>
                 <div class="row app-link headbck">
                     <div class="col-33">
                         <a ng-click="add()">