litian
2024-03-28 7eab4acb4bb2060970f81840e5d2b72f259b07cb
packageBookService/pages/bookServices/detail/buyResource/index.js
@@ -14,12 +14,16 @@
    loading: false,
    shoppingList: [],
    shoppingCartGetId: [],
    methodId: [],
    paymentPage: false,
    superior: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
@@ -365,5 +369,72 @@
  checkAll() {
    const child = this.selectComponent('#tree')
    child.checkAll()
  }
  },
  //购买按钮
  batchPurchase() {
    let saleMethodIds = []
    let requests = []
    let item = []
    const child = this.selectComponent('#tree')
    console.log(child.data.superiorPurchaseSaleMethodId, 'superiorPurchaseSaleMethodId');
    console.log(child.data.sonPurchaseSaleMethodId, 'child.data');
    item = child.data.superiorPurchaseSaleMethodId
    const sonItem = child.data.sonPurchaseSaleMethodId
    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 => ({
          saleMethodId: id,
          count: 1,
        })),
      }).then(res => {
        if (res) {
          wx.navigateTo({
            url: '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber,
          })
          this.setData({
            superior: true
          })
        }
      })
    }
    if (item.length == 0 && sonItem) {
      app.MG.store.initOrder({
        requests: sonItem.map(id => ({
          saleMethodId: id,
          count: 1,
        })),
      }).then(res => {
        if (res) {
          wx.navigateTo({
            url: '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber,
          })
          this.setData({
            paymentPage: true
          })
        }
      })
    }
  },
})