From 338ad19ee45b5380a0d8433cbbce2a727a576dfa Mon Sep 17 00:00:00 2001
From: yiming <m13691596795@163.com>
Date: 星期五, 19 四月 2024 17:34:36 +0800
Subject: [PATCH] bug2

---
 packageBookService/pages/bookServices/detail/buyResource/index.js |  128 ++++++++++++++++++++++++++++++++----------
 1 files changed, 96 insertions(+), 32 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/buyResource/index.js b/packageBookService/pages/bookServices/detail/buyResource/index.js
index 7395880..8c61ce1 100644
--- a/packageBookService/pages/bookServices/detail/buyResource/index.js
+++ b/packageBookService/pages/bookServices/detail/buyResource/index.js
@@ -10,19 +10,23 @@
     learn: [],
     openLearnids: [],
     bookId: "",
-    loading: false,
+    loading: true,
     shoppingList: [],
     shoppingCartGetId: [],
     methodId: [],
     paymentPage: false,
     superior: false,
-    checkAllState: false,
+    checkAllState: true,
+    productLinkPath: '',
+    refCode: '',
+    haider: false
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
+    this.getBookInfo(options.bookId);
     const systInfo = wx.getSystemInfoSync();
     const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
     const navBarHeight =
@@ -31,15 +35,11 @@
       barHeight: systInfo.statusBarHeight,
       navBarHeight: navBarHeight,
       bookId: options.bookId,
+      productLinkPath: options.productLinkPath,
+      refCode: options.refCode
     });
     this.getResourceClass();
-    console.log(options);
-    this.getResourceData({
-      productLinkPath: options.productLinkPath,
-      refCode: options.refCode,
-    });
     this.getShoppingCartProductGet();
-    this.getBookInfo(options.bookId);
   },
 
   /**
@@ -119,6 +119,7 @@
           return this.setData({
             noResources: true,
             loading: false,
+            haider: true
           });
         }
         //鏁欏璧勬簮 浜戝涔�
@@ -135,6 +136,7 @@
               this.setData({
                 teach: list,
                 loading: false,
+                haider: true
               });
               this.findChildIds(this.data.teach, (this.data.openTeachids = []));
             } else if (type.refCode == "jsek_cloudLearning") {
@@ -147,9 +149,10 @@
                 learn: list,
                 loading: false,
                 openLearnids: result,
+                haider: true
               });
-              console.log("鏁欏璧勬簮", list);
             }
+            console.log(list, '浜戝缈�');
           } else {
             // 鏃犳暟鎹�
           }
@@ -158,6 +161,7 @@
           this.setData({
             test: res.datas.cmsDatas[0].datas,
             loading: false,
+            haider: true
           });
         } else {
           console.log("鍏朵粬");
@@ -199,6 +203,7 @@
         jsek_resourceBrief: [],
         jsek_link: [],
         accessType: [],
+        learnSelectType: [],
       },
       pading: {
         start: 0,
@@ -228,12 +233,12 @@
     });
     data.datas.cmsDatas[0].datas.forEach((item) => {
       item.checked = false;
-      item.isbuy = this.resourceIsBuy(item);
+      item.isbuy = this.isShowNeedBuy(item);
       item.isShopCar = this.isShoppingCart(item);
     });
     return data.datas.cmsDatas[0].datas;
   },
-  getBookInfo(id) {
+  async getBookInfo(id) {
     this.setData({
       "mockData'.id": 0,
       "mockData.price": 0,
@@ -271,12 +276,17 @@
         freeEpubPage: [], //epub璇曡鐧惧垎姣�
       },
     };
-    app.MG.store.getProductDetail(query).then(async (res) => {
+    await app.MG.store.getProductDetail(query).then(async (res) => {
       this.setData({
         bookDetail: res.datas,
         buyIdList: res.datas.purchasedSaleMethodIdList,
       });
+      this.getResourceData({
+        productLinkPath: this.data.productLinkPath,
+        refCode: this.data.refCode,
+      });
     });
+
   },
   // 鑾峰彇宸茶喘涔板晢鍝�
   getShoppingCartProductGet() {
@@ -303,6 +313,22 @@
       const isSHow = this.data.buyIdList.some(
         (item) => item == data.saleMethod[0].Id
       );
+      return !isSHow;
+    } else {
+      return false;
+    }
+  },
+
+  isShowNeedBuy(data) {
+    if (data.saleMethod && data.saleMethod.length) {
+      const isSHow = this.data.buyIdList.some(
+        (item) => item == data.saleMethod[0].Id
+      );
+      if (isSHow) {
+        return false;
+      } else {
+        return data.saleMethod[0].price > 0 ? true : false;
+      }
       return !isSHow;
     } else {
       return false;
@@ -380,25 +406,15 @@
     let item = [];
     let selectAllId = [];
     const child = this.selectComponent("#tree");
-
-    console.log(
-      child.data.superiorPurchaseSaleMethodId,
-      "superiorPurchaseSaleMethodId"
-    );
-    console.log(child.data.sonPurchaseSaleMethodId, "child.data");
-    // console.log(child.data.selectAll, 'selectAll');
     item = child.data.superiorPurchaseSaleMethodId;
     const sonItem = child.data.sonPurchaseSaleMethodId;
     let selectAll = child.data.selectAll;
     if (selectAll) {
-      // console.log(selectAll);
       selectAll.forEach((item) => {
         if (item.saleMethod != 0) {
-          // console.log(item, 'item');
           selectAllId.push(item.saleMethod[0].Id);
         }
       });
-      console.log(selectAllId);
       app.MG.store
         .initOrder({
           requests: selectAllId.map((id) => ({
@@ -409,8 +425,7 @@
         .then((res) => {
           if (res) {
             wx.navigateTo({
-              url:
-                "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
+              url: "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
             });
             selectAllId = [];
             child.setData({
@@ -420,15 +435,12 @@
         });
     }
     if (item) {
-      console.log(item, "sadsdasd");
       // 鎷垮埌id
       item.forEach((items) => {
         if (items.saleMethod != 0) {
           saleMethodIds.push(items.saleMethod[0].Id);
         }
       });
-      console.log(saleMethodIds, "saleMethodIds");
-
       app.MG.store
         .initOrder({
           requests: saleMethodIds.map((id) => ({
@@ -439,8 +451,7 @@
         .then((res) => {
           if (res) {
             wx.navigateTo({
-              url:
-                "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
+              url: "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
             });
 
             child.setData({
@@ -460,8 +471,7 @@
         .then((res) => {
           if (res) {
             wx.navigateTo({
-              url:
-                "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
+              url: "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
             });
             this.setData({
               paymentPage: true,
@@ -473,4 +483,58 @@
         });
     }
   },
-});
+
+  // 绔犺妭鍕鹃�夋柟娉�
+  findAndUpdateItemsByIds(tree, ids, state) {
+    function findAndUpdate(node) {
+      if (ids.includes(node.id)) {
+        // console.log(node, 'node');
+        node.checked = state; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
+      }
+      if (node.children && node.children.length > 0) {
+        for (let child of node.children) {
+          findAndUpdate(child); // 閫掑綊澶勭悊瀛愯妭鐐�
+        }
+      }
+    }
+    for (let node of tree) {
+      findAndUpdate(node); // 瀵规瘡涓《灞傝妭鐐规墽琛屾煡鎵惧拰鏇存柊鎿嶄綔
+    }
+    // console.log(tree, 'tree345');
+    return tree; // 杩斿洖淇敼鍚庣殑瀹屾暣鏁扮粍
+  },
+  // 鍗曚釜鍕鹃�夋柟娉�
+  checkResoucrceInfo(tree, id) {
+    function findAndUpdate(node) {
+      if (node.sysType == "CmsFolder" && node.children.length > 0) {
+        for (let index = 0; index < node.children.length; index++) {
+          const element = node.children[index];
+          findAndUpdate(element);
+        }
+      } else if (id == node.id && node.sysType == "CmsItem") {
+        node.checked = !node.checked; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
+      }
+    }
+    for (let node of tree) {
+      findAndUpdate(node); // 瀵规瘡涓《灞傝妭鐐规墽琛屾煡鎵惧拰鏇存柊鎿嶄綔
+    }
+    return tree; // 杩斿洖淇敼鍚庣殑瀹屾暣鏁扮粍
+  },
+  // 绔犺妭鍕鹃�変簨浠�
+  changeListChecked(e) {
+    const ids = e.detail.ids
+    const state = e.detail.flag
+    const updated = this.findAndUpdateItemsByIds(this.data.learn, ids, state)
+    this.setData({
+      learn: updated
+    })
+  },
+  // 鍗曚釜鍕鹃�変簨浠�
+  changeResourceChecked(e) {
+    const id = e.detail.id
+    const updated = this.checkResoucrceInfo(this.data.learn, id)
+    this.setData({
+      learn: updated
+    })
+  }
+});
\ No newline at end of file

--
Gitblit v1.9.1