闫增涛
2025-03-28 b97bfcb85b2ded3b1f380e9a98b54b836faabba5
pages/digitalCourses/digitalCoursesDetails/index.js
@@ -13,6 +13,7 @@
  loginInfo
} from '../../../assets/js/login';
import wxbarcode from 'wxbarcode'
Page({
  /**
@@ -166,24 +167,20 @@
      bookId: options.id,
      bookPath: parentPath.join('\\')
    })
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
    this.digitalCoursesDetailsGet(options.id)
    this.getPlayerList()
    this.getType()
  },
  logInFun(callback) {
      loginInfo(app, (data) => {
        if (data) {
          this.digitalCoursesDetailsGet(options.id)
          this.getPlayerList()
          this.getType()
        } else {}
      })
        callback()
    }
    this.digitalCoursesDetailsGet(options.id)
    this.getPlayerList()
    this.getType()
    // this.setData({
    //   userName: JSON.parse(wx.getStorageSync(app.config.userInfoKey)).name,
    // })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
@@ -831,7 +828,8 @@
  //学习笔记
  //在线提问
  // 图书添加购物车
  async addBookShopcCar() {
  addBookShopcCar() {
    const addFun = async () => {
    if (!this.data.expire) {
      const shoppingCartGetId = [];
      let query = {
@@ -873,6 +871,14 @@
        duration: 1000,
      });
    }
    }
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      this.logInFun(() => {})
    } else {
      addFun()
    }
  },
  showSuccessToast() {
    Toast({
@@ -886,6 +892,7 @@
  //购买按钮
  async buyBtn() {
    const buyFun = async () => {
    if (!this.data.expire) {
      let bookOrdersId = "";
      let query = {
@@ -931,6 +938,14 @@
        duration: 1000,
      });
    }
    }
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      this.logInFun(() => {})
    } else {
      buyFun()
    }
  },
@@ -1097,6 +1112,7 @@
  },
  onCertificate() {
    const cateFun = () => {
    if (!this.data.isBuy) {
      wx.showToast({
        title: "请先购买,体验完整服务",
@@ -1121,7 +1137,6 @@
      });
      return false
    }
    var page = getCurrentPages().pop(); // 获取当前页面实例
    page.setData({
      // 动态设置禁止滚动的样式
@@ -1131,6 +1146,14 @@
      dialogBox: true,
      scrollJudge: ''
    })
    }
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      this.logInFun(() => {})
    } else {
      cateFun()
    }
  },
  closeDialog() {
    this.setData({
@@ -1317,62 +1340,35 @@
    }
  },
  setCoolect() {
    // 首页测试登录功能,后续注释
    // 检查登录状态
    const collectFun = () => {
      if (this.data.digitalsData.isFavourite) {
        app.MG.store
          .delProductLink({
            productIds: [this.data.digitalsData.id],
            linkType: 'Favoriteclass'
          })
          .then(() => {
            this.setData({
              "digitalsData.isFavourite": false
            })
          })
      } else {
        let params = {
          productIds: [this.data.digitalsData.id],
          linkType: 'Favoriteclass'
        }
        app.MG.store.addProductLink(params).then((res) => {
          this.setData({
            "digitalsData.isFavourite": true
          })
        })
      }
    }
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        // 如果不是第一次登录,会执行回调
        if (data) {
          if (this.data.digitalsData.isFavourite) {
            app.MG.store
              .delProductLink({
                productIds: [this.data.digitalsData.id],
                linkType: 'Favoriteclass'
              })
              .then(() => {
                this.setData({
                  "digitalsData.isFavourite": false
                })
              })
      this.logInFun(() => {})
          } else {
            let params = {
              productIds: [this.data.digitalsData.id],
              linkType: 'Favoriteclass'
            }
            app.MG.store.addProductLink(params).then((res) => {
              this.setData({
                "digitalsData.isFavourite": true
              })
            })
          }
        } else {
          // 出现错误,返回false
        }
      })
    } else {
      if (this.data.digitalsData.isFavourite) {
        app.MG.store
          .delProductLink({
            productIds: [this.data.digitalsData.id],
            linkType: 'Favoriteclass'
          })
          .then(() => {
            this.setData({
              "digitalsData.isFavourite": false
            })
          })
      } else {
        let params = {
          productIds: [this.data.digitalsData.id],
          linkType: 'Favoriteclass'
        }
        app.MG.store.addProductLink(params).then((res) => {
          this.setData({
            "digitalsData.isFavourite": true
          })
        })
      }
      collectFun()
    }
  },