From 21f34f1fc290cd129d24df2b25025e47e6ac028a Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期三, 06 三月 2024 15:26:00 +0800
Subject: [PATCH] feat(合并代码): 云测试

---
 pages/bookServices/detail/index.js |   80 +++++++++++++++++++++++++++++++++++----
 1 files changed, 71 insertions(+), 9 deletions(-)

diff --git a/pages/bookServices/detail/index.js b/pages/bookServices/detail/index.js
index e99bb9c..ee631de 100644
--- a/pages/bookServices/detail/index.js
+++ b/pages/bookServices/detail/index.js
@@ -6,6 +6,7 @@
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
+    bookId: '',
     barHeight: '',
     navBarHeight: '',
     options: {
@@ -26,8 +27,10 @@
     teachResources: [],
     teach: [],
     learn: [],
+    test: [],
     openTeachids: [],
     openLearnids: [],
+    openTestids: [],
     resourceClassList: [], // 璧勬簮鎵�灞炲垎绫�
     applyState: "",  // 鏁欏璧勬簮鐢宠鐘舵��
     deadline: "",  // 鏁欏璧勬簮鐢宠鏈夋晥鏃ユ湡
@@ -51,6 +54,7 @@
     const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
     const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
     this.setData({
+      bookId: options.id,
       barHeight: systInfo.statusBarHeight,
       navBarHeight: navBarHeight,
     });
@@ -63,7 +67,8 @@
     this.getBookInfo(options.id);
     this.getResourceClass() // 鑾峰彇璧勬簮鎵�灞炲垎绫�
     this.getApplyInfo(options.id)
-    if (wx.getAccountInfoSync('jsek-token')) {
+    const token = wx.getStorageSync('jsek-token')
+    if (token) {
       this.getShoppingCartProductGet()
     }
   },
@@ -295,7 +300,6 @@
         }
       }
     }
-    console.log('鍒囨崲', this.data.tabValue);
   },
   // 鑾峰彇璧勬簮鎵�灞炲垎绫�
   getResourceClass() {
@@ -340,7 +344,7 @@
           const data = res.datas.cmsDatas[0].datas.filter(
             (item) => item.refCode == 'jsek_questionBank'
           )
-          if (data.length) return getResourceData(data[0])
+          if (data.length) return this.getResourceData(data[0])
         }
         //鏁欏璧勬簮 浜戝涔�
         if (type.refCode == 'jsek_teachingResources' || type.refCode == 'jsek_cloudLearning') {
@@ -351,23 +355,26 @@
               })
               const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
               this.setData({
-                teachResources: list,
                 teach: list
               })
-              this.findChildIds(this.data.teachResources, this.data.openTeachids = [])
+              this.findChildIds(this.data.teach, this.data.openTeachids = [])
             } else if (type.refCode == 'jsek_cloudLearning') {
               const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
               this.setData({
                 learn: list
               })
-              console.log('浜戝涔�', this.data.learn);
-              this.findChildIds(this.data.teachResources, this.data.openLearnids = [])
+              this.findChildIds(this.data.learn, this.data.openLearnids = [])
             }
           } else {
             // 鏃犳暟鎹�
           }
         } else if (type.refCode == 'jsek_questionBank') {
-          console.log('浜戞祴璇�');
+          // const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
+          this.setData({
+            test: res.datas.cmsDatas[0].datas
+          })
+          // this.findChildIds(this.data.test, this.data.openTestids = [])
+          console.log('浜戞祴璇�', this.data.test);
         } else {
           console.log('鍏朵粬');
         }
@@ -375,7 +382,6 @@
       .catch((e) => {
         console.log(e)
       })
-    console.log('淇℃伅', this.data);
   },
   // 鑾峰彇tag涓嬫墍鏈夎祫婧�
   async getAllResource(data) {
@@ -726,6 +732,7 @@
       return false
     }
   },
+  // 鑾峰彇宸茶喘涔板晢鍝�
   getShoppingCartProductGet() {
     let query = {
       start: 0,
@@ -762,5 +769,60 @@
     } else {
       return false
     }
+  },
+  // 閬嶅巻鏍戠粨鏋勮浆鎹负鏁扮粍鏂规硶
+  handleTreeData(array) {
+    const flattenedArray = []
+    array.forEach((node) => {
+      // 灏嗗綋鍓嶈妭鐐规坊鍔犲埌灞曞紑鐨勬暟缁勪腑
+      flattenedArray.push(node)
+      // 閫掑綊澶勭悊瀛愯妭鐐�
+      if (node.children && node.children.length > 0) {
+        const childrenArray = handleTreeData(node.children)
+        flattenedArray.push(...childrenArray)
+      }
+    })
+    return flattenedArray.filter((item) => item.sysType == 'CmsItem')
+  },
+  // 浜戝涔犱竴閿鍙�
+  async getFreeResource() {
+    // if (!localStorage.getItem('jsek-token')) {
+    //   return logIn()
+    // }
+    let arr = handleTreeData(this.data.learn).filter((item) => resourceIsBuy(item))
+    let freeIds = arr.filter((item) => {
+      return item.saleMethod[0].Price == 0
+    })
+    if (!freeIds.length) return console.log('鏆傛棤鍏嶈垂璧勬簮')
+    btnLoading.freeBtn = true
+    let requests = []
+    freeIds.forEach((item, index) => {
+      if (resourceIsBuy(item)) {
+        requests.push({
+          saleMethodId: item.saleMethod[0].Id,
+          count: 1
+        })
+      }
+    })
+
+    let query = {
+      remarks: '浜戝涔�',
+      requests,
+    }
+    try {
+      const initOrderRes = await app.MG.store.initOrder(query)
+      let parameter = {
+        orderNum: initOrderRes.orderNumber
+      }
+      // 纭璁㈠崟
+      const confirmOrderRes = await MG.store.confirmOrder(parameter)
+      if (confirmOrderRes.orderNumber) {
+        // btnLoading.freeBtn = false
+        console.log('棰嗗彇鎴愬叡');
+        this.getBookInfo(this.data.bookId)
+      }
+    } catch (error) {
+      console.log(error)
+    }
   }
 })

--
Gitblit v1.9.1