jiangping
2024-07-29 d9a89d83c2048a964f16ca179feb2b7f21b9d33a
wechat_staff/pages/detailDis/realpic.js
@@ -1,4 +1,4 @@
import { getRealcaseInfo, actionDo } from '../../api/index'
import { getRealcaseInfo, actionDo ,refreshEnjoy} from '../../api/index'
Page({
  /**
@@ -15,6 +15,9 @@
  /**
   * 生命周期函数--监听页面加载
   */
  onShow(){
    refreshEnjoy(this)
  },
  onLoad(options) {
    var app = getApp().globalData
    this.setData({
@@ -35,16 +38,68 @@
      actionType,
      id: this.data.info.id
    }).then(res => {
      info.collection = !info.collection
      info.isCollection = !info.isCollection
      wx.showToast({
        title: actionType == 'collect' ? '收藏成功' : '取消收藏',
      })
      this.setData({info})
    })
  },
  handleEnjoy(e) {
    const info = this.data.info
    if(info.id == null ){
      return
    }
    const enjoyList = wx.getStorageSync('enjoyList') || []
    const { type, flag } = e.detail
    console.log('type', type);
    console.log('flag', flag);
    if(type == 'enjoy'){
      // 点击了喜欢
      const index = enjoyList.findIndex( i => i.id === info.id )
      if(index === -1){
        info.isEnjoy = true
        this.setData({ info })
        enjoyList.push({
          ...info,
          joinType: '2',
          timestamp: new Date().getTime()
        })
      }else{
        info.isEnjoy = false
        this.setData({ info })
        enjoyList.splice(index, 1)
      }
      wx.setStorageSync('enjoyList', enjoyList)
      refreshEnjoy(this)
    }else{
      actionDo({
        id: info.id,
        actionType: flag ? 'collect' : 'collect_cancel'
      }).then(res => {
        info.isCollection = flag
        wx.showToast({title: flag ? '收藏成功' : '取消收藏'})
        this.setData({
          info
        })
      })
    }
  },
  priviewSpace(e) {
    const url = e.currentTarget.dataset.url
    const { info } = this.data
    wx.previewImage({
      urls: info.contentImgList,
      current: url
    })
  },
  getDetail(id) {
    const enjoyList = wx.getStorageSync('enjoyList') || []
    getRealcaseInfo({id}).then(res => {
      this.setData({ info: res.data })
      const index = enjoyList.findIndex( i => i.id === res.data.id )
      this.setData({ info: {
        ...res.data, isEnjoy: index > -1
      }})
      wx.setNavigationBarTitle({
        title: res.data.title
     })