const navigationBarHeight = (getApp().statusBarHeight + 44) const Http = require("../utils/HttpBasics"); const imgurl = require("../utils/imgurl"); const config = require("../config/config"); let app = getApp(); Page({ /** * 页面的初始数据 */ data: { navigationBarHeight, lists: [], merchantVoList:[], indexId: 0, businessId:0, windowHeight:"", page:1, isFirstPage:false, isLastPage:false, teljpgUrl: imgurl.teljpg.url }, // 左侧点击事件 jumpIndex(e) { let that = this; let index = e.currentTarget.dataset.menuindex; that.setData({ indexId: index, businessId: index }); that.setData({ page:1 }) that.getList(1, that.data.businessId); }, goSearchBar(){ wx.navigateTo({ url: '/pages/searchbar/searchbar', }) }, /** * 跳转到门店列表的详情页面 */ gotoDetail(e){ wx.navigateTo({ url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}` }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; that.getBussiness(); that.getList(1, 0); wx.showLoading({ title: '加载中...', }) }, onShow(){ if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 1 }) } let that = this; wx.getSystemInfo({ success: function (res) { that.setData({ windowHeight: res.windowHeight + navigationBarHeight }) }, }) }, getBussiness:function(){ let that = this; Http.get({ url: config.api.businessList, data:{ filter:1 } }).then(res => { that.setData({ lists: [{ id: 0, title: "全部", type: 1 }].concat(res.data) }); }) .catch(err => { wx.showToast({ title: err.errMsg, icon: 'none', duration: 2000, mask: false }); }) }, getList: function (page, businessId) { let that = this; let data; if(businessId == 0){ data = { pageNum: page, pageSize: 8 } }else{ data = { pageNum: page, pageSize: 8, businessId: businessId } } Http.get({ url: config.api.merchantList, data: data }).then(res => { wx.hideLoading(); if (page == 1) { that.setData({ merchantVoList: [], }) } var tmpArr = that.data.merchantVoList; tmpArr.push.apply(tmpArr, res.data.list); // console.log(tmpArr) that.setData({ merchantVoList: tmpArr, isFirstPage: res.data.isFirstPage, isLastPage: res.data.isLastPage }) // console.log(that.data.merchantVoList) }) .catch(err => { wx.hideLoading(); wx.showToast({ title: err.errMsg, icon: 'none', duration: 2000, mask: false }); }) }, phone: function (e) { let that = this; if (e.currentTarget.dataset.merchantlinkphone) { wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.merchantlinkphone }) } }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { let that = this; that.data.page++; that.setData({ page: that.data.page }); console.log(that.data.page); // 如果是最后一页 //就不发送请求 if (!that.data.isLastPage || that.data.isFirstPage && that.data.isLastPage){ that.getList(that.data.page, that.data.businessId); } } })