90 lines
2.1 KiB
JavaScript
90 lines
2.1 KiB
JavaScript
/**
|
|
* 手太欠
|
|
* 5g获客星光网 - 商城
|
|
*/
|
|
|
|
const data = require("../../data/demo")
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
banners : [], //banner图
|
|
categories : [], //分类
|
|
freeCoupon : [], //免费劵商品列表
|
|
hotSale : [], //优惠热爱列表
|
|
pushList : [], //推荐商品列表
|
|
page : {}, //分页信息
|
|
lodingStats : false //加载状态
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(){
|
|
// 获取商城首页数据
|
|
this.indexInfo();
|
|
|
|
// 获取为您推荐
|
|
this.pushInfo();
|
|
},
|
|
|
|
/**
|
|
* 商城首页数据
|
|
*/
|
|
indexInfo () {
|
|
wx.$api.mall.index().then(res=>{
|
|
this.setData({
|
|
banners : res.banners,
|
|
categories : res.categories,
|
|
freeCoupon : res.free_coupon,
|
|
hotSale : res.hot_sale
|
|
})
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 为您推荐
|
|
*/
|
|
pushInfo(page) {
|
|
wx.$api.mall.pushData({
|
|
page : page,
|
|
pagesize: 15
|
|
}).then(res=>{
|
|
let listArr = this.data.pushList,
|
|
newData = []
|
|
if(page == 1 || page == undefined) listArr = []
|
|
newData = listArr.concat(res.data)
|
|
this.setData({
|
|
pushList : newData,
|
|
page : res.page,
|
|
lodingStats : false
|
|
})
|
|
wx.stopPullDownRefresh()
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
// 获取为您推荐
|
|
this.pushInfo();
|
|
},
|
|
|
|
/**
|
|
* 上拉加载
|
|
*/
|
|
onReachBottom(){
|
|
this.setData({
|
|
lodingStats: true
|
|
})
|
|
let pageNumber = this.data.page.current
|
|
if(this.data.page.has_more){
|
|
pageNumber++
|
|
// 获取为您推荐
|
|
this.pushInfo(pageNumber);
|
|
}
|
|
}
|
|
}) |