shop-search.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. var app = new Vue({
  2. 'el': '#app',
  3. 'data': {
  4. // 列表数据
  5. dataList: [],
  6. // 参数
  7. params: {
  8. page: 1,
  9. pageSize: 15,
  10. keyword: '',
  11. lng: 108.325449,
  12. lat: 22.823939,
  13. type: 1,
  14. },
  15. loading: false,
  16. loaded: false,
  17. },
  18. created: function(){
  19. this.params.keyword = getParam('kw');
  20. //this.loadLocation();
  21. this.getDataList(0);
  22. },
  23. mounted: function(){
  24. var _this = this;
  25. $(".weui-navbar__item").click(function(){
  26. _this.params.page = 1;
  27. _this.loaded = false;
  28. _this.params.type = $(this).index()+1;
  29. $(this).addClass('on').siblings().removeClass('on');
  30. _this.dataList = [];
  31. _this.getDataList(0);
  32. });
  33. $(window).scroll(function(){
  34. var scrollHeight = $(this).scrollTop();
  35. var height = $('body')[0].scrollHeight;
  36. var docHeight = $(this).outerHeight();
  37. if(docHeight+scrollHeight >= height){
  38. if(_this.loading || _this.loaded){
  39. return false;
  40. }
  41. _this.params.page++;
  42. _this.getDataList(1);
  43. }
  44. })
  45. },
  46. methods: {
  47. // 详情
  48. goDetail: function(id){
  49. if(id){
  50. if(this.params.type == 2){
  51. location.href = '/weixin/shop/detail?id='+id;
  52. }else{
  53. location.href = '/weixin/goods/detail?id='+id;
  54. }
  55. }
  56. },
  57. // 初始化定位
  58. initPoint: function(){
  59. var lng = sessionStorage.getItem('point_lng');
  60. var lat = sessionStorage.getItem('point_lat');
  61. if(lng){
  62. this.params.lng = lng;
  63. }
  64. if(lat){
  65. this.params.lat = lat;
  66. }
  67. },
  68. // 定位
  69. loadLocation: function () {
  70. var _this = this;
  71. var geolocation = new BMap.Geolocation();
  72. $.showLoading('获取定位中...')
  73. geolocation.getCurrentPosition(function (r) {
  74. $.hideLoading();
  75. if (this.getStatus() == BMAP_STATUS_SUCCESS) {
  76. _this.params.lng = r.point.lng;
  77. _this.params.lat = r.point.lat;
  78. var 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', address)
  83. }
  84. else {
  85. $.toast('获取您的位置信息失败', 'text');
  86. }
  87. }, {enableHighAccuracy: true});
  88. },
  89. // 获取列表数据
  90. getDataList: function(more){
  91. var _this = this;
  92. if(_this.params.page == 1){
  93. _this.dataList = [];
  94. }
  95. $.showLoading("数据加载中...");
  96. _this.loading = true;
  97. $.post('/weixin/shop/doSearch', _this.params, function (res) {
  98. $.hideLoading();
  99. _this.loading = false;
  100. if (res.code == 'success') {
  101. if(res.data.data.length<=0 && _this.params.page > 1){
  102. _this.loaded = true;
  103. $.toast("已加载完全部...",'text');
  104. return false;
  105. }
  106. if(more){
  107. $.each(res.data.data, function(k,item){
  108. _this.dataList.push(item);
  109. });
  110. }else{
  111. _this.dataList = res.data.data
  112. }
  113. }else if(res.code == 'login'){
  114. login(res.data.url);
  115. }
  116. }, "json");
  117. },
  118. }
  119. })