From c96612e8a63ecef9590be0f8b5199277ec94e5b9 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期三, 18 九月 2024 18:43:12 +0800
Subject: [PATCH] 云学习购买目录,修改bug

---
 pages/digitalCourses/index.js |  217 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 172 insertions(+), 45 deletions(-)

diff --git a/pages/digitalCourses/index.js b/pages/digitalCourses/index.js
index b4d5ba5..a99fbbf 100644
--- a/pages/digitalCourses/index.js
+++ b/pages/digitalCourses/index.js
@@ -17,7 +17,37 @@
     tabList: [],
     courseList: [],
     searchValue: '',
-    activeItem: null
+    active: 0,
+    activeItem: null,
+    loading: false,
+    contentLoading: false,
+    noData:false,
+    shoppingCartGetId: [],
+    sorter: {
+      value: "*",
+      options: [{
+          value: "*",
+          label: "榛樿鎺掑簭",
+        },
+        {
+          value: "nameAsc",
+          label: "鐐瑰嚮閲忔搴�",
+        },
+        {
+          value: "nameDesc",
+          label: "鐐瑰嚮閲忓�掑簭",
+        },
+        {
+          value: "timeAsc",
+          label: "鍒涘缓鏃堕棿姝e簭",
+        },
+        {
+          value: "timeDesc",
+          label: "鍒涘缓鏃堕棿鍊掑簭",
+        },
+      ],
+    },
+    sortActive: '',
   },
 
   /**
@@ -32,7 +62,13 @@
       barHeight: systInfo.statusBarHeight,
       navBarHeight: navBarHeight,
     });
+    if (options.courseTypeActive) {
+      this.setData({
+        active: JSON.parse(options.courseTypeActive),
+      });
+    }
     this.getCourseTypeListList()
+    this.getShoppingCartList()
   },
 
   /**
@@ -85,6 +121,9 @@
   },
   onTabsChange(event) {
     const value = event.detail.value
+    this.setData({
+      contentLoading: true
+    })
     this.getCourseList(this.data.tabList[value])
   },
 
@@ -93,12 +132,15 @@
     wx.navigateBack();
   },
   getCourseTypeListList() {
+    this.setData({
+      loading: true,
+    })
     const data = {
       path: '*',
-      filterList: [{
-        value: 'Normal',
-        field: 'state'
-      }],
+      // filterList: [{
+      //   value: 'Normal',
+      //   field: 'state'
+      // }],
       queryType: '\\',
       searchList: [],
       size: '20',
@@ -110,52 +152,63 @@
       }
     }
     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,
-        activeItem: newData[0]
+        loading: false
       })
-      this.getCourseList(newData[0])
-
+      if (this.data.active) {
+        this.getCourseList(newData[this.data.active])
+      } else {
+        this.setData({
+          activeItem: newData[0],
+        })
+        this.getCourseList(newData[0])
+      }
 
     })
   },
 
   getCourseList(item) {
     let searchObj = {}
-    // let sort = {}
+    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()
       }
     }
 
-    // if (timeSort.value) {
-    //     sort = {
-    //         CreateDate: timeSort.value || 'Desc'
-
-    //     }
-    // } else {
-    //     sort = {
-    //         ViewCount: nameSort.value || 'Desc'
-    //     }
+    if (this.data.sortActive == 'nameAsc') {
+      sort = {
+        ViewCount: 'Asc'
+      }
+    } else if (this.data.sortActive == 'nameDesc') {
+      sort = {
+        ViewCount: 'Desc'
+      }
+    } else if (this.data.sortActive == 'timeAsc') {
+      sort = {
+        CreateDate: 'Asc'
+      }
+    } else if (this.data.sortActive == 'timeDesc') {
+      sort = {
+        CreateDate: 'Desc'
+      }
+    }
     //     // 缁勫悎鐨勫啓娉� 瑕佹煡璇㈢殑瀛楁:鍗囧簭鍜岄檷搴�
-
-    //     // Name: "Desc"
-    //     //涓�鑸殑鎺掑簭浼犳硶
-    //     // type: "Asc",
-    //     // field: "CreateDate",
-    // }
-    // courseList.value = [];
     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
       },
@@ -167,7 +220,7 @@
         value: 'Normal',
         field: 'state'
       }],
-      // sort: sort,
+      sort: sort,
       fields: {
         courseLeader: [],
         affiliatedUnit: [],
@@ -178,34 +231,108 @@
       }
     }
     app.MG.store.getProductList(obj).then((res) => {
-      console.log(res, '7895')
+      if(!res.datas.length) {
+        return this.setData({
+          noData:true,
+          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,
       })
-
-      console.log(this.data.courseList);
-
     })
   },
   searchBook() {
-    console.log(this.data.searchValue);
     this.getCourseList(this.data.activeItem)
   },
+  onSort(e) {
+    this.setData({
+      "sortActive": e.detail.value,
+    });
+    this.getCourseList(this.data.activeItem);
+  },
   courseDetail(e) {
-    console.log(e);
     const item = e.currentTarget.dataset.item
-
     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
     })
 
-  }
+  },
+  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