闫增涛
2024-04-01 aa2c08b3be23a01d44205b2c19d21a2bf53f944f
packageBookService/pages/bookServices/detail/components/tree/index.js
@@ -1,5 +1,7 @@
import Message from 'tdesign-miniprogram/message/message';
const util = require('./components/util') // 引入封装过的加载提示
import {
  loginInfo
} from '../../../../../../assets/js/login'
const app = getApp()
Component({
  // checked: false,
@@ -127,71 +129,75 @@
    },
    // 跳转音视频播放器
    goPlayer(e) {
      if (this.properties.isShowCheck) return true
      const item = e.currentTarget.dataset.item
      const parent = e.currentTarget.dataset.parent
      let url
      if (item.selectType == 'video' || item.learnSelectType == 'video') {
        url = '/packageDomain/pages/resourceDetails/myVideo/index'
      } else if (item.selectType == 'audio' || item.learnSelectType == 'audio') {
        url = '/packageDomain/pages/resourceDetails/myAudio/index'
      } else if (item.selectType == 'picture' || item.selectType == 'zip') {
        url = '/packageDomain/pages/resourceDetails/document/index'
      }
      if (this.properties.tab == 'jsek_cloudLearning' && this.resourceIsBuy(item)) {
        return wx.showToast({
          icon: 'error',
          title: '请先购买该资源',
        })
      }
      wx.navigateTo({
        url: `${url}?productLinkPath=${item.productLinkPath}&parentProductLinkPath=${parent.productLinkPath}&parentName=${parent.name}&activeId=${item.id}&bookId=${this.properties.bookInfo.id}&bookName=${this.properties.bookInfo.name}&cmsId=${this.properties.bookInfo.rootCmsItemId}`,
      })
      if (item.selectType == 'document' || item.selectType == 'pdf') {
        const fileLink = app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file
        console.log(fileLink, 'fileLink');
        //提示加载中
        util.showLoading()
        // 单次下载允许的最大文件为 200MB
        wx.downloadFile({
          url: fileLink, // 地址已打码,自己换个其他的地址("https://www.xxxxx.com/file/测试通知.pdf")
          success: function (res) {
            console.log(res, "wx.downloadFile success res")
            if (res.statusCode != 200) {
              util.hideLoadingWithErrorTips()
              return false
            }
            var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
            wx.openDocument({
              filePath: Path,
              showMenu: true,
              success: function (res) {
                console.log('打开成功');
                util.hideLoading()
              }
            })
          },
          fail: function (err) {
            console.log(err, "wx.downloadFile fail err");
            util.hideLoadingWithErrorTips()
      // 检查登录状态
      const token = wx.getStorageSync(app.config.tokenKey)
      if (!token) {
        loginInfo(app, (data) => {
          // 如果不是第一次登录,会执行回调
          if (data) {
            // 登录成功,自动记录token和用户信息,并返回true
          } else {
            // 出现错误,返回false
          }
        })
      }
      if (item.selectType == 'webpage') {
        console.log(11);
        this.setData({
          webpageSrc: item.jsek_link
      } else {
        if (this.properties.isShowCheck) return true
        const item = e.currentTarget.dataset.item
        const parent = e.currentTarget.dataset.parent
        let url
        if (item.selectType == 'video' || item.learnSelectType == 'video') {
          url = '/packageDomain/pages/resourceDetails/myVideo/index'
        } else if (item.selectType == 'audio' || item.learnSelectType == 'audio') {
          url = '/packageDomain/pages/resourceDetails/myAudio/index'
        } else if (item.selectType == 'picture' || item.selectType == 'zip') {
          url = '/packageDomain/pages/resourceDetails/document/index'
        }
        if (this.properties.tab == 'jsek_cloudLearning' && this.resourceIsBuy(item)) {
          return wx.showToast({
            icon: 'error',
            title: '请先购买该资源',
          })
        }
        wx.navigateTo({
          url: `${url}?productLinkPath=${item.productLinkPath}&parentProductLinkPath=${parent.productLinkPath}&parentName=${parent.name}&activeId=${item.id}&bookId=${this.properties.bookInfo.id}&bookName=${this.properties.bookInfo.name}&cmsId=${this.properties.bookInfo.rootCmsItemId}`,
        })
        console.log(this.data.webpageSrc, 'webpageSrc');
        if (item.selectType == 'document' || item.selectType == 'pdf') {
          const fileLink = app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file
          console.log(fileLink, 'fileLink');
          //提示加载中
          util.showLoading()
          // 单次下载允许的最大文件为 200MB
          wx.downloadFile({
            url: fileLink, // 地址已打码,自己换个其他的地址("https://www.xxxxx.com/file/测试通知.pdf")
            success: function (res) {
              console.log(res, "wx.downloadFile success res")
              if (res.statusCode != 200) {
                util.hideLoadingWithErrorTips()
                return false
              }
              var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
              wx.openDocument({
                filePath: Path,
                showMenu: true,
                success: function (res) {
                  console.log('打开成功');
                  util.hideLoading()
                }
              })
            },
            fail: function (err) {
              console.log(err, "wx.downloadFile fail err");
              util.hideLoadingWithErrorTips()
            }
          })
        }
        if (item.selectType == 'webpage') {
          this.setData({
            webpageSrc: item.jsek_link
          })
          console.log(this.data.webpageSrc, 'webpageSrc');
        }
      }
    },
    // 拿到所有项
    getAllChildren(id) {
@@ -346,7 +352,6 @@
          })
        }
      })
      // this.onCloudShoppingCart()
    },
    // 子项勾选
    checkResource(e) {
@@ -378,34 +383,47 @@
      })
    },
    // 加入购物车
    async onCloudShoppingCart() {
      let requests = []
      const item = this.data.cloudShoppingCart
      console.log(item, 'item');
      item.forEach((items) => {
        if (items.saleMethod.length) {
          requests.push({
            saleMethodId: items.saleMethod[0].Id,
            count: 1
          })
        }
      })
    async onCloudShoppingCart(e) {
      let shoppingCartGetId = []
      const saleMethodId = e.currentTarget.dataset.item.saleMethod[0].Id
      console.log(saleMethodId);
      let query = {
        remarks: '云学习',
        requests
        start: 0,
        size: 999,
        filterList: [],
        searchList: []
      }
      // 查询订单
      let initOrderRes = await app.MG.store.initOrder(query)
      let parameter = {
        orderNum: initOrderRes.orderNumber
      const res = await app.MG.store.getShoppingCartProductList(query)
      res.datas.forEach(item => {
        shoppingCartGetId.push(item.saleMethod.id)
      })
      if (shoppingCartGetId.includes(saleMethodId)) {
        console.log(111);
        wx.showToast({
          icon: 'error',
          title: '已添加',
        })
      } else {
        let query = {
          requests: [{
            saleMethodId: saleMethodId,
            storeEventId: null,
            // agentCode: '电子书'
          }]
        }
        const addRes = await app.MG.store.addShoppingCart(query)
        console.log(addRes, 'addRes');
        wx.showToast({
          icon: 'success',
          title: '添加成功',
        })
      }
      const confirmOrderRes = await app.MG.store.confirmOrder(parameter)
      // if (confirmOrderRes.orderNumber) {
      //   wx.navigateTo({
      //     url: `/pages/cart/paymentPage/index?orderNumber=${confirmOrderRes.orderNumber}`,
      //   })
      //   requests = []
      // }
    },
  },
  onCheckAllChange(e) {
@@ -414,5 +432,5 @@
    // this.setData({
    //   checkAllValues: event.detail,
    // });
  }
  },
})