From ccda9ec2fe70d8f51ef184eafc04b78d22dfbabd Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期三, 26 六月 2024 15:02:28 +0800
Subject: [PATCH] 小程序,教材,课程

---
 pages/digitalCourses/index.js |   74 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/pages/digitalCourses/index.js b/pages/digitalCourses/index.js
index a07e0b7..45505fc 100644
--- a/pages/digitalCourses/index.js
+++ b/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)
+      }
+    }
+
+  },
 
 })
\ No newline at end of file

--
Gitblit v1.9.1