//获取应用实例 const app = getApp() var merchantNo = ''; Page({ /** * 页面的初始数据 */ data: { indicatorDots: true, autoplay: true, interval: 5000, duration: 1000, imgUrls: [], // merchantNo: '', // bannerImage: '/images/activity_banner.png', menu_list: [{ name: '拼团', disabled: false, className: 'green_button' }, { name: '秒杀', disabled: true, className: 'gray_button' }, { name: '夺宝', disabled: true, className: 'gray_button' }, { name: '砍价', disabled: true, className: 'gray_button' } ], nowDate: new Date().getTime(), activityList: [], pageNum: 1, pageSize: 20, hasMoreData: true, img1: '/images/u40.png', addrIndex: 0, districtName: '', }, /** * 城市选择 */ bindAddrChange: function(e) { this.setData({ _num: e.detail.value + 1, addrIndex: e.detail.value }), this.getActivityList(); }, /** * 生命周期函数--监听页面加载 */ onShow: function(options) { let that = this; //获取本地数据 // 获取地址 wx.getStorage({ key: 'districtName', success: function(res) { that.setData({ districtName: res.data }) } }); // 商家编号 wx.getStorage({ key: 'merchantNo', success: function(res) { that.setData({ merchantNo: res.data }), that.getActivityList(); wx.request({ url: app.gw.hostUrl + '/mall/wxa/activity/banner', method: 'get', data: { merchantNo: res.data }, header: { 'Content-Type': 'application/x-www-form-urlencoded' }, success: function(res) { var data = res.data; var status = data.code; if (status == 0) { var data = res.data; var status = data.code; that.setData({ imgUrls: data.response }) } else { wx.showToast({ title: data.msg, icon: 'none', duration: 3000 }); return; } }, fail: function(res) { wx.showToast({ title: '加载数据失败', }); }, }) } }); }, getActivityList: function() { let that = this; wx.showNavigationBarLoading() //在标题栏中显示加载 wx.request({ url: app.gw.hostUrl + '/mall/wxa/activity/list', method: 'get', data: { merchantNo: that.data.merchantNo, pageNum: that.data.pageNum, pageSize: that.data.pageSize }, header: { 'Content-Type': 'application/x-www-form-urlencoded' }, success: function(res) { var data = res.data; var status = data.code; var activitylistTem = that.data.activityList; if (status == 0) { if (that.data.pageNum == 1) { //刷新清空数据 activitylistTem = []; } var list = data.response; if (list.length < that.data.pageSize) { //最后一页数据添加 that.setData({ activityList: activitylistTem.concat(list), hasMoreData: false }); } else { that.setData({ activityList: activitylistTem.concat(list), hasMoreData: true, pageNum: that.data.pageNum + 1 }); } } else { wx.showToast({ title: data.msg, icon: 'none', duration: 3000 }); return; } }, fail: function(res) { wx.showToast({ title: '加载数据失败', }); console.log(res) }, complete: function(res) { // complete wx.hideNavigationBarLoading() //完成停止加载 wx.stopPullDownRefresh() //停止下拉刷新 }, }) }, /** * 点击去开团 */ openGroup: function(e) { wx.navigateTo({ url: '../activity_detail/activity_detail?activityNo=' + e.currentTarget.dataset.item, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { let that = this; this.data.pageNum = 1; this.getActivityList(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { if (this.data.hasMoreData) { this.getActivityList(); } else { wx.showToast({ title: '没有更多数据', }) } }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { }, getUserInfo: function(e) { console.log(e) app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) } })