SpecialSale.js 2.43 KB
// packageIndex/pages/SpecialSale/SpecialSale.js
import cartApi from '~/api/module/cart.js'
import homeApi from '~/api/module/home.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageParams: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let userInfo = wx.p.storage.get('userInfo')
    this.setData({userInfo})
    wx.p.router.getRouterParams(options).then(params => {
      this.setData({
        pageParams: params
      })
    }).catch(err => {
      console.error('参数获取失败:', err)
    })
  },

    // 加入购物车
    handleAddToCart(e) {
      let value = e.detail
      // let { userInfo } = this.data
      // const PARAMS = {
      //   goodsId: value.goodsId,
      //   sellQty: 1,
      //   goodsSource: value.goodsSource,
      //   scoreSource: userInfo?.channelSource,
      //   merchantId: userInfo?.merchantId
      // }
      // if (!value.goodsStock) return wx.p.wxApi.showToast('暂无库存')
      // if (value.goodsSource == 1) {
      //   cartApi.addToCart(PARAMS).then(res => {
      //     wx.p.wxApi.showToast('加入购物车成功')
      //   })
      // } else {
        // 获取商品详情
        this.getDetail(value)
      // }
    },
    getDetail(options) {
      homeApi.getGoodsDetailInfo({id: options.id, businessType: 1}).then(res => {
        // if (res && res.specificationResponses?.length) {
        //   this.toGetSpecString(res, res.startQty)
        // }
        if (res && res.platformGlGoodsSpecifications?.length) {
          let item = res.platformGlGoodsSpecifications[0] || {}
          res.goodsStock = item.stock
          res.specificationData = item.specificationData
          this.setData({
            activeSku: item.specificationData
          })
        }
        this.setData({
          detailInfo: res || {},
          showSku: true
        })
      })
    },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})