detail.js 6.8 KB
// pages/index/detail/detail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgs: ['/images/img3.png'],
    poster_state: false,
    more_state: false,
    id: '',
    tables: [],
    list: [],
    state: false,
    name: '',
    comment_text: '',
    user_id: '',
  },


  //评论
  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,
    })
  },

  showPoster(e) {
    var id = e.currentTarget.dataset.id
    var that = this
    var list = that.data.list
    list.showMore = false
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 2000
    })
    this.setData({
      more_state: false
    })
    this.getPoster(id)
  },

  canclePopup() {
    var list = this.data.list
    for (var i = 0; i < list.length; i++) {
      list[i].more_state = false
    }
    this.setData({
      poster_state: false,
      // list: list,
      more_state: false
    })
    wx.showTabBar({})
  },

  getPoster(id) {
    let that = this;
    let url = '/home/index/fashionShare';
    let param = {
      list_id: id
    }
    let header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, param, header).then((res) => {
      console.log(res)

      if (res.data.code == 20000) {
        this.setData({
          poster: res.data.data.url,
        })
        setTimeout((res) => {
          that.setData({
            poster_state: true
          })
          wx.hideTabBar({})
        })
      } else if (res.data.code == 30001) {
        wx.showToast({
          title: '上传图片才可生成海报',
          icon: 'none',
          duration: 2000
        })
        that.setData({
          poster_state: false
        })
        wx.showTabBar({})
      }

    })
  },

  showMore() {
    this.setData({
      more_state: !(this.data.more_state)
    })
  },

  complain(e) {
    var id = e.currentTarget.dataset.id
    var type = e.currentTarget.dataset.type
    wx.navigateTo({
      url: '/pages/index/comment/comment?id=' + id + '&type=' + type,
    })
  },

  replay(e) {
    var id = e.currentTargent.dataset.id
    var comment_state = e.currentTargent.dataset.comment_state
    var name = e.currentTargent.dataset.name
    if (comment_state == 1) {
      this.setData({
        state: true,
        name: name
      })
    }
    // wx.navigateTo({
    //   url: '/pages/index/comment/comment',
    // })
  },

  getData() {
    let that = this;
    let url = '/home/index/fashionEdit';
    let param = {
      list_id: this.data.id
    }
    let header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, param, header).then((res) => {
      console.log('数据:', res)
      var list = res.data.data.fashion
      list.more_state = false
      if (res.data.code == 20000) {
        that.setData({
          list: list,
          tables: res.data.data.tables,
        })
      }
    }).catch((errMsg) => {})
  },

  submitComment(e) {
    var id = e.currentTarget.dataset.id
    let url = '/home/index/tablePost'
    let params = {
      list_id: id,
      text: e.detail.value
    }
    let header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      if (res.data.code == 20000) {
        this.getData()
        this.setData({
          comment_text: ''
        })
      }
    })
  },


  //点击关注
  attention(e) {
    var status = ''
    var index = e.currentTarget.dataset.index
    var id = e.currentTarget.dataset.id
    var list = this.data.list
    if (list.user_host == 1) {
      list.user_host = 0
      status = 2
    } else {
      list.user_host = 1
      status = 1
    }
    this.attentionInfo(id, status)
    this.setData({
      list: list
    })
  },

  //关注接口
  attentionInfo(id, status) {
    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()
      }
    })
  },

  //点赞
  likeCharge(e) {
    var id = e.currentTarget.dataset.id
    var list = this.data.list
    var status = ''
    if (list.user_support == 1) {
      list.user_support = 0
      status = 2
    } else {
      list.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.getData()
      }
    })
  },

  //收藏,取消收藏
  collectInfo(e) {
    var id = e.currentTarget.dataset.id
    var list = this.data.list
    var status = ''
    if (list.user_collect == 1) {
      list.user_collect = 0
      status = 2
    } else {
      list.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.getData()
      }
    })
  },

  showMore(e) {
    var index = e.currentTarget.dataset.index
    var list = this.data.list
    list.more_state = !(list.more_state)
    this.setData({
      more_state: !(this.data.more_state),
      list: list
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      id: options.id ? options.id : '',
      user_id: wx.getStorageSync('user_id')
    })
  },

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

  },

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

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

  },

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

  },

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

  },

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

  },

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

  }
})