litian
2024-06-26 ccda9ec2fe70d8f51ef184eafc04b78d22dfbabd
pages/digitalCourses/index.js
@@ -18,7 +18,8 @@
    courseList: [],
    searchValue: '',
    activeItem: null,
    loading: false
    loading: false,
    shoppingCartGetId: []
  },
  /**
@@ -34,6 +35,7 @@
      navBarHeight: navBarHeight,
    });
    this.getCourseTypeListList()
    this.getShoppingCartList()
  },
  /**
@@ -212,6 +214,74 @@
      url: '/pages/digitalCourses/digitalCoursesDetails/index?id=' + item.id,
    })
  },
  getShoppingCartList() {
    let query = {
      start: 0,
      size: 999,
      filterList: [],
      searchList: []
  }
    app.MG.store.getShoppingCartProductList(query).then((res) => {
      let idList = [];
      res.datas.forEach((item) => {
        idList.push(item.saleMethod.id)
      })
      this.setData({
        shoppingCartGetId: idList
      })
    })
  },
  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) {
            wx.showToast({
              title: "添加成功",
              icon: 'success',
              duration: 1000
            })
          }
          this.getShoppingCartList()
        }
      } catch (error) {
        console.error('出错了:', error)
      }
    }
  },
})