niangjiuteacher.js 4.5 KB
// pages/homeblock/niangjiuteacher/niangjiuteacher.js
var WxParse = require('../../../wxParse/wxParse.js');
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
    id:'',
    page:1,
    jiushishow:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      url: app.globalData.url,
      id:options.id
    })
    let token=wx.getStorageSync("token");
    if(token==''){
      wx.navigateTo({
        url: '/pages/login/login?id=' + this.data.id + '&type=' + 1,//type=1发现的首页酿酒师
      })

      wx.setStorageSync("url", "/pages/homeblock/niangjiuteacher/niangjiuteacher")
    }
    
  },
  //获取酿酒师
  getniangjiu(){
    let that = this;
    let url = 'index/Winemaker/detail', params = {
     id:that.data.id,
    

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



      let newattr = res.attr;
      for (let i = 0; i < newattr.length; i++) {
        newattr[i].show = true

        WxParse.wxParse('content' + i, 'html', newattr[i]['content'], that, 5);

        if (i === newattr.length - 1) {

          WxParse.wxParseTemArray("artileList", 'content', newattr.length, that)
        }
      }

      that.setData({
        attr: newattr
      })



    }).catch((err) => {

    })
  },
  showinfo(e) {
    let idx = e.currentTarget.dataset.idx;
    console.log(idx)
    let newattr = this.data.attr;
    for (var i = 0; i < newattr.length; i++) {
      if (i == idx) {
        newattr[i].show = !newattr[i].show
      }
    }
    this.setData({
      attr: newattr
    })
  },
  //关注和取消关注
  attention(e){
    let that = this;
    let id=e.currentTarget.dataset.id;

   
    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 newinfo=that.data.info;
      if (newinfo.is_concern==0){
        newinfo.is_concern=1
      }else{
        newinfo.is_concern = 0
      }


      that.setData({
        info:newinfo
      })


    }).catch((err) => {

    })
  },

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

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

      let newinfo = that.data.info;
      console.log(newinfo)
      if (newinfo.is_good == 0) {
        newinfo.is_good = 1;
        newinfo.good_count = newinfo.good_count+1
      } else {
        newinfo.is_good = 0;
        if (newinfo.good_count==0){
          newinfo.good_count=0
        }else{
          newinfo.good_count = newinfo.good_count-1
        }
      }


      that.setData({
        info: newinfo
      })

      console.log(that.data.info)


    }).catch((err) => {

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

  jiushinfoshow() {
    this.setData({
      jiushishow: !this.data.jiushishow
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

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

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.setStorageSync("guantype", 1)
  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let that = this;
   
    let  url = '/pages/homeblock/niangjiuteacher/niangjiuteacher?id='+ that.data.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)
      }
    }
  }
})