yiming
2024-04-16 cb15c57d0ff984f5a100cf25d560fb0a69c00984
packageBookService/pages/bookServices/detail/buyResource/index.js
@@ -16,7 +16,7 @@
    methodId: [],
    paymentPage: false,
    superior: false,
    checkAllState: false,
    checkAllState: true,
  },
  /**
@@ -33,7 +33,6 @@
      bookId: options.bookId,
    });
    this.getResourceClass();
    console.log(options);
    this.getResourceData({
      productLinkPath: options.productLinkPath,
      refCode: options.refCode,
@@ -148,7 +147,6 @@
                loading: false,
                openLearnids: result,
              });
              console.log("教学资源", list);
            }
          } else {
            // 无数据
@@ -380,25 +378,15 @@
    let item = [];
    let selectAllId = [];
    const child = this.selectComponent("#tree");
    console.log(
      child.data.superiorPurchaseSaleMethodId,
      "superiorPurchaseSaleMethodId"
    );
    console.log(child.data.sonPurchaseSaleMethodId, "child.data");
    // console.log(child.data.selectAll, 'selectAll');
    item = child.data.superiorPurchaseSaleMethodId;
    const sonItem = child.data.sonPurchaseSaleMethodId;
    let selectAll = child.data.selectAll;
    if (selectAll) {
      // console.log(selectAll);
      selectAll.forEach((item) => {
        if (item.saleMethod != 0) {
          // console.log(item, 'item');
          selectAllId.push(item.saleMethod[0].Id);
        }
      });
      console.log(selectAllId);
      app.MG.store
        .initOrder({
          requests: selectAllId.map((id) => ({
@@ -409,8 +397,7 @@
        .then((res) => {
          if (res) {
            wx.navigateTo({
              url:
                "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
              url: "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
            });
            selectAllId = [];
            child.setData({
@@ -420,15 +407,12 @@
        });
    }
    if (item) {
      console.log(item, "sadsdasd");
      // 拿到id
      item.forEach((items) => {
        if (items.saleMethod != 0) {
          saleMethodIds.push(items.saleMethod[0].Id);
        }
      });
      console.log(saleMethodIds, "saleMethodIds");
      app.MG.store
        .initOrder({
          requests: saleMethodIds.map((id) => ({
@@ -439,8 +423,7 @@
        .then((res) => {
          if (res) {
            wx.navigateTo({
              url:
                "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
              url: "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
            });
            child.setData({
@@ -460,8 +443,7 @@
        .then((res) => {
          if (res) {
            wx.navigateTo({
              url:
                "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
              url: "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber,
            });
            this.setData({
              paymentPage: true,
@@ -473,4 +455,58 @@
        });
    }
  },
});
  // 章节勾选方法
  findAndUpdateItemsByIds(tree, ids, state) {
    function findAndUpdate(node) {
      if (ids.includes(node.id)) {
        // console.log(node, 'node');
        node.checked = state; // 将目标项的 check 属性设置为 true
      }
      if (node.children && node.children.length > 0) {
        for (let child of node.children) {
          findAndUpdate(child); // 递归处理子节点
        }
      }
    }
    for (let node of tree) {
      findAndUpdate(node); // 对每个顶层节点执行查找和更新操作
    }
    // console.log(tree, 'tree345');
    return tree; // 返回修改后的完整数组
  },
  // 单个勾选方法
  checkResoucrceInfo(tree, id) {
    function findAndUpdate(node) {
      if (node.sysType == "CmsFolder" && node.children.length > 0) {
        for (let index = 0; index < node.children.length; index++) {
          const element = node.children[index];
          findAndUpdate(element);
        }
      } else if (id == node.id && node.sysType == "CmsItem") {
        node.checked = !node.checked; // 将目标项的 check 属性设置为 true
      }
    }
    for (let node of tree) {
      findAndUpdate(node); // 对每个顶层节点执行查找和更新操作
    }
    return tree; // 返回修改后的完整数组
  },
  // 章节勾选事件
  changeListChecked(e) {
    const ids = e.detail.ids
    const state = e.detail.flag
    const updated = this.findAndUpdateItemsByIds(this.data.learn, ids, state)
    this.setData({
      learn: updated
    })
  },
  // 单个勾选事件
  changeResourceChecked(e) {
    const id = e.detail.id
    const updated = this.checkResoucrceInfo(this.data.learn, id)
    this.setData({
      learn: updated
    })
  }
});