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

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

  /**
   * 生命周期函数--监听页面加载
   */
  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/findblock/wenzhangdetail/wenzhangdetail")
    }

  },
  //获取酿酒师
  getniangjiu() {
    let that = this;
    let url = 'index/Find/article_detail', params = {
      id: that.data.id,


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



      WxParse.wxParse('article', 'html', res.info.content, that, 5)


    }).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
    })
  },
 

  //点赞
  zan(e) {
    let that = this;
    let id = e.currentTarget.dataset.id;

    let url = 'index/Common/good', params = {
      sort: 4,
      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?id=' + id + '&type=' + 4,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

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

  },

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

  },

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

  },

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

  },

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

  }
})