闫增涛
2024-10-24 e7b28656801d4ff8284e0c43deddf0a6953b08ae
packageBookService/pages/bookServices/detail/components/tree/index.js
@@ -53,6 +53,12 @@
    },
    cloundMenuIsBuy: {
      type: Boolean
    },
    learnMenu: {
      type: Object
    },
    isCloundHaveSaleMethod: {
      type: Boolean
    }
  },
  data: {
@@ -66,7 +72,6 @@
    purchaseList: []
  },
  ready() {},
  onLoad() {},
  observers: {
    treeList: function (newValue) {
@@ -160,6 +165,7 @@
    // 跳转音视频播放器
    goPlayer(e) {
      // 检查登录状态
      console.log(e.currentTarget.dataset.item)
      const token = wx.getStorageSync(app.config.tokenKey);
      if (!token) return false
      const item = e.currentTarget.dataset.item;
@@ -189,17 +195,17 @@
        })
      }
      if (item.selectType == 'zip') {
        if (this.properties.applyState == 'Normal') {
          return wx.showToast({
            icon: 'error',
            title: '请前往PC端下载',
          })
        } else {
          return wx.showToast({
            icon: 'error',
            title: '请先申请下载',
          })
        }
        // if (this.properties.applyState == 'Normal') {
        return wx.showToast({
          icon: 'error',
          title: '请前往PC端下载',
        })
        // } else {
        //   return wx.showToast({
        //     icon: 'error',
        //     title: '请先申请下载',
        //   })
        // }
      }
      if (this.properties.tab == "jsek_teachingResources" && (item.file || item.freeFile)) {
        let file = item.fileMap[item.file] ? item.fileMap[item.file] : item.fileMap[item.freeFile]
@@ -211,37 +217,29 @@
        }
      }
      if (this.properties.tab == "jsek_cloudLearning") {
        // 判断父级或自身是否购买
        var myEventOption = {
          bubbles: true,
          composed: true,
        };
        // 出发判断云学习是否购买判断
        this.triggerEvent("getCloundIsBuy", {}, myEventOption)
        if (!this.properties.cloundMenuIsBuy) {
          // 云学习未购买,查找以购买的目录和资源本身
          const learn = this.handleTreeData(this.properties.treeList).filter(
        // 1.找出所有父级目录和本身(有销售方式) 和 云学习本身(有销售方式) 放到一个数组  为空则暂未开放销售
        let learn = []
        if (this.properties.isCloundHaveSaleMethod) {
          // 1.1 云学习有销售方式,加入父级数组
          learn.push(this.properties.learnMenu)
        } else {
          // 1.2 云学习无销售方式,将父级目录和本身加入数组
          learn = this.handleTreeData(this.properties.learnList).filter(
            (citem) => citem.saleMethod &&
            citem.saleMethod.find((ditem) => ditem.SaleType == 'Normal') &&
            new Date(citem.saleMethod.find((ditem) => ditem.SaleType == 'Normal').EndDate).getTime() >= new Date().getTime() &&
            new Date(citem.saleMethod.find((ditem) => ditem.SaleType == 'Normal').BeginDate).getTime() <= new Date().getTime() &&
            item.productLinkPath.includes(citem.productLinkPath)
          )
          // 资源和父级目录都无销售方式
          // if (!learn.length) return wx.showToast({
          //   icon: 'error',
          //   title: '暂未开售',
          // })
          const buyList = learn.filter((citem) => this.properties.buyIds.includes(citem.saleMethod.find((ditem) => ditem.SaleType == 'Normal').Id))
          if (!buyList.length && learn.length) {
            // 资源和本身都未购买 且 父级或本身有销售方式
            const itemSaleMethod = item.saleMethod && item.saleMethod.length ? item.saleMethod.find(citem => citem.SaleType == 'Normal') : undefined
            return wx.showToast({
              icon: 'error',
              title: itemSaleMethod && itemSaleMethod.Price == 0 ? '请先领取资源' : '请先购买资源',
            })
          }
        }
        // 2.找出这个数组里已购买的 形成新数组     为空则未购买
        let buyList = []
        if (learn.length) buyList = learn.filter((item) => this.properties.buyIds.includes(item.saleMethod.find((citem) => citem.SaleType == 'Normal').Id))
        // 有父级(包含销售方式),且未购买
        if (learn.length && !buyList.length) return wx.showToast({
          icon: 'error',
          title: '请先购买该资源',
        })
      }
      let url;
      if (item.selectType == "video" || item.learnSelectType == "video") {
@@ -253,7 +251,7 @@
      ) {
        url = "/packageDomain/pages/resourceDetails/myAudio/index";
      }
      if (item.selectType == "picture" || item.selectType == 'document') {
      if (item.selectType == "picture" || item.selectType == 'document' || item.selectType == 'pdf') {
        url = "/packageDomain/pages/resourceDetails/document/index";
      }
      wx.navigateTo({
@@ -412,7 +410,6 @@
      this.setData({
        openIds: this.data.openIds,
      });
      wx.hideLoading()
    },
    // 子项勾选
    checkResource(e) {
@@ -483,7 +480,6 @@
          this.triggerEvent("changeListChecked", myEventDetail, myEventOption);
        }
      }
      wx.hideLoading()
    },
    // 加入购物车
    async onCloudShoppingCart(e) {