mycomment.js 5.3 KB
// pages/morecomment/morecomment.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    comentarr: ['全部', '审核中', '已发布', '未通过'],
    coment: 0,
    type:'',
    commentlist:[],
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getcomment()
  },
  selitem(e) {
    console.log(e)
    this.setData({
      coment: e.currentTarget.dataset.index,
      page:1,
      commentlist:[]
    })

    console.log(this.data.coment)
    if (this.data.coment==0){
      this.setData({
        type:''
      })
    } else if (this.data.coment==1){
      console.log(this.data.comment)
      this.setData({
        type:1
      })
      console.log(this.data.type)
    } else if (this.data.coment==2){
      this.setData({
        type:2
      })
    } else if (this.data.coment == 3) {
      this.setData({
        type: 3
      })
    }
    console.log(this.data.type)

    this.getcomment()

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

  // 获取我的评论
  getcomment(){
    console.log(990900)
    var that = this;
    var url = 'member/getRemark';
    var params = {
      type: that.data.type,
      page:that.data.page,
      limit:15

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



    }).catch((err) => {

    })

  },

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

  },

  // 店铺收藏
  collect(e){
    let id=e.currentTarget.dataset.id;
    let index=e.currentTarget.dataset.index;
    console.log(index)
    let that = this;
    var url = '/shop/shopCollect';
    var params = {
      shop_id: id,

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

      that.data.commentlist.forEach(function(value,indexk,array){
        if(index==indexk){
          if (value.is_collect==0){
            value.is_collect=1;
            wx.showToast({
              title: '店铺收藏成功',
              icon: 'none'
            })
          } else if (value.is_collect == 1){
            value.is_collect = 0;
            wx.showToast({
              title: '取消店铺收藏成功',
              icon: 'none'
            })
          }
        }
      })

      that.setData({
        commentlist: that.data.commentlist
      })
      console.log(that.data.commentlist)



    }).catch((err) => {

    })
  },
  goodtail(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/shopdetail/shopdetail?id=' + id,
    })
  },

  // goodtail(e) {
  //   let token = wx.getStorageSync("token");
  //   if (token == '') {
  //     wx.showToast({
  //       title: '请先登录',
  //       icon: "none"
  //     })
  //     setTimeout(function() {
  //       wx.navigateTo({
  //         url: '/pages/index/index',
  //       })
  //     }, 1500)
  //   } else {
  //     let id = e.currentTarget.dataset.id;
  //     wx.navigateTo({
  //       url: '/pages/shopdetail/shopdetail?id=' + id,
  //     })
  //   }

  // },

  // 删除点评
  delcomment(e){
    let that = this
    let id=e.currentTarget.dataset.id;
    wx.showModal({
      title: '提示',
      content: '是否删除此条评论',
      success(res) {
        if (res.confirm) {
          var url = '/remark/deleteRemark';
          var params = {
            remark_id:id

          }
          app.post(url, params).then((res) => {
            console.log(res);
            wx.showToast({
              title: '删除点评成功',
              icon:'none'
            })
            console.log(6666)
            that.setData({
              commentlist:[],
              page:1,
            })

            that.getcomment()

          }).catch((err) => {

          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },
  // 点评详情
  comentdetail(e) {
    let commentid = e.currentTarget.dataset.id;
    let shopid=e.currentTarget.dataset.shop_id
    wx.navigateTo({
      url: '/pages/commentdetail/commentdetail?commentid='+commentid+'&shopid='+ this.data.shopid,
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

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

  }
})