collectlist.js 4.7 KB
// pages/collectlist/collectlist.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nav: 1,
    delBtnWidth: 160,
    data: [],
    isScroll: true,
    windowHeight: 0,
    page:1,
    colectlist:[],
    dianpinglist:[],
    pagek:1,
    nomore:false
  },
  sel(e) {
    this.setData({
      nav: e.currentTarget.dataset.id
    })
    if(this.data.nav==1){
      this.setData({
        page:1,
        colectlist:[]
      })
      this.getcollect()
    }else{
      this.setData({
        page: 1,
        data:[]
      })
      this.getcommentlist()
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          windowHeight: res.windowHeight
        });
      }
    });

    this.getcollect()
  },

  goodtail(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/shopdetail/shopdetail?id=' + id,
    })
  },
  drawStart: function (e) {
    // console.log("drawStart");  
    var touch = e.touches[0]

    for (var index in this.data.data) {
      var item = this.data.data[index]
      item.right = 0
    }
    this.setData({
      data: this.data.data,
      startX: touch.clientX,
    })

  },
  drawMove: function (e) {
    var touch = e.touches[0]
    var item = this.data.data[e.currentTarget.dataset.index]
    var disX = this.data.startX - touch.clientX

    if (disX >= 20) {
      if (disX > this.data.delBtnWidth) {
        disX = this.data.delBtnWidth
      }
      item.right = disX
      this.setData({
        isScroll: false,
        data: this.data.data
      })
    } else {
      item.right = 0
      this.setData({
        isScroll: true,
        data: this.data.data
      })
    }
  },
  drawEnd: function (e) {
    var item = this.data.data[e.currentTarget.dataset.index]
    if (item.right >= this.data.delBtnWidth / 2) {
      item.right = this.data.delBtnWidth
      this.setData({
        isScroll: true,
        data: this.data.data,
      })
    } else {
      item.right = 0
      this.setData({
        isScroll: true,
        data: this.data.data,
      })
    }
  },

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

          }
          app.post(url, params).then((res) => {
            console.log(res);
            wx.showToast({
              title: '删除成功',
              icon:"none"
            })
            that.setData({
              pagek:1,
              data:[]
            })
            that.getcommentlist()



          }).catch((err) => {

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

  // 获取我的收藏
  getcollect(){
    let that = this;
    var url = 'member/getShopCollect';
    var params = {
     page:that.data.page,
     limit:15

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

      console.log(that.data.colectlist)

    }).catch((err) => {

    })
  },
  // 获取我的点评
  getcommentlist(){
    let that = this;
    var url = '/member/getRemarkCollect';
    var params = {
      page: that.data.pagek,
      limit:15

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



    }).catch((err) => {

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    if(this.data.nav==1){
      let newpage = this.data.page;
      newpage++;
      this.setData({
        page: newpage
      })
      this.colectlist()
    }else{
      let newpage=this.data.pagek;
      newpage++;
      this.setData({
        pagek:newpage
      })
      this.getcommentlsit()
    }
   

  },

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

  }
})