k94314517
2024-07-25 a75b18a4157ab486e0b51c438ac165ab3a08e3e0
wechat_staff/pages/detailDis/product.js
@@ -3,6 +3,7 @@
  getProductInfo,
  actionDo
} from '../../api/index'
import moment from "moment";
Page({
  /**
   * 页面的初始数据
@@ -33,30 +34,57 @@
      member
    })
  },
  handleAction(e) {
    const actionType = e.currentTarget.dataset.code
    const {
      info
    } = this.data
    actionDo({
      actionType,
      id: this.data.info.id
    }).then(res => {
      info.collection = !info.collection
      this.setData({
        info
  //  组件事件
  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: '0',
          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
        })
      })
      wx.showToast({
        title: actionType == 'collect' ? '收藏成功' : '取消收藏',
      })
    })
    }
  },
  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
@@ -155,6 +183,15 @@
  onHide() {
  },
  goTestPage(){
    wx.navigateTo({
      url: '/pages/webView/index',
      success: function(res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('data',{link:'http://crmtest.zhibang.com:8000/core/oauth/authorize/jump?timestamp=-465385833&agent_phone_number=18055151023&bindKey=mpAddIntention&sign=cdfe13abfe2727b40eee160085c80d11'} );
      }
    })
  },
  onUnload() {
  },
@@ -165,10 +202,4 @@
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  }
})