You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
5.3 KiB

//获取应用实例
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
indicatorDots: true,
autoplay: true,
interval: 5000,
duration: 1000,
imgUrls: [],
// 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/title-icon.png',
cityId: 440100000,
typeNum: 10,
addrArray: { id: [440100000, 430426000], name: ['长沙', '深圳', '上海', '长沙', '武汉', '杭州', '北京'] },
addrIndex: 0,
},
/**
* 城市选择
*/
bindAddrChange: function (e) {
this.setData({
_num: e.detail.value + 1,
addrIndex: e.detail.value
}),
this.getActivityList();
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let that = this;
wx.request({
url: app.gw.hostUrl + '/mall/wxa/activity/banner',
method: 'get',
data: {
merchantNo: 'SH180331153109966163'
},
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;
console.log(res);
that.setData({
imgUrls: data.response
})
} else {
wx.showToast({
title: data.msg,
icon: 'none',
duration: 3000
});
return;
}
},
fail: function (res) {
wx.showToast({
title: '加载数据失败',
});
},
}),
this.getActivityList();
},
getActivityList: function(){
let that = this;
wx.showNavigationBarLoading() //在标题栏中显示加载
wx.request({
url: app.gw.hostUrl + '/mall/wxa/activity/list',
method: 'get',
data: {
merchantNo: 'SH180331153109966163',
// selectedCityId: that.data.addrArray.id[that.data.addrIndex] == undefined ? 0 : that.data.addrArray.id[that.data.addrIndex],
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;
console.log(res);
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: '加载数据失败',
});
},
complete: function (res) {
// complete
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
},
})
},
/**
* 点击去开团
*/
openGroup:function(e){
console.log('activityNo:' + e.currentTarget.dataset.item);
wx.navigateTo({
url: '../activity_detail/activity_detail?activityNo=' + e.currentTarget.dataset.item,
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
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
})
}
})