import { requestCategory, } from '../../http/api/categoryApi'
import { requestGooodsList } from '../../http/api/goodsApi'
Page({
/**
* 页面的初始数据
*/
data: {
menu: [],
goodsList:[],
curIndex: 0,
activeId: null,
pageData:1,
pageSize:10,
hasLoadData:true,
itemCateData:{}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.setNavigationBarTitle({
title: '分类',
})
},
switchCategory(e) {
let itemData= e.currentTarget.dataset.bean;
this.setData({
goodsList:[],
pageData:1,
curIndex: e.currentTarget.dataset.index?e.currentTarget.dataset.index:0,
itemCateData:itemData
})
this.getGoodsData(itemData)
},
getGoodsData(itemData){
let that =this;
let postdata= {
shopId: 1008600001,
pageNum:this.data.pageData,
pageSize: this.data.pageSize,
categoryId:itemData.id
}
requestGooodsList(postdata,).then((res) => {
let resultData= res.data.list.map((item) => {
return {
...item,
gallery:item.gallery.split(','),
};
});
if(resultData.length < that.data.pageSize){
this.setData({
hasLoadData:false,
})
}else{
this.setData({
hasLoadData:true,
})
}
this.setData({
goodsList: this.data.goodsList.concat(resultData),
})
})
},
productDetails(event) {
let delID= event.currentTarget.dataset.bean.id;
wx.navigateTo({
url: `/pages/detail/detail?delID=${delID}`,
});
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
let that =this;
if(this.data.hasLoadData==true){
this.setData({
pageData: that.data.pageData + 1
})
this.getGoodsData(this.data.itemCateData)
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
loadCategory(){
let postdata={
shopId: 1008600001,
}
requestCategory(postdata).then((res) => {
this.getGoodsData(res.data[0])
this.setData({
menu:res.data,
itemCateData:res.data[0]
})
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.loadCategory()
const tabBar = this.getTabBar()
tabBar.setData({
TabBarActive: 1
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
网友评论