userInfo.js 6.5 KB
// pages/my/userInfo/userInfo.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    look: 0,
    look_type: '',
    status: 1,
    page: 1,
    list: [],
  },

  goDetail(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/index/detail/detail?id=' + id,
    })
  },

  showMask(e) {
    this.setData({
      mask_state: true,
    })
  },

  cancleMask() {
    this.setData({
      mask_state: false
    })
  },

  attentionInfo() {
    var that = this
    var id = that.data.id
    var status = that.data.host
    status == 1 ? status = 2 : status = 1
    let url = '/home/index/host';
    let param = {
      open_user_id: id,
      status: status,
    }
    let header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, param, header).then((res) => {
      if (res.data.code == 20000) {
        that.getData()
      }
    })
  },

  goList(e) {
    var status = e.currentTarget.dataset.status
    var id = this.data.id
    wx.navigateTo({
      url: '/pages/index/fans/fans?status=' + status + '&id=' + id,
    })
  },

  //点赞
  likeCharge(e) {
    var id = e.currentTarget.dataset.id
    var index = e.currentTarget.dataset.index
    var list = this.data.list
    var status = ''
    if (list[index].user_support == 1) {
      list[index].user_support = 0
      status = 2
    } else {
      list[index].user_support = 1
      status = 1
    }
    this.setData({
      list: list
    })
    this.like(id, status)
  },

  like(id, status) {
    let url = '/home/index/support'
    let params = {
      list_id: id,
      status: status
    }
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      if (res.data.code == 20000) {
        this.getData2()
      }
    })
  },
  //收藏,取消收藏
  collectInfo(e) {
    console.log(e)
    var id = e.currentTarget.dataset.id
    var index = e.currentTarget.dataset.index
    var list = this.data.list
    var status = ''
    if (list[index].user_collect == 1) {
      list[index].user_collect = 0
      status = 2
    } else {
      list[index].user_collect = 1
      status = 1
    }
    this.setData({
      list: list
    })
    this.collect(id, status)
  },

  collect(id, status) {
    let url = '/home/index/collect'
    let params = {
      list_id: id,
      status: status
    }
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
      if (res.data.code == 20000) {
        this.getData2()
      }
    })
  },

  //评论
  review(e) {
    var id = e.currentTarget.dataset.id
    var type = e.currentTarget.dataset.type
    wx.navigateTo({
      url: '/pages/index/comment/comment?id=' + id + '&type=' + type,
    })
  },
  getData() {
    let url = '/home/index/userPage'
    let params = {
      open_user_id: this.data.id,
      look: this.data.look,
      look_type: this.data.look_type,
      page: this.data.page
    }
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
      if (res.data.code == 20000) {
        if (this.data.id != '') {
          var open_user_id = this.data.id
        } else {
          var open_user_id = res.data.data.list[0].open_user_id
        }
        this.setData({
          avatar: res.data.data.avatar,
          fans_num: res.data.data.fans_num,
          host: res.data.data.host,
          host_num: res.data.data.host_num,
          // list: res.data.data.list,
          open_user_id: open_user_id ,
          signature: res.data.data.signature,
          user_nickname: res.data.data.user_nickname
        })
      }
    })
  },

  getData2() {
    let url = '/home/index/checkPage'
    let params = {
      open_user_id: this.data.id,
      status: this.data.status,
      page: this.data.page
    }
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
      if (res.data.code == 20000) {
        this.setData({
          list: res.data.data.list
        })

      }
    })
  },

  chargeTime(e) {
    var current = e.currentTarget.dataset.current
    var tab_current = this.data.tab_current
    if (current == 1) {
      this.setData({
        state: !(this.data.state)
      })
    }
    if (current == 4) {
      this.setData({
        state2: true
      })
    } else {
      this.setData({
        state2: false
      })
    }
    if (tab_current == current) {
      return false
    } else {
      this.setData({
        tab_current: current,
        status: current,
      })
      this.getData2()
    }
  },


  //关注接口
  attentionInfo(e) {
    var id = this.data.id
    var host = this.data.host
    var status = ''
    host == 1 ? status = 2 : status = 1
    let that = this;
    let url = '/home/index/host';
    let param = {
      open_user_id: id,
      status: status
    }
    let header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, param, header).then((res) => {
      if (res.data.code == 20000) {
        this.getData()
      }
    })
  },


  goBox() {
    wx.navigateTo({
      url: '/pages/my/draft/draft',
    })
  },

  goMessage() {
    wx.navigateTo({
      url: '/pages/index/message/message',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      id: options.id ? options.id : '',
      look_type: options.look_type ? options.look_type : '',
      look: options.look ? options.look : ''
    })
    if (options.id != '' && options.id != undefined) {
      this.getData()
      this.getData2()
    }
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})