From f2036f82c20767036fe8c4d627e5694e28e6ab73 Mon Sep 17 00:00:00 2001
From: QYF-GitLab1 <1940665526@qq.com>
Date: 星期二, 29 七月 2025 18:29:33 +0800
Subject: [PATCH] 修复资源移动目录产生的BUG

---
 packageBookService/pages/bookServices/detail/index.js |  295 +++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 198 insertions(+), 97 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js
index 72cd1ec..8fc6ca3 100644
--- a/packageBookService/pages/bookServices/detail/index.js
+++ b/packageBookService/pages/bookServices/detail/index.js
@@ -212,9 +212,20 @@
     protocolTxt: '',
     learnMenu: null,
     md5List: [],
-    editDialog: false
+    editDialog: false,
+    scrollTop: 0, // 鎵爜杩涜祫婧愭粴鍔�
+    source: '',
+    activeId: '',
+    qrTabValue: '',
+    cacheData: [], // 浜戝涔犲垵濮嬫暟鎹�
   },
-
+  // 鎵爜鍒拌祫婧愬垪琛紝婊氬姩鍒拌璧勬簮浣嶇疆
+  handleScrollTop(e) {
+    if (this.data.tabValue == this.data.qrTabValue)
+      this.setData({
+        scrollTop: e.detail.top
+      })
+  },
   resetTree: function (e) {
     this.setData({
       currentCheck: e.detail.checkedItem,
@@ -258,7 +269,11 @@
         name: decodeURI(options.name),
         storeInfo: options.storeInfo,
       },
+      source: options.source,
+      activeId: options.resourceId,
+      qrTabValue: options.tabValue
     });
+    console.log('浼犲弬', this.data);
     wx.setNavigationBarTitle({
       title: decodeURI(options.name),
     })
@@ -301,6 +316,7 @@
     }
     this.setData({
       num: Number(this.data.paperBookList.length) + Number(this.data.electronicBookList.length),
+      editDialog: false
     });
     if (this.data.bookDetail.id) {
       this.getBookInfo(this.data.bookDetail.id)
@@ -444,9 +460,11 @@
         freeEpubPage: [], //epub璇曡鐧惧垎姣�
         bookEditor: [], //鍥句功缂栬緫
         contactInformation: [], //鑱旂郴鏂瑰紡
+        IsTextbook: [] // 鏄惁涓烘暀鏉� 濡傛灉鏄暀鏉愮姝㈡樉绀烘墍鏈夎喘涔版寜閽�
       },
     };
     app.MG.store.getProductDetail(query).then(async (res) => {
+      res.datas.IsTextbook = res.datas.IsTextbook == '1' ? true : false
       this.getResourceCode(id, res.datas.rootCmsItemId)
       res.datas.bookEditor = res.datas.bookEditor ? res.datas.bookEditor : '-'
       res.datas.contactInformation = res.datas.contactInformation ? res.datas.contactInformation : '-'
@@ -771,7 +789,11 @@
       editDialog: true
     })
   },
-
+  closeEditDialog() {
+    this.setData({
+      editDialog: false
+    })
+  },
   // 鎴戣寤鸿
   suggestBtn() {
     // 妫�鏌ョ櫥褰曠姸鎬�
@@ -971,23 +993,27 @@
     // 杩斿洖鏇存柊鍚庣殑鏁扮粍  
     return array;
   },
-  // 閫掑綊鏍戠粨鏋勶紝濡傛灉鐖剁骇鏈夐攢鍞柟寮�(鏈夋晥鏈�)锛屽幓鎺夋墍鏈夊瓙闆嗙殑閿�鍞柟寮�
-  clearTreeSealmethod(clearSaleMethod, tree) {
+  // 閫掑綊鏍戠粨鏋�
+  handleSalmethodBtn(tree, data, parent) {
     for (let item of tree) {
-      const saleData = item.saleMethod &&
-        item.saleMethod.length ?
-        item.saleMethod.find((citem) => citem.SaleType == 'Normal') : null
-      if (
-        ((saleData && new Date(saleData.EndDate).getTime() >= new Date().getTime() && new Date(saleData.BeginDate).getTime() <= new Date().getTime()) ||
-          clearSaleMethod) && item.children && item.children.length
-      ) {
-        item.children.forEach((ditem) => (ditem.saleMethod = []))
+      // 鏄惁鏄剧ず鎸夐挳
+      item.isShowIcon = false;
+      if (item.sysType == 'CmsItem') {
+        // 鏌ユ壘鐩綍涓嬭祫婧愰攢鍞柟寮忥紝鐩綍涓嬭祫婧愭病鏈夐攢鍞柟寮�
+        if (item.saleMethod?.length == 0) {
+          // 鏌ョ湅鍏剁埗绾ф槸鍚︽湁閿�鍞柟寮�
+          if (parent.saleMethod?.length > 0) {
+            // 鐖剁骇鏄湁閿�鍞柟寮忕洿鎺ユ樉绀烘寜閽�
+            parent.isShowIcon = true
+          }
+        } else {
+          item.isShowIcon = true
+        }
+      } else {
+        if (item.children?.length > 0) {
+          this.handleSalmethodBtn(item.children, data, item)
+        }
       }
-      if (item.children && item.children.length)
-        this.clearTreeSealmethod(
-          saleData && new Date(saleData.EndDate).getTime() >= new Date().getTime() && new Date(saleData.BeginDate).getTime() <= new Date().getTime(),
-          item.children
-        )
     }
     return tree
   },
@@ -1028,6 +1054,9 @@
           loading: false,
         });
       }
+      this.setData({
+        cacheData: res.datas.cmsDatas[0].datas
+      })
       let list = []
       // 鍒ゆ柇浜戝涔犳湁鏃犻攢鍞柟寮忓拰鏈夋晥鏈�
       const cloundSaleMethod =
@@ -1081,15 +1110,19 @@
       }
       let result = [];
       if (type.refCode == "jsek_teachingResources") {
-        this.findChildIds(list, result);
+        if (this.data.activeId) {
+          result = this.findChildIdsByCode(res.datas.cmsDatas[0].datas)
+        } else {
+          this.findChildIds(list, result);
+        }
         this.setData({
           openTeachids: result,
           loading: false,
           teach: list,
         });
       } else if (type.refCode == "jsek_cloudLearning") {
-        // 浜戝涔犱笂鏃犻攢鍞柟寮忥紝璧扮洰褰� 璧勬簮 閿�鍞柟寮忓幓闄ゆ柟娉�
-        if (!flags) list = this.clearTreeSealmethod(false, list)
+        // 鎺у埗鎸夐挳鏄剧ず
+        list = this.handleSalmethodBtn(list, list, null)
         // 鍒ゆ柇棰嗗彇鏌ョ湅鏄惁鏄剧ず(浜戝涔狅紝鎴栬祫婧愮洰褰曪紝鏈夊敭浠蜂负0)
         let isshowDrawBtn = res.datas.cmsDatas[0].datas.some(
           (item) =>
@@ -1099,15 +1132,22 @@
           new Date(item.saleMethod.find((citem) => citem.SaleType == 'Normal').BeginDate).getTime() <= new Date().getTime()
         ) || (flags && cloundSaleMethod.Price == 0)
         // 鍒ゆ柇浜戝涔犲叏閮ㄨ喘涔版寜閽槸鍚︽樉绀�
-        let isShowBuyCloundMenu = flags && cloundSaleMethod.Price > 0 && !this.data.buyIdList.includes(cloundSaleMethod.Id)
-        // 鍒ゆ柇璧勬簮璐拱鎸夐挳鏄惁鏄剧ず
-        let isShowBuyCloundBtn = !flags && res.datas.cmsDatas[0].datas.some(citem => citem.saleMethod.length != 0)
+        let isShowBuyCloundMenu = flags && cloundSaleMethod.Price > 0 && !this.data.buyIdList.includes(cloundSaleMethod.Id) && !this.data.bookDetail.IsTextbook
+        // 鍒ゆ柇璧勬簮璐拱鎸夐挳鏄惁鏄剧ず 锛堜簯瀛︿範鏃犻攢鍞柟寮忥紝璧勬簮鍜岀洰褰曚腑鏈夐攢鍞柟寮忥紝涓斿敭浠峰ぇ浜�0锛�
+        let isShowBuyCloundBtn = !flags && res.datas.cmsDatas[0].datas.some(item => item.saleMethod.length &&
+          item.saleMethod.find((citem) => citem.SaleType == 'Normal').Price > 0 &&
+          new Date(item.saleMethod.find((citem) => citem.SaleType == 'Normal').EndDate).getTime() >= new Date().getTime() &&
+          new Date(item.saleMethod.find((citem) => citem.SaleType == 'Normal').BeginDate).getTime() <= new Date().getTime()) && !this.data.bookDetail.IsTextbook
         // 鍒ゆ柇璐墿杞︽寜閽拰閿佹寜閽槸鍚︽樉绀�
         this.handleTreeData(list).forEach(item => {
           item.isbuy = this.resourceIsBuy(item);
           item.isShopCar = this.isShoppingCart(item);
         })
-        this.findChildIds(list, result);
+        if (this.data.activeId) {
+          result = this.findChildIdsByCode(res.datas.cmsDatas[0].datas)
+        } else {
+          this.findChildIds(list, result);
+        }
         this.setData({
           isshowDrawBtn,
           isShowBuyCloundMenu,
@@ -1119,7 +1159,6 @@
           learnPath: type.productLinkPath
         });
       }
-      console.log('1', this.data.teach);
     })
   },
   //  鑾峰彇 浜戞祴璇�
@@ -1200,7 +1239,7 @@
               });
             }
             if (data.length > 0) {
-              console.log('data', data);
+              console.log('data01', data);
               let list = []
               that.getTreeList(data, list, query.cmsPath)
               list = that.ensureTreeConsistency(list)
@@ -1270,14 +1309,19 @@
       }
   },
 
+  // 鑾峰彇鐩綍鎵爜灞曞紑椤�
+  findChildIdsByCode(list) {
+    let arr = []
+    const data = list.find(item => item.id == this.data.activeId)
+    if (data) {
+      const ids = data.productLinkInfo.find(item => item.CmsItemId == data.id).LinkPath.split('\\')
+      arr = [data.id, ...ids].map(item => Number(item))
+    }
+    return arr
+  },
+
   // 鍥句功娣诲姞璐墿杞�
   addBookShopcCar() {
-    const token = wx.getStorageSync(app.config.tokenKey);
-    if (token) {
-      addFun()
-    } else {
-      this.logInFun(() => {})
-    }
     const addFun = async () => {
       if (!this.data.expire) {
         const shoppingCartGetId = [];
@@ -1321,6 +1365,13 @@
         });
       }
     }
+    const token = wx.getStorageSync(app.config.tokenKey);
+    if (token) {
+      addFun()
+    } else {
+      this.logInFun(() => {})
+    }
+
   },
 
   showSuccessToast() {
@@ -1673,28 +1724,55 @@
   },
   // 鍒ゆ柇璧勬簮鏄惁璐拱
   resourceIsBuy(data) {
-    if (data.saleMethod && data.saleMethod.length) {
-      const saleData = data.saleMethod.find((item) => item.SaleType == 'Normal')
-      if (saleData.State == 'Disable') return false
-      const isShow = this.data.buyIdList.some(
-        (item) => item == saleData.Id
-      );
-      // 宸茬粡璐拱
-      if (isShow || saleData.Price == 0) return false
-      // 鏈喘涔帮紝鏌ョ湅閿�鍞柟寮忔槸鍚﹁繃鏈�
-      if (!isShow) {
-        const flag = new Date(saleData.EndDate).getTime() >= new Date().getTime() &&
-          new Date(saleData.BeginDate).getTime() <= new Date().getTime()
-        if (flag) {
-          // 涓鸿繃鏈� 锛岄渶瑕佽喘涔�
-          return true
-        } else {
-          // 宸茶繃鏈� 鏃犻渶璐拱
-          return false
+    // if (data.saleMethod && data.saleMethod.length) {
+    //   const saleData = data.saleMethod.find((item) => item.SaleType == 'Normal')
+    //   if (saleData.State == 'Disable') return false
+    //   const isShow = this.data.buyIdList.some(
+    //     (item) => item == saleData.Id
+    //   );
+    //   // 宸茬粡璐拱
+    //   if (isShow || saleData.Price == 0) return false
+    //   // 鏈喘涔帮紝鏌ョ湅閿�鍞柟寮忔槸鍚﹁繃鏈�
+    //   if (!isShow) {
+    //     const flag = new Date(saleData.EndDate).getTime() >= new Date().getTime() &&
+    //       new Date(saleData.BeginDate).getTime() <= new Date().getTime()
+    //     if (flag) {
+    //       // 涓鸿繃鏈� 锛岄渶瑕佽喘涔�
+    //       return true
+    //     } else {
+    //       // 宸茶繃鏈� 鏃犻渶璐拱
+    //       return false
+    //     }
+    //   }
+    // } else {
+    //   return false;
+    // }
+    let linkData = data.productLinkPath.split("\\");
+    linkData.reverse()
+    let dataList = linkData.map(item => {
+      let data = this.data.cacheData.find(citem => citem.id == item);
+      if (data) return data;
+    })
+    let isBuy = 1;
+    for (let i = 0; i < dataList.length; i++) {
+      const dataItem = dataList[i];
+      if (dataItem) {
+        if (dataItem.saleMethod.length > 0) {
+          isBuy = 2;
+          if (this.data.bookDetail.purchasedSaleMethodIdList.indexOf(dataItem.saleMethod[0].Id) > -1 || dataItem.saleMethod[0].Price == 0) {
+            isBuy = 3;
+            break;
+          } else {
+            break;
+          }
         }
       }
+    }
+    if (isBuy == 2) {
+      // 鏈喘涔�
+      return false
     } else {
-      return false;
+      return true
     }
   },
   // 浜戝涔犺祫婧愭槸鍚︽樉绀洪攣鍥炬爣锛堟湭璐拱锛屼笖璧勬簮鍞环澶т簬闆讹級
@@ -1796,13 +1874,6 @@
   },
   // 浜戝涔犱竴閿鍙�
   getFreeResource() {
-    const child = this.selectComponent("#learn-resource");
-    const token = wx.getStorageSync(app.config.tokenKey);
-    if (!token) {
-      this.logInFun(() => {});
-    } else {
-      getFreeFun()
-    }
     const getFreeFun = async () => {
       // 棰嗗彇鏌ョ湅 锛屽厛鐪嬩簯瀛︿範涓婄殑  鍐嶇湅璧勬簮涓婄殑
       const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning')
@@ -1871,6 +1942,14 @@
         console.log(error);
       }
     }
+    const child = this.selectComponent("#learn-resource");
+    const token = wx.getStorageSync(app.config.tokenKey);
+    if (!token) {
+      this.logInFun(() => {});
+    } else {
+      getFreeFun()
+    }
+
   },
   // 浜戝涔犱竴閿喘涔�
   async allAddShoppiingCar() {
@@ -1924,12 +2003,6 @@
   },
   // 浜戝涔犲叏閮ㄨ喘涔�
   buyCloudLearnClass() {
-    const token = wx.getStorageSync(app.config.tokenKey);
-    if (token) {
-      buyClass()
-    } else {
-      this.logInFun(() => {})
-    }
     const buyClass = async () => {
       const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning')
       let query = {
@@ -1954,6 +2027,13 @@
         });
       }
     }
+    const token = wx.getStorageSync(app.config.tokenKey);
+    if (token) {
+      buyClass()
+    } else {
+      this.logInFun(() => {})
+    }
+
   },
   // 鍙樹负鎵�鏈塩heck   true
   findAndUpdateItemsByIds(tree, ids) {
@@ -2096,12 +2176,6 @@
   },
   // 璐拱缁勫嵎
   buyMock() {
-    const token = wx.getStorageSync(app.config.tokenKey);
-    if (token) {
-      buyMockFun()
-    } else {
-      this.logInFun(() => {})
-    }
     const buyMockFun = async () => {
       let res;
       if (!this.data.mockData.id)
@@ -2150,6 +2224,13 @@
         console.log(error);
       }
     }
+    const token = wx.getStorageSync(app.config.tokenKey);
+    if (token) {
+      buyMockFun()
+    } else {
+      this.logInFun(() => {})
+    }
+
   },
   // 璁板綍璐拱缁勫嵎鏃堕棿
   recordBuyMock() {
@@ -2251,12 +2332,6 @@
   },
   // 搴曢儴璐拱鎸夐挳
   buyBtn() {
-    const token = wx.getStorageSync(app.config.tokenKey);
-    if (token) {
-      buyFun()
-    } else {
-      this.logInFun(() => {})
-    }
     const buyFun = () => {
       if (this.data.tabValue == "brief" && !this.data.bookBuy) {
         this.buyBook();
@@ -2267,6 +2342,13 @@
         console.log(this.data.tabValue);
       }
     }
+    const token = wx.getStorageSync(app.config.tokenKey);
+    if (token) {
+      buyFun()
+    } else {
+      this.logInFun(() => {})
+    }
+
   },
 
   goRead(e) {
@@ -2421,12 +2503,6 @@
 
   //鐢宠鐢靛瓙鏍蜂功
   appplyElectronicBook() {
-    const token = wx.getStorageSync(app.config.tokenKey);
-    if (token) {
-      applyFun()
-    } else {
-      this.logInFun(() => {})
-    }
     const applyFun = () => {
       // 鍏堝垽鏂笅鏁欏笀璁よ瘉锛屾湭瀵瑰師鏈夐�昏緫淇敼
       let role = this.data.userInfo != null ? this.data.userInfo.role : null;
@@ -2534,15 +2610,16 @@
         });
       }
     }
-  },
-  //鐢宠绾歌川鏍蜂功
-  appplyPaperBook() {
     const token = wx.getStorageSync(app.config.tokenKey);
     if (token) {
       applyFun()
     } else {
       this.logInFun(() => {})
     }
+
+  },
+  //鐢宠绾歌川鏍蜂功
+  appplyPaperBook() {
     const applyFun = () => {
       let role = this.data.userInfo != null ? this.data.userInfo.role : null;
       if (role && role == "Teacher") {} else {
@@ -2630,6 +2707,13 @@
         });
       }
     }
+    const token = wx.getStorageSync(app.config.tokenKey);
+    if (token) {
+      applyFun()
+    } else {
+      this.logInFun(() => {})
+    }
+
   },
   //  娣诲姞鏍蜂功
   addBookFun(item, type) {
@@ -2673,9 +2757,14 @@
 
   //鍘绘牱涔︾敵璇峰崟
   goApply() {
-    wx.navigateTo({
-      url: "/packageDomain/pages/sampleBookList/applicationForm/index",
-    });
+    const token = wx.getStorageSync(app.config.tokenKey);
+    if (token) {
+      wx.navigateTo({
+        url: "/packageDomain/pages/sampleBookList/applicationForm/index",
+      });
+    } else {
+      this.logInFun(() => {})
+    }
   },
   handleTree() {
     // const child = this.selectComponent('#teach-tree')
@@ -2756,14 +2845,6 @@
     return childrenList
   },
   uploadFile(e) {
-    const token = wx.getStorageSync(app.config.tokenKey);
-    if (token) {
-      uploadFun()
-    } else {
-      this.logInFun(() => {
-        uploadFun()
-      })
-    }
     const uploadFun = () => {
       const userInfo = JSON.parse(wx.getStorageSync(app.config.userInfoKey))
       if (userInfo.role != 'Teacher') return wx.showToast({
@@ -2775,6 +2856,15 @@
         isShowUp: true
       });
     }
+    const token = wx.getStorageSync(app.config.tokenKey);
+    if (token) {
+      uploadFun()
+    } else {
+      this.logInFun(() => {
+        uploadFun()
+      })
+    }
+
   },
   closeDialog() {
     this.setData({
@@ -3016,6 +3106,17 @@
       cloundMenuIsBuy: flag
     })
   },
+
+  // 鏄剧ずISBN
+  showISBN() {
+    wx.showModal({
+      title: '',
+      content: this.data.bookDetail.isbn,
+      showCancel: false,
+      confirmText: '鍏抽棴',
+      success: (res) => {}
+    })
+  },
   /**
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
    */

--
Gitblit v1.9.1