// pages/beerShop/beerShop.js const app = getApp(); const request = require("../../utils/request.js"); const login = require("../../utils/login.js"); Page({ /** * 页面的初始数据 */ data: { head_item: 0, choice_show: false, beerTypeId: null, breweryId: null, lastProductId: null, breweryTagList: [], styleList: [], productDataList: [] }, toBeerDetail(event) { login.ifLogin('../beerDetail/beerDetail?productId=' + event.currentTarget.dataset.pid) }, getProductList() { let that = this; let breweryId = that.data.breweryId; let beerTypeId = that.data.beerTypeId; request.getData( 'app/product/list', {breweryId: breweryId, beerTypeId: beerTypeId}, res => { that.setData({ productDataList: res.data.data }) }, res => { console.log(res) } ) }, bindHead(event) { let id = event.currentTarget.dataset.id; if(this.data.head_item == id) { this.setData({ head_item: 0, choice_show: false }) }else{ this.setData({ head_item: id, choice_show: true }) } }, choiceShow() { this.setData({ choice_show: false, head_item: 0, }) }, chooseStyle(e) { let id = e.currentTarget.dataset.id; if(this.data.beerTypeId == id) { this.setData({ beerTypeId: null, choice_show: false, head_item: 0 }) }else{ this.setData({ beerTypeId: id, choice_show: false, head_item: 0 }) } this.getProductList(); }, chooseBrewery(e) { let id = e.currentTarget.dataset.id; if(this.data.breweryId == id) { this.setData({ breweryId: null, choice_show: false, head_item: 0 }) }else{ this.setData({ breweryId: id, choice_show: false, head_item: 0 }) } this.getProductList(); }, getTagData() { let that = this; request.getData( 'app/tag/filtrate/list',{}, res => { let breweryTagList = res.data.data.breweryTagList; breweryTagList.unshift({ breaweryName: '全部', breweryId: null }) let styleList = res.data.data.styleList; styleList.unshift({ beerTypeName: '全部', beerTypeId: null }) that.setData({ breweryTagList: breweryTagList, styleList: styleList }) }, res => { console.log(res) } ) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; that.getTagData(); that.getProductList(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 1 }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { let that = this; let breweryId = that.data.breweryId; let beerTypeId = that.data.beerTypeId; let lastProductId = Number(that.data.productDataList[that.data.productDataList.length-1].productId); request.getData( 'app/product/list', {breweryId: breweryId,beerTypeId: beerTypeId, lastProductId: lastProductId}, res => { that.setData({ productDataList: that.data.productDataList.concat(res.data.data) }) }, res => { console.log(res) } ) }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, })