meirixinjiu.js 2.2 KB
// pages/findblock/meirixinjiu/meirixinjiu.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
    page:1,
    winelist:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      url: app.globalData.url
    })
    this.getwinelist()
  },  
  //获取每日新酒列表
  getwinelist(){
    let that = this;
    let url = 'index/Find/new_list', params = {
      page: that.data.page

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        winelist: res.all_list
      })



    }).catch((err) => {

    })

  },
  //收藏和取消收藏
  collect(e) {

    let that = this;
    let id = e.currentTarget.dataset.id;
    let url = 'index/Common/favorite', params = {
      sort: 1,
      id: id

    }
    app.post(url, params).then((res) => {
      console.log(res);
      wx.showToast({
        title: res,
        icon:'none'
      })

      let newwinelist = that.data.winelist;
      console.log(newwinelist)
      for(var obj of newwinelist){
        for(var p of obj.list){
          if (p.wine_id == id) {
            if (p.is_favorite == 0) {
              p.is_favorite = 1
            } else {
             p.is_favorite = 0
            }
          }
        }
       
      }
      that.setData({
        winelist: newwinelist
      })


    }).catch((err) => {

    })
  },

  jump(e){
    let id=e.currentTarget.dataset.id;
    console.log(id)
    wx.navigateTo({
      url: '/pages/homeblock/jiuzidian/jiuzidian?id=' + id,
    })
  },

 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})