From 38cd76c5f05fd55855038e2d393074e27909c63d Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期五, 28 三月 2025 15:28:01 +0800
Subject: [PATCH] 剩余页面登录迁移

---
 pages/digitalCourses/index.js |  153 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 95 insertions(+), 58 deletions(-)

diff --git a/pages/digitalCourses/index.js b/pages/digitalCourses/index.js
index 9175e6e..204a643 100644
--- a/pages/digitalCourses/index.js
+++ b/pages/digitalCourses/index.js
@@ -1,4 +1,7 @@
 // pages/digitalCourses/index.js
+import {
+  loginInfo
+} from '../../assets/js/login';
 const app = getApp()
 import {
   setSessionGuid,
@@ -20,6 +23,8 @@
     active: 0,
     activeItem: null,
     loading: false,
+    contentLoading: false,
+    noData: false,
     shoppingCartGetId: [],
     sorter: {
       value: "*",
@@ -45,7 +50,7 @@
         },
       ],
     },
-    sortActive: ''
+    sortActive: '',
   },
 
   /**
@@ -66,7 +71,8 @@
       });
     }
     this.getCourseTypeListList()
-    this.getShoppingCartList()
+    const token = wx.getStorageSync(app.config.tokenKey)
+    if (token) this.getShoppingCartList()
   },
 
   /**
@@ -119,6 +125,9 @@
   },
   onTabsChange(event) {
     const value = event.detail.value
+    this.setData({
+      contentLoading: true
+    })
     this.getCourseList(this.data.tabList[value])
   },
 
@@ -128,14 +137,14 @@
   },
   getCourseTypeListList() {
     this.setData({
-      loading: true
+      loading: true,
     })
     const data = {
       path: '*',
-      filterList: [{
-        value: 'Normal',
-        field: 'state'
-      }],
+      // filterList: [{
+      //   value: 'Normal',
+      //   field: 'state'
+      // }],
       queryType: '\\',
       searchList: [],
       size: '20',
@@ -147,8 +156,12 @@
       }
     }
     app.MG.store.getStoreChannelList(data).then((res) => {
-      // 鍘婚櫎鏁扮粍鏈�鍚庝竴涓厓绱�
       const newData = res.datas.slice(0, res.datas.length - 1)
+      newData.unshift({
+        name: "鍏ㄩ儴",
+        pathList: newData[0].pathList[0],
+        id: ""
+      })
       this.setData({
         tabList: newData,
         loading: false
@@ -166,13 +179,17 @@
   },
 
   getCourseList(item) {
+    this.setData({
+      noData: false,
+    })
     let searchObj = {}
     let sort = {}
     // // 鎼滅储妗�
     if (this.data.searchValue) {
       searchObj = {
-        'Name*': this.data.searchValue.trim()
-        // '||subtitle*': searchInputValue.value.trim()
+        'Name*': this.data.searchValue.trim(),
+        '||isbn*': this.data.searchValue.trim(),
+        '||courseLeader*': this.data.searchValue.trim()
       }
     }
 
@@ -196,7 +213,9 @@
     //     // 缁勫悎鐨勫啓娉� 瑕佹煡璇㈢殑瀛楁:鍗囧簭鍜岄檷搴�
     const obj = {
       storeInfo: app.config.goodsStore,
-      path: item.pathList + '\\' + item.id,
+      // path: item.pathList + '\\' + item.id,
+      path: item.id ? item.pathList + '\\' + item.id : item.pathList,
+      queryType: "*",
       coverSize: {
         width: 260
       },
@@ -219,14 +238,22 @@
       }
     }
     app.MG.store.getProductList(obj).then((res) => {
+      if (!res.datas.length) {
+        return this.setData({
+          noData: true,
+          courseList: [],
+          contentLoading: false
+        })
+      }
       res.datas.forEach(item => {
         item.price = item.price.toFixed(2)
+        item.productLinkInfo = JSON.parse(item.productLinkInfo)
       })
-
+      // 鎺掗櫎鍏朵粬鍒嗙被閲岀殑鏁版嵁
       this.setData({
-        courseList: res.datas
+        courseList: res.datas,
+        contentLoading: false,
       })
-
     })
   },
   searchBook() {
@@ -236,7 +263,6 @@
     this.setData({
       "sortActive": e.detail.value,
     });
-    console.log(e)
     this.getCourseList(this.data.activeItem);
   },
   courseDetail(e) {
@@ -244,7 +270,7 @@
     setNewView('productId', item.id)
     this.getCourseTypeListList()
     wx.navigateTo({
-      url: '/pages/digitalCourses/digitalCoursesDetails/index?id=' + item.id,
+      url: '/pages/digitalCourses/digitalCoursesDetails/index?id=' + item.id + '&path=' + item.idPath
     })
 
   },
@@ -266,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()
+        }
+      })
+    }
   },
 
 })
\ No newline at end of file

--
Gitblit v1.9.1