闫增涛
2024-03-26 d61a31af1b8a220af669c818f11b6a13c1fb8dba
packageBookService/pages/bookServices/detail/buyResource/index.js
@@ -12,6 +12,8 @@
    openLearnids: [],
    bookId: '',
    loading: false,
    shoppingList: [],
    shoppingCartGetId: [],
  },
  /**
@@ -29,6 +31,8 @@
    this.getResourceClass()
    console.log(options);
    this.getResourceData({ productLinkPath: options.productLinkPath, refCode: options.refCode })
    this.getShoppingCartProductGet()
    this.getBookInfo(options.bookId)
  },
  /**
@@ -123,7 +127,8 @@
        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
              item.checked = false,
                item.checkAll = true
            })
            const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
            if (type.refCode == 'jsek_teachingResources') {
@@ -133,15 +138,17 @@
              })
              this.findChildIds(this.data.teach, this.data.openTeachids = [])
            } else if (type.refCode == 'jsek_cloudLearning') {
              const result = []
              res.datas.cmsDatas[0].datas.forEach(item => {
                item.checked = false
              })
              const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
              this.findChildIds(list, result)
              this.setData({
                learn: list,
                loading: false
                loading: false,
                openLearnids: result
              })
              this.findChildIds(this.data.learn, this.data.openLearnids = [])
              console.log('教学资源', list);
            }
          } else {
            // 无数据
@@ -270,15 +277,52 @@
    });
  },
    // 判断资源是否购买
    resourceIsBuy(data) {
      if (data.saleMethod && data.saleMethod.length) {
        const isSHow = this.data.buyIdList.some((item) => item == data.saleMethod[0].Id)
        return !isSHow
      } else {
  // 获取已购买商品
  getShoppingCartProductGet() {
    let query = {
      start: 0,
      size: 999,
      filterList: [],
      searchList: []
    }
    app.MG.store.getShoppingCartProductList(query).then((res) => {
      const list = []
      res.datas.forEach((item) => {
        list.push(item.saleMethod.id)
      })
      this.setData({
        shoppingList: res.datas,
        shoppingCartGetId: list
      })
    })
  },
  // 判断资源是否购买
  resourceIsBuy(data) {
    if (data.saleMethod && data.saleMethod.length) {
      const isSHow = this.data.buyIdList.some((item) => item == data.saleMethod[0].Id)
      return !isSHow
    } else {
      return false
    }
  },
  // 判断资源加入购物车按钮是否显示
  isShoppingCart(data) {
    if (data.saleMethod && data.saleMethod.length) {
      if (data.saleMethod[0].Price <= 0) return false
      // 再判断是否购买
      const isBuy = this.data.buyIdList.some((item) => item == data.saleMethod[0].Id)
      if (isBuy) {
        // 购买了
        return false
      } else {
        // 判断是否加入购物车
        const isSHow = this.data.shoppingCartGetId.some((item) => item == data.saleMethod[0].Id)
        return !isSHow
      }
    },
    } else {
      return false
    }
  },
  // 获取展开项
  findChildIds(data, result) {
    let index = 0
@@ -318,4 +362,8 @@
      })
    })
  },
  checkAll() {
    const child = this.selectComponent('#tree')
    child.checkAll()
  }
})