commentdetail.js 6.2 KB
// pages/commentdetail/commentdetail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    commentid: '',
    commentdetail: '',
    sendactive: false,
    comment: '',
    shopid:'',
    ispraise:false,
    iscollect:false,
    sendshow:false

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      commentid: options.commentid,
      shopid:options.shopid
    })
    this.getcommentdetail()
  },

  mycomment(){
    wx.navigateTo({
      url: '/pages/mycomment/mycomment',
    })
  },

  getcommentdetail() {
    let that = this;
    var url = 'remark/getRemarkInfo';
    var params = {
      id: that.data.commentid,

    }
    app.post(url, params, "post").then((res) => {
      console.log(res);
      that.setData({
        commentdetail: res
      })
        // var imagesk=[];
        // console.log(that.data.commentdetail.images.length)
        // if(that.data.commentdetail.images.length>9){
        //   for(var i=0;i<that.data.commentdetail.images.length;i++){
        //     if(i<9){
        //       imagesk.push(that.data.commentdetail.images[i])
        //     }
        //   }
        //   that.data.commentdetail.images=imagesk
        // }

        // that.setData({
        //   commentdetail:that.data.commentdetail
        // })
       
     

    }).catch((err) => {

    })
  },
// 进入主页
  personpage(e){
    console.log(e)
    let userid=e.currentTarget.dataset.userid;
    wx.navigateTo({
      url: '/pages/personpage/personpage?userid='+userid,
    })
  },
  // 输入评论内容
  enterword(e) {
    this.setData({
      comment:e.detail.value
    })
  },
  finish(){
    this.setData({
      sendactive:true
    })
  },

    // 评论图片预览
    previewimgk(e){
 
     
      let index=e.currentTarget.dataset.index;
      wx.previewImage({
        current: this.data.commentdetail.images[index],
        urls:this.data.commentdetail.images,
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
        })
  
    },

  // 发送评论
  send(){
    let that = this;
   
    
    if (that.data.comment==''){
      wx.showToast({
        title: '请输入评论',
        icon:"none"
      })
     
    }else{
      that.setData({
        sendshow: true
      })
      var url = 'remark_comments/addComments';
      var params = {
        remark_id: that.data.commentid,
        content: that.data.comment
      }
      app.post(url, params).then((res) => {
        console.log(res);
        wx.showToast({
          title: '评论成功',
          icon: 'none'
        })

        setTimeout(function () {
          wx.navigateBack({
            checked: true
          })
        }, 1500)

        app.globalData.shopid = this.data.shopid



      }).catch((err) => {

      })
    }
    
  },

  // 点赞
  praise(e){
    let that=this;
    let id=e.currentTarget.dataset.id;
    that.setData({
      ispraise:!that.data.ispraise
    })
    if(that.data.ispraise==true){
      wx.showToast({
        title: '点赞成功',
        icon:"none"
      })

      that.data.commentdetail.praise_num = that.data.commentdetail.praise_num+1;
      that.setData({
        commentdetail: that.data.commentdetail
      })
    }else{
      wx.showToast({
        title: '取消点赞成功',
        icon: "none"
      })
      that.data.commentdetail.praise_num = that.data.commentdetail.praise_num-1;
      that.setData({
        commentdetail: that.data.commentdetail
      })
    }

   
    var url = '/remark/remarkPraise';
    var params = {
      remark_id: id,

    }
    app.post(url, params,"post").then((res) => {
      console.log(res);



    }).catch((err) => {

    })

  },

  // 收藏
  collect(e) {
    let that = this;
    let id = e.currentTarget.dataset.id;
    that.setData({
      iscollect: !that.data.iscollect
    })
    if (that.data.iscollect == true) {
      wx.showToast({
        title: '收藏成功',
        icon: "none"
      })

      that.data.commentdetail.collect_num = that.data.commentdetail.collect_num + 1;
      that.setData({
        commentdetail: that.data.commentdetail
      })
    } else {
      wx.showToast({
        title: '取收藏赞成功',
        icon: "none"
      })
      that.data.commentdetail.collect_num = that.data.commentdetail.collect_num - 1;
      that.setData({
        commentdetail: that.data.commentdetail
      })
    }


    var url = '/remark/remarkCollect';
    var params = {
      remark_id: id,

    }
    app.post(url, params, "post").then((res) => {
      console.log(res);



    }).catch((err) => {

    })

  },

  // 评论列表点赞
  xiaozan(e){
    let that = this;
    let id=e.currentTarget.dataset.id;
    let index=e.currentTarget.dataset.index;
    that.data.commentdetail.comments.forEach(function(value,indexk,array){
      if (indexk==index){
         
            if(value.is_praise==0){
              value.is_praise=1;
              value.praise_num = value.praise_num+1
              wx.showToast({
                title: '点赞成功',
                icon:"none"
              })
            }else{
              value.is_praise=0;
              value.praise_num = value.praise_num-1
              wx.showToast({
                title: '取消点赞成功',
                icon: "none"
              })
            }
        }
    })

    that.setData({
      commentdetail: that.data.commentdetail
    })
    var url = 'remark_comments/remarkPraise';
    var params = {
      remark_comments_id: id,

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



    }).catch((err) => {

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})