| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- var app = new Vue({
- 'el': '#app',
- 'data': {
- // 列表数据
- dataList: [],
- // 参数
- params: {
- page: 1,
- pageSize: 15,
- keyword: '',
- lng: 108.325449,
- lat: 22.823939,
- type: 1,
- },
- loading: false,
- loaded: false,
- },
- created: function(){
- this.params.keyword = getParam('kw');
- //this.loadLocation();
- this.getDataList(0);
- },
- mounted: function(){
- var _this = this;
- $(".weui-navbar__item").click(function(){
- _this.params.page = 1;
- _this.loaded = false;
- _this.params.type = $(this).index()+1;
- $(this).addClass('on').siblings().removeClass('on');
- _this.dataList = [];
- _this.getDataList(0);
- });
- $(window).scroll(function(){
- var scrollHeight = $(this).scrollTop();
- var height = $('body')[0].scrollHeight;
- var docHeight = $(this).outerHeight();
- if(docHeight+scrollHeight >= height){
- if(_this.loading || _this.loaded){
- return false;
- }
- _this.params.page++;
- _this.getDataList(1);
- }
- })
- },
- methods: {
- // 详情
- goDetail: function(id){
- if(id){
- if(this.params.type == 2){
- location.href = '/weixin/shop/detail?id='+id;
- }else{
- location.href = '/weixin/goods/detail?id='+id;
- }
- }
- },
- // 初始化定位
- initPoint: function(){
- var lng = sessionStorage.getItem('point_lng');
- var lat = sessionStorage.getItem('point_lat');
- if(lng){
- this.params.lng = lng;
- }
- if(lat){
- this.params.lat = lat;
- }
- },
- // 定位
- loadLocation: function () {
- var _this = this;
- var geolocation = new BMap.Geolocation();
- $.showLoading('获取定位中...')
- geolocation.getCurrentPosition(function (r) {
- $.hideLoading();
- if (this.getStatus() == BMAP_STATUS_SUCCESS) {
- _this.params.lng = r.point.lng;
- _this.params.lat = r.point.lat;
- var 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', address)
- }
- else {
- $.toast('获取您的位置信息失败', 'text');
- }
- }, {enableHighAccuracy: true});
- },
- // 获取列表数据
- getDataList: function(more){
- var _this = this;
- if(_this.params.page == 1){
- _this.dataList = [];
- }
- $.showLoading("数据加载中...");
- _this.loading = true;
- $.post('/weixin/shop/doSearch', _this.params, function (res) {
- $.hideLoading();
- _this.loading = false;
- if (res.code == 'success') {
- if(res.data.data.length<=0 && _this.params.page > 1){
- _this.loaded = true;
- $.toast("已加载完全部...",'text');
- return false;
- }
- if(more){
- $.each(res.data.data, function(k,item){
- _this.dataList.push(item);
- });
- }else{
- _this.dataList = res.data.data
- }
- }else if(res.code == 'login'){
- login(res.data.url);
- }
- }, "json");
- },
- }
- })
|