niangjiushi.js 3.8 KB
// pages/findblock/niangjiushi/niangjiushi.js
const app=getApp()
Page({

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

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      url: app.globalData.url
    })
   
  },
  //获取酿酒大师列表
  getniangju(){
    let that = this;
    let url = 'index/Find/master_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) => {

    })


  },

  //关注
  atten(e){
    let id=e.currentTarget.dataset.id;

    let that = this;
    let url = 'index/Common/concern', params = {
      sort:2,
      id:id


    }
    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.winemaker_id==id){
          if (obj.is_concern==0){
            obj.is_concern=1
          }else{
            obj.is_concern=0
          }
        }
      }

      that.setData({
        list:newlist
      })


    }).catch((err) => {

    })
  },
  //点赞和取消点赞
  zan(e){
    let that = this;
    let id = e.currentTarget.dataset.id;
    let url = 'index/Common/good', params = {
     id:id,
     sort:3


    }
    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.winemaker_id==id){
        if (obj.is_good==0){
          obj.is_good=1;
          obj.good_count = obj.good_count+1 
        }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;
    wx.navigateTo({
      url: '/pages/myblock/pingjia/pingjia?winemaker_id='+id+'&type='+3,
    })
  },
  //酿酒大师详情
  niangjiuteacherdetail(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/homeblock/niangjiuteacher/niangjiuteacher?id='+id,
    })
  },

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

  },

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

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

  },

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

  },

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

  },

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    let that = this;

    let id = e.target.dataset.id;


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