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.
183 lines
3.4 KiB
183 lines
3.4 KiB
// pages/signIn/signIn.js
|
|
var app = getApp()
|
|
import { getDisplay,getDisplayProduct } from "../../api/home"
|
|
let that
|
|
|
|
Page({
|
|
data: {
|
|
activeKey: 0,
|
|
displayList:[],
|
|
displayProductList:[],
|
|
cateId:10,
|
|
page:1,
|
|
limit:10
|
|
},
|
|
getDisplayList() {
|
|
|
|
getDisplay({}).then(res => {
|
|
if(res.code ==1) {
|
|
that.setData({
|
|
displayList: res.data
|
|
})
|
|
console.log(that.data.activeKey)
|
|
that.getDisplayProductList({
|
|
cate_id:that.data.displayList[that.data.activeKey].id,
|
|
page:that.data.page,
|
|
limit:that.data.limit
|
|
})
|
|
|
|
|
|
}
|
|
})
|
|
|
|
|
|
},
|
|
|
|
//触底响应函数
|
|
onBottom(){
|
|
if(that.data.displayProductList.length==that.data.limit*that.data.page){
|
|
(that.data.page)++;
|
|
that.getDisplayProductList({
|
|
cate_id:that.data.displayList[that.data.activeKey].id,
|
|
page:that.data.page,
|
|
limit:that.data.limit
|
|
})
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//获取列表失败的回调函数
|
|
getListFail(err){
|
|
wx.showToast({
|
|
title: '获取失败,请稍后重试',
|
|
icon:'none',
|
|
duration:2500,
|
|
})
|
|
},
|
|
|
|
|
|
|
|
getDisplayProductList(query){
|
|
getDisplayProduct(query).then(res => {
|
|
if(res.code ==1) {
|
|
if (that.data.page == 1) {
|
|
that.setData({
|
|
displayProductList: res.data,
|
|
})
|
|
} else {
|
|
|
|
//获取原始列表
|
|
let displayProductList = that.data.displayProductList;
|
|
//获取新列表
|
|
let arr = res.data;
|
|
//新列表数据与原列表数据合并
|
|
let newArr = displayProductList.concat(arr);
|
|
that.setData({
|
|
displayProductList: newArr,
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
onChange(event) {
|
|
that.setData({
|
|
activeKey:event.detail,
|
|
page:1
|
|
})
|
|
that.getDisplayProductList({
|
|
cate_id:that.data.displayList[event.detail].id,
|
|
page:that.data.page,
|
|
limit:that.data.limit
|
|
})
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
that = this
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
if(app.globalData.id=='undefined'||app.globalData.id==null||app.globalData.id==''){
|
|
|
|
that.setData({
|
|
activeKey:0
|
|
})
|
|
}else{
|
|
that.setData({
|
|
activeKey:app.globalData.id
|
|
})
|
|
}
|
|
|
|
|
|
that.getTabBar().init();
|
|
that.getDisplayList();
|
|
|
|
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
this.onBottom();
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
},
|
|
// 下拉
|
|
onPageScroll: function(e) {
|
|
if (e.scrollTop < 0) {
|
|
wx.pageScrollTo({
|
|
scrollTop: 0
|
|
})
|
|
}
|
|
}
|
|
})
|