From 810be121d0ad95211ad13ebed9fb4e834c0c2f72 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期一, 25 三月 2024 11:08:32 +0800
Subject: [PATCH] 添加资源购买功能页面

---
 packageBookService/pages/bookServices/detail/buyResource/index.js |  210 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 207 insertions(+), 3 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/buyResource/index.js b/packageBookService/pages/bookServices/detail/buyResource/index.js
index b15b4de..dc40f65 100644
--- a/packageBookService/pages/bookServices/detail/buyResource/index.js
+++ b/packageBookService/pages/bookServices/detail/buyResource/index.js
@@ -1,18 +1,34 @@
 // packageBookService/pages/bookServices/detail/buyResource/index.js
+const app = getApp()
 Page({
 
   /**
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
-
+    barHeight: '',
+    navBarHeight: '',
+    learn: [],
+    openLearnids: [],
+    bookId: '',
+    loading: false,
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
-
+    const systInfo = wx.getSystemInfoSync();
+    const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
+    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
+    this.setData({
+      barHeight: systInfo.statusBarHeight,
+      navBarHeight: navBarHeight,
+      bookId: options.bookId
+    });
+    this.getResourceClass()
+    console.log(options);
+    this.getResourceData({ productLinkPath: options.productLinkPath, refCode: options.refCode })
   },
 
   /**
@@ -62,5 +78,193 @@
    */
   onShareAppMessage() {
 
-  }
+  },
+  goBack() {
+    wx.navigateBack()
+  },
+  //  鑾峰彇鏁欏璧勬簮  浜戝涔�  浜戞祴璇�
+  getResourceData(type) {
+    this.setData({
+      loading: true,
+      noResources: false
+    })
+    let query = {
+      path: '*',
+      queryType: '*',
+      productId: this.data.bookId,
+      cmsPath: type.productLinkPath,
+      itemFields: {
+        SysType: 'CmsFolder',
+        // 璧勬簮绫诲瀷锛岃瘯璇绘枃浠讹紝鏄惁鍏佽涓嬭浇绛夊弬鏁�
+        selectType: [],
+        freeFile: [],
+        file: [],
+        resourcesClassification: [],
+        isDownload: [],
+        jsek_resourceBrief: [],
+        jsek_link: [],
+        jsek_questionBank: []
+      },
+      pading: {
+        start: 0,
+        size: 999
+      },
+    }
+    app.MG.store
+      .getProductDetail(query)
+      .then(async (res) => {
+        if (!res.datas.cmsDatas[0].datas.length) {
+          return this.setData({
+            noResources: true,
+            loading: false
+          })
+        }
+        //鏁欏璧勬簮 浜戝涔�
+        if (type.refCode == 'jsek_teachingResources' || type.refCode == 'jsek_cloudLearning') {
+          if (res.datas.cmsDatas[0].datas.length > 0) {
+            res.datas.cmsDatas[0].datas.forEach(item => {
+              item.checked = false
+            })
+            const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
+            if (type.refCode == 'jsek_teachingResources') {
+              this.setData({
+                teach: list,
+                loading: false
+              })
+              this.findChildIds(this.data.teach, this.data.openTeachids = [])
+            } else if (type.refCode == 'jsek_cloudLearning') {
+              res.datas.cmsDatas[0].datas.forEach(item => {
+                item.checked = false
+              })
+              const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
+              this.setData({
+                learn: list,
+                loading: false
+              })
+              this.findChildIds(this.data.learn, this.data.openLearnids = [])
+            }
+          } else {
+            // 鏃犳暟鎹�
+          }
+        } else if (type.refCode == 'jsek_questionBank') {
+          // const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
+          this.setData({
+            test: res.datas.cmsDatas[0].datas,
+            loading: false
+          })
+        } else {
+          console.log('鍏朵粬');
+        }
+      })
+      .catch((e) => {
+        console.log(e)
+      })
+  },
+  // 鑾峰彇tag涓嬫墍鏈夎祫婧�
+  async getAllResource(data) {
+    if (!data.length) return false
+    for (let i = 0; i < data.length; i++) {
+      let item = data[i]
+      if (item.sysType == 'CmsFolder' && item.childrenCount > 0) {
+        item.children = []
+        item.children = await this.getFolderItem(item.productLinkPath)
+        await this.getAllResource(item.children)
+      }
+    }
+    return data
+  },
+  // 鑾峰彇璧勬簮鎺ュ彛
+  async getFolderItem(path) {
+    let query = {
+      path: '*',
+      queryType: '*',
+      productId: this.data.bookId,
+      cmsPath: path,
+      itemFields: {
+        SysType: 'CmsFolder',
+        // 璧勬簮绫诲瀷锛岃瘯璇绘枃浠讹紝鏄惁鍏佽涓嬭浇绛夊弬鏁�
+        selectType: [],
+        freeFile: [],
+        file: [],
+        protectedFile: [],
+        resourcesClassification: [],
+        isDownload: [],
+        jsek_resourceBrief: [],
+        jsek_link: [],
+        accessType: []
+      },
+      pading: {
+        start: 0,
+        size: 999
+      },
+    }
+    const data = await app.MG.store.getProductDetail(query)
+    data.datas.cmsDatas[0].datas.forEach((item) => {
+      this.data.resourceClassList.forEach((type) => {
+        if (type.value == item.resourcesClassification) item.resourceClass = type.name
+      })
+      // 缃戦〉 涓嶈兘涓嬭浇 绉佹湁鏂囦欢
+      if (item.sysType == 'CmsItem') {
+        if (item.selectType == 'webpage') {
+          item.disabled = true
+        } else {
+          if (item.isDownload != 1) {
+            item.disabled = true
+          }
+        }
+        if (item.file) {
+          if (item.fileMap[item.file].protectType == 'Private') item.disabled = true
+        }
+      }
+    })
+    data.datas.cmsDatas[0].datas.forEach(item => {
+      if (this.data.tabValue == 'jsek_teachingResources') {
+        item.checked = false
+      } else if (this.data.tabValue == 'jsek_cloudLearning') {
+        item.checked = false
+        item.isbuy = this.resourceIsBuy(item)
+        item.isShopCar = this.isShoppingCart(item)
+      }
+    })
+    return data.datas.cmsDatas[0].datas
+  },
+  // 鑾峰彇灞曞紑椤�
+  findChildIds(data, result) {
+    let index = 0
+    for (let i = 0; i < data.length; i++) {
+      if (index < 3) {
+        const item = data[i]
+        if (item.childrenFolderCount > 0) {
+          result.push(item.id)
+          for (let j = 0; j < item.children.length; j++) {
+            if (index < 3) {
+              const childrenItme = item.children[j]
+              if (item.childrenCount > 0) {
+                result.push(childrenItme.id)
+                index += 1
+              }
+            } else {
+              break
+            }
+          }
+        } else if (item.childrenCount > 0) {
+          result.push(item.id)
+          index += 1
+        }
+      } else {
+        break
+      }
+    }
+  },
+  // 鑾峰彇璧勬簮鎵�灞炲垎绫�
+  getResourceClass() {
+    let query = {
+      refCodes: ['resourcesClassification']
+    }
+    app.MG.store.getProductTypeField(query).then((res) => {
+      this.setData({
+        resourceClassList: JSON.parse(res[0].config).option
+      })
+    })
+  },
 })
\ No newline at end of file

--
Gitblit v1.9.1