// subPackage/page/pages/myReleaseDetail.js
const app = getApp()
const wxService = require('../../../../utils/wxService')
const utils = require('../../../../utils/util')
const { memberId } = wx.getStorageSync('_baseUserInfo')


wxService.page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    showDialig: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options && options.id) {
      this.setData({
        id: options.id
      })
    }
  },
  handleDel() {
    this.setData({
      showDialig: true
    })
  },

  // 获取内容详情
  getContentDetail() {
    wxService.post(`/merchant/contentMobileTerminal/terminalContentParticulars`, {
      id: this.data.id,
      userId: memberId
    }).then(res => {
      if (!res) return false
      const { result, data } = res.data
      if (result == 0) {
        this.setData({
          contentInfo: data
        })
        
      }

    }).finally(() => {
    })
  },

  // 点赞
  gotoLike() {
    const { memberId } = wx.getStorageSync('_baseUserInfo')
    let params = {
      contentId: this.data.contentInfo.id,
      type: this.data.contentInfo.type,
      userId: memberId
    }
    if (!this.data.contentInfo.currentType) {
      wxService.post(`/merchant/contentMobileTerminal/operationSave`, params).then(res => {
        if (!res) return false
        const { result, data } = res.data
        if (result == 0) {
          wx.showToast({
            title: '点赞成功',
            icon: 'none'
          })
          this.getContentList(this.data.currentTab)
        }

      }).finally(() => {
      })

    } else {
      wxService.post(`/merchant/contentMobileTerminal/operationDelete`, {
        id: this.data.contentInfo.id,
        userId: memberId
      }).then(res => {
        if (!res) return false
        const { result, data } = res.data
        if (result == 0) {
          wx.showToast({
            title: '取消点赞成功',
            icon: 'none'
          })
          this.getContentList(this.data.currentTab)
        }

      }).finally(() => {
      })
    }
  },

  // 删除
  closeDialog(){
    wxService.post(`/merchant/contentMobileTerminal/contentDelete`, {
      id: this.data.contentInfo.id,
      userId: memberId
    }).then(res => {
      if (!res) return false
      const { result, data } = res.data
      if (result == 0) {
        wx.showToast({
          title: '删除成功',
          icon: 'none'
        })
        wxService.back()
      }

    }).finally(() => {
    })
  },

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

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

  },

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

  },

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

  },

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

  },

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

  }
})