123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- // 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 () {
- },
- })
|