index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. var app = new Vue({
  2. 'el': '#app',
  3. 'data': {
  4. // 当前导航
  5. curNav: 'index',
  6. // 定位信息
  7. location: {
  8. city: '位置',
  9. address: '',
  10. info: {},
  11. lng: '',
  12. lat: ''
  13. },
  14. // 幻灯片列表
  15. advertList: [],
  16. id: 0,
  17. },
  18. created: function(){
  19. this.getAdvertList();
  20. },
  21. updated: function(){
  22. // 顶部轮播图
  23. var mySwiper = new Swiper ('.swiper-container', {
  24. // 如果需要分页器
  25. autoplay:true,
  26. pagination: {
  27. el: '.swiper-pagination'
  28. }
  29. });
  30. },
  31. mounted: function(){
  32. this.loadLocation();
  33. },
  34. methods: {
  35. // 搜索
  36. search: function(){
  37. var kw = $.trim($("#search").find('.keyword').val());
  38. location.href = '/weixin/shop/search?kw='+kw;
  39. },
  40. // 获取幻灯片,列表
  41. getAdvertList: function(){
  42. var _this = this;
  43. $.post('/weixin/index/getAdvertList', {}, function (res) {
  44. if (res.code == 'success') {
  45. _this.advertList = res.data
  46. }else if(res.code == 'login'){
  47. login(res.data.url);
  48. }
  49. }, "json");
  50. },
  51. // 初始化定位
  52. initPoint: function(){
  53. var lng = sessionStorage.getItem('point_lng');
  54. var lat = sessionStorage.getItem('point_lat');
  55. var city = sessionStorage.getItem('city');
  56. if(lng){
  57. this.params.lng = lng;
  58. }
  59. if(lat){
  60. this.params.lat = lat;
  61. }
  62. if(city){
  63. this.location.city = city;
  64. }
  65. },
  66. // 定位
  67. /*loadLocation: function () {
  68. var _this = this;
  69. var geolocation = new BMap.Geolocation();
  70. //$.showLoading('获取定位中...')
  71. geolocation.getCurrentPosition(function (r) {
  72. if (this.getStatus() == BMAP_STATUS_SUCCESS) {
  73. console.log(r)
  74. _this.location.lat = r.point.lat;
  75. _this.location.lat = r.point.lat;
  76. _this.location.info = r.address;
  77. _this.location.city = r.address.city;
  78. _this.location.address = r.address.province+' '+r.address.city +' '+r.address.district;
  79. sessionStorage.setItem('point_lng', r.point.lng)
  80. sessionStorage.setItem('point_lat', r.point.lat)
  81. sessionStorage.setItem('city', r.address.city)
  82. sessionStorage.setItem('address', _this.location.address)
  83. setTimeout(function(){
  84. $.toast.prototype.defaults.duration = 1000;
  85. $.toast('您的城市:'+_this.location.city,'text');
  86. }, 500)
  87. }
  88. else {
  89. $.toast('获取您的位置信息失败', 'text');
  90. }
  91. }, {enableHighAccuracy: true});
  92. },*/
  93. // 微信地图定位
  94. loadLocation: function () {
  95. var _this = this;
  96. $.post('/weixin/index/getJssdkParams', {url: location.href}, function (res) {
  97. var params = res.data;
  98. // 微信JSSDK
  99. wx.config({
  100. debug: false, // 是否调试模式
  101. appId: params.appId, // 必填,公众号的唯一标识
  102. timestamp: params.timestamp, // 必填,生成签名的时间戳
  103. nonceStr: params.nonceStr, // 必填,生成签名的随机串
  104. signature: params.signature,// 必填,签名
  105. jsApiList: ['getLocation'] // 必填,需要使用的JS接口列表
  106. });
  107. // 初始化处理
  108. wx.ready(function () {
  109. wx.getLocation({
  110. type: 'BD09', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  111. // type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  112. success: function (res) {
  113. var geocoder = new qq.maps.Geocoder({
  114. complete: function (result) {
  115. var detail = result.detail;
  116. var address = detail.addressComponents;
  117. if(address.city){
  118. _this.location = address;
  119. $.toast.prototype.defaults.duration = 1000;
  120. $.toast('您的位置:'+address.city,'text');
  121. }
  122. }
  123. });
  124. var coord=new qq.maps.LatLng(res.latitude, res.longitude);
  125. geocoder.getAddress(coord);
  126. }
  127. });
  128. });
  129. }, "json");
  130. },
  131. }
  132. })