闫增涛
2025-03-28 b97bfcb85b2ded3b1f380e9a98b54b836faabba5
pages/digitalCourses/index.js
@@ -1,4 +1,7 @@
// pages/digitalCourses/index.js
import {
  loginInfo
} from '../../assets/js/login';
const app = getApp()
import {
  setSessionGuid,
@@ -68,7 +71,8 @@
      });
    }
    this.getCourseTypeListList()
    this.getShoppingCartList()
    const token = wx.getStorageSync(app.config.tokenKey)
    if (token) this.getShoppingCartList()
  },
  /**
@@ -288,55 +292,66 @@
    })
  },
  addCart(e) {
    const {
      item
    } = e.currentTarget.dataset;
    wx.showToast({
      title: "建设中",
      icon: 'none',
      duration: 1000
    })
    if (wx.getStorageSync(app.config.tokenKey)) {
      let query = {
        start: 0,
        size: 999,
        filterList: [],
        searchList: []
      }
      try {
        if (
          this.data.shoppingCartGetId.includes(
            item.defaultSaleMethodId
          )
        ) {
          wx.showToast({
            title: "该课程已在购物车,请勿重复添加",
            icon: 'none',
            duration: 1000
          })
        } else {
          let query = {
            requests: [{
              saleMethodId: item.defaultSaleMethodId,
              storeEventId: null,
              agentCode: '数字课程'
            }]
          }
          const addRes = app.MG.store.addShoppingCart(query)
          if (addRes) {
    const addFun = () => {
      const {
        item
      } = e.currentTarget.dataset;
      wx.showToast({
        title: "建设中",
        icon: 'none',
        duration: 1000
      })
      if (wx.getStorageSync(app.config.tokenKey)) {
        let query = {
          start: 0,
          size: 999,
          filterList: [],
          searchList: []
        }
        try {
          if (
            this.data.shoppingCartGetId.includes(
              item.defaultSaleMethodId
            )
          ) {
            wx.showToast({
              title: "添加成功",
              icon: 'success',
              title: "该课程已在购物车,请勿重复添加",
              icon: 'none',
              duration: 1000
            })
          } else {
            let query = {
              requests: [{
                saleMethodId: item.defaultSaleMethodId,
                storeEventId: null,
                agentCode: '数字课程'
              }]
            }
            const addRes = app.MG.store.addShoppingCart(query)
            if (addRes) {
              wx.showToast({
                title: "添加成功",
                icon: 'success',
                duration: 1000
              })
            }
            this.getShoppingCartList()
          }
          this.getShoppingCartList()
        } catch (error) {
          console.error('出错了:', error)
        }
      } catch (error) {
        console.error('出错了:', error)
      }
    }
    const token = wx.getStorageSync(app.config.tokenKey)
    if (token) {
      addFun()
    } else {
      loginInfo(app, (data) => {
        if (data) {
          this.getShoppingCartList()
        }
      })
    }
  },
})