const app = getApp() Page({ /** * 页面的初始数据 */ data: { listClassify:[],//分类 goodId:1, goodsByClassifyList:[],//商品列表 filePath:app.globalData.$filePath }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getListClassify(); }, getListClassify(){ app.requestP({ url:'/zy/goods/listClassify', method:'get', }).then(res=>{ this.setData({ listClassify:res.data.data, goodId:res.data.data[0].id || '' }) this.getListGoodsByClassify({ classifyId:res.data.data[0].id || '', pageSize:999, pageNum:1 }) }).catch(err=>{ app.showToptip(this,'error',err.data.msg) }) }, getListGoodsByClassify(params={}){ app.requestP({ url:'/zy/goods/listGoodsByClassify', method:'post', contentType:'application/json', data:params }).then(res=>{ this.setData({ goodsByClassifyList:res.data.rows.map(item=>{ return {...item,banners:this.data.filePath+JSON.parse(item.banners)[0]} }) }) }).catch(err=>{ app.showToptip(this,'error',err.data.msg) }) }, goIfy(e){ var that = this; const id = e.currentTarget.dataset.id; this.setData({ goodId:id },()=>{ that.getListGoodsByClassify({ classifyId:id+'', pageSize:999, pageNum:1 }) }) }, goGoodsInfo(e){ const item = e.currentTarget.dataset.item; wx.navigateTo({ url: '/pages/zyShop/zyShopInfo/zyShopInfo?content='+encodeURIComponent(JSON.stringify(item.content || '暂无'))+'&icon='+item.banners+'&name='+item.name+'&id='+item.id+'&tags='+item.tags+'&classifyId='+item.classifyId+'&price='+item.price, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, exchange(){ wx.navigateTo({ url: '/pages/zyShop/recordList/recordList', }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })