pingjia.js 2.6 KB
// pages/myblock/pingjia/pingjia.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
    id:'',
    type:'',
    page:1,
    pinglist:[],
    content:'',
    winemaker_id:''
  },

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

    this.getpinglist()
  },
  //获取评论列表
  getpinglist(){

    let that = this;
    let chuanid='';
    if(that.data.type==3){
      chuanid=that.data.winemaker_id
    }else{
      chuanid=that.data.id
    }
    let url = 'index/Common/comment_detail', params = {
      sort:that.data.type,
      id: chuanid,
      page:that.data.page

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



    }).catch((err) => {

    })

  },

  //输入评论内容
  entertext(e){
    let content=e.detail.value;
    this.setData({
      content: content
    })
  },
  //发表评论
  publishcomment(){
    let that = this;
    if(that.data.content==''){
      wx.showToast({
        title: '请输入评论内容',
        icon:'none'
      })
    }else{
      let chuanid='';
      
      if (that.data.type == 3) {
        chuanid = that.data.winemaker_id
      } else {
        chuanid = that.data.id
      }
      let url = 'index/Common/comment', params = {
        sort: that.data.type,
        id: chuanid ,
        content: that.data.content
      }
      app.post(url, params).then((res) => {
        console.log(res);
        wx.showToast({
          title: res,
          icon: "none"
        })
        that.setData({
          page: 1,
          pinglist: []
        })
        that.getpinglist()


      }).catch((err) => {

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

  },

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

  },

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

  },

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

  },

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

  },

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

    this.getpinglist()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})