jiangping
2024-07-24 af9f7ad7d711f0562e4394449a117da20f808fc2
wechat_staff/pages/detailDis/product.js
@@ -3,6 +3,7 @@
  getProductInfo,
  actionDo
} from '../../api/index'
import moment from "moment";
Page({
  /**
   * 页面的初始数据
@@ -33,6 +34,43 @@
      member
    })
  },
  //  组件事件
  handleEnjoy(e) {
    const enjoyList = wx.getStorageSync('enjoyList') || []
    const { type, flag } = e.detail
    console.log('type', type);
    console.log('flag', flag);
    const info = this.data.info
    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: 'product',
          timestamp: new Date().getTime()
        })
      }else{
        info.isEnjoy = false
        this.setData({ info })
        enjoyList.splice(index, 1)
      }
      wx.setStorageSync('enjoyList', enjoyList)
    }else{
      actionDo({
        id: info.id,
        actionType: flag ? 'collect' : 'collect_cancel'
      }).then(res => {
        info.isCollection = flag
        wx.showToast({title: flag ? '收藏成功' : '取消收藏'})
        this.setData({
          info
        })
      })
    }
  },
  handleAction(e) {
    const actionType = e.currentTarget.dataset.code
    const {
@@ -42,7 +80,7 @@
      actionType,
      id: this.data.info.id
    }).then(res => {
      info.collection = !info.collection
      info.isCollection = !info.isCollection
      this.setData({
        info
      })
@@ -51,12 +89,20 @@
      })
    })
  },
  onShareAppMessage() {
    console.log('用户点击了分享');
  },
  getDetail(id) {
    const enjoyList = wx.getStorageSync('enjoyList') || []
    getProductInfo({
      id
    }).then(res => {
      const index = enjoyList.findIndex( i => i.id === res.data.id )
      this.setData({
        info: res.data
        info: {
          ...res.data,
          isEnjoy: index > -1
        }
      })
      wx.setNavigationBarTitle({
        title: res.data.title