| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- var app = new Vue({
- 'el': '#app',
- 'data': {
- // 当前导航
- curNav: 'index',
- // 定位信息
- location: {
- city: '位置',
- address: '',
- info: {},
- lng: '',
- lat: ''
- },
- // 幻灯片列表
- advertList: [],
- id: 0,
- },
- created: function(){
- this.getAdvertList();
- },
- updated: function(){
- // 顶部轮播图
- var mySwiper = new Swiper ('.swiper-container', {
- // 如果需要分页器
- autoplay:true,
- pagination: {
- el: '.swiper-pagination'
- }
- });
- },
- mounted: function(){
- this.loadLocation();
- },
- methods: {
- // 搜索
- search: function(){
- var kw = $.trim($("#search").find('.keyword').val());
- location.href = '/weixin/shop/search?kw='+kw;
- },
- // 获取幻灯片,列表
- getAdvertList: function(){
- var _this = this;
- $.post('/weixin/index/getAdvertList', {}, function (res) {
- if (res.code == 'success') {
- _this.advertList = res.data
- }else if(res.code == 'login'){
- login(res.data.url);
- }
- }, "json");
- },
- // 初始化定位
- initPoint: function(){
- var lng = sessionStorage.getItem('point_lng');
- var lat = sessionStorage.getItem('point_lat');
- var city = sessionStorage.getItem('city');
- if(lng){
- this.params.lng = lng;
- }
- if(lat){
- this.params.lat = lat;
- }
- if(city){
- this.location.city = city;
- }
- },
- // 定位
- /*loadLocation: function () {
- var _this = this;
- var geolocation = new BMap.Geolocation();
- //$.showLoading('获取定位中...')
- geolocation.getCurrentPosition(function (r) {
- if (this.getStatus() == BMAP_STATUS_SUCCESS) {
- console.log(r)
- _this.location.lat = r.point.lat;
- _this.location.lat = r.point.lat;
- _this.location.info = r.address;
- _this.location.city = r.address.city;
- _this.location.address = r.address.province+' '+r.address.city +' '+r.address.district;
- sessionStorage.setItem('point_lng', r.point.lng)
- sessionStorage.setItem('point_lat', r.point.lat)
- sessionStorage.setItem('city', r.address.city)
- sessionStorage.setItem('address', _this.location.address)
- setTimeout(function(){
- $.toast.prototype.defaults.duration = 1000;
- $.toast('您的城市:'+_this.location.city,'text');
- }, 500)
- }
- else {
- $.toast('获取您的位置信息失败', 'text');
- }
- }, {enableHighAccuracy: true});
- },*/
- // 微信地图定位
- loadLocation: function () {
- var _this = this;
- $.post('/weixin/index/getJssdkParams', {url: location.href}, function (res) {
- var params = res.data;
- // 微信JSSDK
- wx.config({
- debug: false, // 是否调试模式
- appId: params.appId, // 必填,公众号的唯一标识
- timestamp: params.timestamp, // 必填,生成签名的时间戳
- nonceStr: params.nonceStr, // 必填,生成签名的随机串
- signature: params.signature,// 必填,签名
- jsApiList: ['getLocation'] // 必填,需要使用的JS接口列表
- });
- // 初始化处理
- wx.ready(function () {
- wx.getLocation({
- type: 'BD09', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
- // type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
- success: function (res) {
- var geocoder = new qq.maps.Geocoder({
- complete: function (result) {
- var detail = result.detail;
- var address = detail.addressComponents;
- if(address.city){
- _this.location = address;
- $.toast.prototype.defaults.duration = 1000;
- $.toast('您的位置:'+address.city,'text');
- }
- }
- });
- var coord=new qq.maps.LatLng(res.latitude, res.longitude);
- geocoder.getAddress(coord);
- }
- });
- });
- }, "json");
- },
- }
- })
|