yiming
2024-04-03 f0229b7c6801f6429dec75e208192b61053b8c7d
packageBookService/pages/bookServices/detail/components/tree/index.js
@@ -50,7 +50,9 @@
    activeValues: [1, 2],
    webpageSrc: '',
    cloudShoppingCart: [],
    selectAll: []
    selectAll: [],
    shoppingCart: true,
    stop: false,
  },
  ready() {
    this.setData({
@@ -78,7 +80,6 @@
  },
  methods: {
    handleList(tree) {
      for (let index = 0; index < tree.length; index++) {
        const item = tree[index];
@@ -141,10 +142,15 @@
          }
        })
      } else {
        if (this.properties.isShowCheck) return true
        const item = e.currentTarget.dataset.item
        const parent = e.currentTarget.dataset.parent
        let url
        if (this.properties.isShowCheck && this.resourceIsBuy(item)) {
          return wx.showToast({
            icon: 'error',
            title: "请先购买资源"
          })
        }
        if (item.selectType == 'video' || item.learnSelectType == 'video') {
          url = '/packageDomain/pages/resourceDetails/myVideo/index'
        } else if (item.selectType == 'audio' || item.learnSelectType == 'audio') {
@@ -240,7 +246,6 @@
        }
      }
      tree.forEach(node => {
        flatten(node);
      });
      // console.log(result, 'result');
@@ -248,11 +253,11 @@
    },
    // 变为true
    findAndUpdateItemsByIds(tree, ids) {
    findAndUpdateItemsByIds(tree, ids, state) {
      function findAndUpdate(node) {
        if (ids.includes(node.id)) {
          // console.log(node, 'node');
          node.checked = !node.checked // 将目标项的 check 属性设置为 true
          node.checked = state // 将目标项的 check 属性设置为 true
        }
        if (node.children && node.children.length > 0) {
          for (let child of node.children) {
@@ -260,9 +265,7 @@
          }
        }
      }
      for (let node of tree) {
        findAndUpdate(node); // 对每个顶层节点执行查找和更新操作
      }
      // console.log(tree, 'tree345');
@@ -285,7 +288,7 @@
      }
      return tree; // 返回修改后的完整数组
    },
    // 全选
    checkAll() {
      const ids = []
      const list = []
@@ -297,21 +300,16 @@
      })
      list.forEach(item => {
        ids.push(item.id)
        checked = item.checked
      })
      const updataList = this.findAndUpdateItemsByIds(this.properties.treeList, ids);
      const flag = list.findIndex(item => item.checked == false) > -1 ? true : false
      const updataList = this.findAndUpdateItemsByIds(this.properties.treeList, ids, flag);
      console.log(checked, 'list');
      if (!checked) {
        this.setData({
          selectAll: list
        })
      }
      this.setData({
        treeList: updataList
      })
@@ -319,6 +317,8 @@
    // 章节勾选
    checkResourceTitle(e) {
      const flag = e.detail.checked
      debugger
      // 这个时候checked的值是fals
      let checkResourceTitleList = []
      const item = e.currentTarget.dataset.item
@@ -329,20 +329,16 @@
        ids.push(item.id)
      })
      // console.log(list, 'list789');
      const updatedTreeList = this.findAndUpdateItemsByIds(this.properties.treeList, ids);
      const updatedTreeList = this.findAndUpdateItemsByIds(this.properties.treeList, ids, flag);
      this.setData({
        treeList: updatedTreeList // 更新 treeList 数据
      });
      console.log(list, 'list.checked');
      if (!list.checked) {
        this.setData({
          superiorPurchaseSaleMethodId: list
        })
      }
      // console.log(this.data.superiorPurchaseSaleMethodId, 'superiorPurchaseSaleMethodId');
      list.forEach(items => {
        console.log(items.checked, 'itesasd');
@@ -352,7 +348,9 @@
          })
        }
      })
      this.setData({
        openIds: this.data.openIds
      })
    },
    // 子项勾选
    checkResource(e) {
@@ -402,6 +400,14 @@
      })
      if (shoppingCartGetId.includes(saleMethodId)) {
        console.log(111);
        wx.showToast({
          icon: 'error',
          title: '已添加',
        })
        this.setData({
          shoppingCart: false
        })
      } else {
        let query = {
          requests: [{
@@ -412,15 +418,14 @@
        }
        const addRes = await app.MG.store.addShoppingCart(query)
        console.log(addRes, 'addRes');
        wx.showToast({
          icon: 'success',
          title: '添加成功',
        })
      }
    },
  },
  onCheckAllChange(e) {
    // debugger
    // console.log('checkbox', e.detail.value);
    // this.setData({
    //   checkAllValues: event.detail,
    // });
  }
  catchtap() {}
})