zhuanjiapinjiu.js 3.5 KB
// pages/findblock/zhuanjiapinjiu/zhuanjiapinjiu.js
const app=getApp()
Page({

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

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

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



    }).catch((err) => {

    })
  },

  //进入视频
  entervideo(e) {
    let url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: '/pages/homeblock/video/video?url=' + url,
    })
  },

  //点赞
  dianzan(e){
    let id=e.currentTarget.dataset.id;
    let that = this;
    let url = 'index/Common/good', params = {
      id:id,
      sort:2


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

      let newlist = that.data.list;
      for(var obj of newlist){
        if(obj.id==id){
          if (obj.is_good==0){
            obj.is_good=1;
            obj.good_count++
          }else{
            obj.is_good = 0
            if (obj.good_count==0){
              obj.good_count=0
            }else{
              obj.good_count = obj.good_count-1
            }

            
          }
        }
      }

      that.setData({
        list:newlist
      })



    }).catch((err) => {

    })
  },

  //进入评论页面
  ping(e) {
    let id = e.currentTarget.dataset.id;
    let type = 2
    // let winemaker_id = e.currentTarget.dataset.winemaker_id
    wx.navigateTo({
      url: '/pages/myblock/pingjia/pingjia?type=' + type + '&id=' + id 
    })
  },

  //专家酒品详情页
  detail(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/findblock/zhuanjiapinjiudetail/zhuanjiapinjiudetail?id='+id,
    })
  },

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

  },

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

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

  },

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

  },

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

  },

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

    this.getjiulist()
  },

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

    let url = '/pages/findblock/zhuanjiapinjiudetail/zhuanjiapinjiudetail?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)
      }
    }
  }
})