jiulist.js 4.6 KB
// pages/findblock/jiulist/jiulist.js
const app=getApp()
Page({

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

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      type:options.type
    })
   
  },

  //获取名人酒单列表
  getwinelist(){
    let that = this;
    let url = 'index/Find/rec_list', params = {
      page: that.data.page

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

      let newpeoplelist = that.data.peoplelist;
      for (var obj of newpeoplelist){
        
        for(var p of obj.list){
          
          p.choose=false
        }
      }
      that.setData({
        peoplelist:newpeoplelist
      })
      console.log(that.data.peoplelist)


    }).catch((err) => {

    })
  },

  //出现弹层
  shareAction(e){
    let id=e.currentTarget.dataset.id;
    let newpeoplelist=this.data.peoplelist
    for (var obj of newpeoplelist){
      for(var p of obj.list){
        if(p.id==id){
          p.choose = !p.choose
        }
       
      }
    }

    this.setData({
      peoplelist: newpeoplelist
    })
  },
//点赞
  zan(e){
    let id=e.currentTarget.dataset.id;
    let that = this;
    let url = 'index/Common/good', params = {
      sort:1,
      id:id

    }
    app.post(url, params).then((res) => {
      console.log(res);
      wx.showToast({
        title: res,
        icon:'none'
      })
      let newpeoplelist = that.data.peoplelist;
      for (var obj of newpeoplelist) {
        for (var p of obj.list) {
          if (p.user_id == id) {
            if (p.is_good==0){
              p.is_good=1;
              p.good_count = p.good_count+1
            }else{
              p.is_good = 0;
              if (p.good_count ==0){
                p.good_count = 0
              }else{
                p.good_count = p.good_count - 1
              }
             
            }
           
          }

        }
      }

      this.setData({
        peoplelist: newpeoplelist
      })

    }).catch((err) => {

    })
  },

  //收藏和取消收藏
  collect(e){
    let id=e.currentTarget.dataset.id;
    let that = this;
    let url = 'index/Common/favorite', params = {
      sort:3,
      id:id

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

      let newpeoplelist = that.data.peoplelist
      for (var obj of newpeoplelist) {
        for (var p of obj.list) {
          if (p.user_id == id) {
            if (p.is_favorite==0){
              p.is_favorite=1
            }else{
              p.is_favorite = 0
            }
          }

        }
      }

      that.setData({
        peoplelist: newpeoplelist
      })

     


    }).catch((err) => {

    })
    
  },
  pinglun(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/myblock/pingjia/pingjia?id='+id+'&type='+this.data.type,
    })
  },
  //进入详情页
  detail(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/findblock/jiudandetail/jiudandetail?id='+id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      page:1,
      peoplelist:[]
    })
    this.getwinelist()
  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let page=this.data.page;
    page++;
    this.setData({
      page:page
    })

    this.getwinelist()
  },  

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    let that = this;
    console.log(e)
    let id = e.target.dataset.id;
    console.log(id)
   
    let url = '/pages/findblock/jiudandetail/jiudandetail?id=' + id
  


    return {
      title: '发现', // 转发后 所显示的title
      // path: '/pages/home/buildtextdetail/buildtextdetail?buildid='+buildid+'&gettoken='+newtoken, // 相对的路径

      path: url,//建档攻略分享1
      // path:'',
      success: (res) => {    // 成功后要做的事情
        console.log(res)

      },
      fail: function (res) {
        // 分享失败
        console.log(res)
      }
    }
  }
})