index.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. $.hideLoading();
  73. if (this.getStatus() == BMAP_STATUS_SUCCESS) {
  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 = 2000;
  85. $.toast('您的城市:'+_this.location.city,'text');
  86. }, 500)
  87. }
  88. else {
  89. $.toast('获取您的位置信息失败', 'text');
  90. }
  91. }, {enableHighAccuracy: true});
  92. },
  93. }
  94. })