闫增涛
2025-03-28 b97bfcb85b2ded3b1f380e9a98b54b836faabba5
packageBookService/pages/bookServices/detail/index.js
@@ -13,9 +13,6 @@
   * 页面的初始数据
   */
  data: {
    // 进页面默认切换  展开的id
    // defaultactiveTeachid  教学资源
    // defaultactiveLearnid  云学习
    bookId: "",
    barHeight: "",
    navBarHeight: "",
@@ -49,7 +46,7 @@
    learnPath: '',
    applyResourceState: false, // 申请教学资源按钮防抖
    resourceClassList: [], // 资源所属分类
    applyState: "", // 教学资源申请状态
    applyState: "1", // 教学资源申请状态
    deadline: "", // 教学资源申请有效日期,
    isShowBuyCloundBtn: false,
    isshowDrawBtn: true, // 云学习领取查看按钮是否显示
@@ -224,6 +221,26 @@
      list: e.detail.changeList,
    });
  },
  logInFun(callback) {
    loginInfo(app, (data) => {
      if (data) {
        this.getShoppingCartProductGet();
        this.getApplyInfo(this.data.options.id);
        this.getAlreadyPBookList();
        this.getAlreadyEBookList();
        if (wx.getStorageSync(app.config.userInfoKey)) {
          this.setData({
            userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey)),
          });
          // 获取申请次数
          this.getSelectPaperBookCount();
          this.getSelectBookCount();
        }
        callback()
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
@@ -245,21 +262,18 @@
    wx.setNavigationBarTitle({
      title: decodeURI(options.name),
    })
    let token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {} else {}
      })
    }
    this.getBookInfo(options.id);
    // this.getResourceClass(); // 获取资源所属分类
    token = wx.getStorageSync(app.config.tokenKey)
    if (options.tabValue) {
      this.setData({
        tabValue: options.tabValue,
      });
    }
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      this.getShoppingCartProductGet();
      this.getApplyInfo(options.id);
      this.getApplyInfo(this.data.options.id);
      this.getAlreadyPBookList();
      this.getAlreadyEBookList();
    }
    if (wx.getStorageSync(app.config.userInfoKey)) {
      this.setData({
        userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey)),
@@ -268,10 +282,6 @@
      this.getSelectPaperBookCount();
      this.getSelectBookCount();
    }
    if (options.tabValue) {
      this.setData({
        tabValue: options.tabValue,
      });
    }
  },
@@ -724,17 +734,14 @@
  setCollect() {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (!token) {
      // 检查登录状态
      loginInfo(app, (data) => {
        // 如果不是第一次登录,会执行回调
        if (data) {
          // 登录成功,自动记录token和用户信息,并返回true
      this.logInFun(() => {
          this.getBookInfo(this.data.bookId);
      })
        } else {
          // 出现错误,返回false
      this.collectFun()
        }
      });
    } else {
  },
  collectFun() {
      if (this.data.bookDetail.isFavourite) {
        app.MG.store
          .delProductLink({
@@ -757,9 +764,7 @@
          });
        });
      }
    }
  },
  // 联系
  editPhone() {
    this.setData({
@@ -771,12 +776,18 @@
  suggestBtn() {
    // 检查登录状态
    const token = wx.getStorageSync(app.config.tokenKey);
    const child = this.selectComponent("#suggest-component");
    if (token)
      // child.showDialog();
    if (token) {
      this.setData({
        showIndex: '1'
      })
    } else {
      this.logInFun(() => {
        this.setData({
          showIndex: '1'
        })
      })
    }
  },
  // 跳转网店
  goShop(e) {
@@ -810,17 +821,6 @@
            "buyResourceData.refCode": checkData.refCode,
          });
        }
        // if (
        //   (e.detail.value == "jsek_teachingResources" &&
        //     !this.data.teach.length) ||
        //   (e.detail.value == "jsek_cloudLearning" && !this.data.learn.length) ||
        //   (e.detail.value == "questionBank" && !this.data.test.length)
        // ) {
        //   if (e.detail.value == "jsek_teachingResources") {
        //     wx.setStorageSync('teachResourcesPath', checkData.productLinkPath)
        //   }
        //   this.getResourceData(checkData);
        // }
        if ((e.detail.value == "jsek_teachingResources" && !this.data.teach.length) || (e.detail.value == "jsek_cloudLearning" && !this.data.learn.length)) {
          wx.setStorageSync('teachResourcesPath', checkData.productLinkPath)
          this.getResourceDataList(checkData)
@@ -1028,7 +1028,6 @@
          loading: false,
        });
      }
      let list = []
      // 判断云学习有无销售方式和有效期
      const cloundSaleMethod =
@@ -1120,6 +1119,7 @@
          learnPath: type.productLinkPath
        });
      }
      console.log('1', this.data.teach);
    })
  },
  //  获取 云测试
@@ -1271,7 +1271,14 @@
  },
  // 图书添加购物车
  async addBookShopcCar() {
  addBookShopcCar() {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      addFun()
    } else {
      this.logInFun(() => {})
    }
    const addFun = async () => {
    if (!this.data.expire) {
      const shoppingCartGetId = [];
      let query = {
@@ -1312,6 +1319,7 @@
        icon: "none",
        duration: 1000,
      });
      }
    }
  },
@@ -1787,19 +1795,15 @@
    return flattenedArray;
  },
  // 云学习一键领取
  async getFreeResource() {
  getFreeResource() {
    const child = this.selectComponent("#learn-resource");
    const token = wx.getStorageSync(app.config.tokenKey);
    if (!token) {
      loginInfo(app, (data) => {
        // 如果不是第一次登录,会执行回调
        if (data) {
          // 登录成功,自动记录token和用户信息,并返回true
      this.logInFun(() => {});
        } else {
          // 出现错误,返回false
      getFreeFun()
        }
      });
    }
    const getFreeFun = async () => {
    // 领取查看 ,先看云学习上的  再看资源上的
    const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning')
    const cloundMenuSaleMethod =
@@ -1866,6 +1870,7 @@
    } catch (error) {
      console.log(error);
    }
    }
  },
  // 云学习一键购买
  async allAddShoppiingCar() {
@@ -1918,7 +1923,14 @@
    }
  },
  // 云学习全部购买
  async buyCloudLearnClass() {
  buyCloudLearnClass() {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      buyClass()
    } else {
      this.logInFun(() => {})
    }
    const buyClass = async () => {
    const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning')
    let query = {
      remarks: '云学习',
@@ -1941,11 +1953,7 @@
        title: "请重试",
      });
    }
  },
  // 云学习字段购买
  async buyCloundMenu() {
    const cloundData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning')
    }
  },
  // 变为所有check   true
  findAndUpdateItemsByIds(tree, ids) {
@@ -1964,9 +1972,6 @@
      findAndUpdate(node); // 对每个顶层节点执行查找和更新操作
    }
    return tree; // 返回修改后的完整数组
  },
  handleTrue() {
    // findAndUpdateItemsByIds(this.date.)
  },
  // 题库购买
@@ -2090,7 +2095,14 @@
      });
  },
  // 购买组卷
  async buyMock() {
  buyMock() {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      buyMockFun()
    } else {
      this.logInFun(() => {})
    }
    const buyMockFun = async () => {
    let res;
    if (!this.data.mockData.id)
      return wx.showToast({
@@ -2136,6 +2148,7 @@
      }
    } catch (error) {
      console.log(error);
      }
    }
  },
  // 记录购买组卷时间
@@ -2238,6 +2251,13 @@
  },
  // 底部购买按钮
  buyBtn() {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      buyFun()
    } else {
      this.logInFun(() => {})
    }
    const buyFun = () => {
    if (this.data.tabValue == "brief" && !this.data.bookBuy) {
      this.buyBook();
    } else if (this.data.tabValue == "jsek_cloudLearning") {
@@ -2246,9 +2266,11 @@
    } else {
      console.log(this.data.tabValue);
    }
    }
  },
  goRead() {
  goRead(e) {
    const readFun = (bookBuy) => {
    if (!this.data.noFile) {
      wx.showToast({
        title: "暂无阅读文件",
@@ -2267,11 +2289,26 @@
        "&freePage=" +
        this.data.fileInfo.freePage +
        "&bookBuy=" +
        this.data.bookBuy +
          bookBuy +
        "&bookId=" +
        this.data.bookDetail.id,
    });
    }
    const {
      type
    } = e.currentTarget.dataset
    if (type == 'freeFile') return readFun(this.data.bookBuy)
    if (this.data.bookDetail.price == '0.00')
      return readFun(true)
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      readFun(this.data.bookBuy)
    } else {
      this.logInFun(() => {
        readFun(this.data.bookBuy)
      })
    }
  },
  //样书申请
@@ -2384,6 +2421,13 @@
  //申请电子样书
  appplyElectronicBook() {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      applyFun()
    } else {
      this.logInFun(() => {})
    }
    const applyFun = () => {
    // 先判断下教师认证,未对原有逻辑修改
    let role = this.data.userInfo != null ? this.data.userInfo.role : null;
    if (role && role == "Teacher") {} else {
@@ -2489,9 +2533,17 @@
        duration: 1000,
      });
    }
    }
  },
  //申请纸质样书
  appplyPaperBook() {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      applyFun()
    } else {
      this.logInFun(() => {})
    }
    const applyFun = () => {
    let role = this.data.userInfo != null ? this.data.userInfo.role : null;
    if (role && role == "Teacher") {} else {
      return wx.showModal({
@@ -2576,6 +2628,7 @@
        icon: "none",
        duration: 1000,
      });
      }
    }
  },
  //  添加样书
@@ -2703,6 +2756,15 @@
    return childrenList
  },
  uploadFile(e) {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      uploadFun()
    } else {
      this.logInFun(() => {
        uploadFun()
      })
    }
    const uploadFun = () => {
    const userInfo = JSON.parse(wx.getStorageSync(app.config.userInfoKey))
    if (userInfo.role != 'Teacher') return wx.showToast({
      icon: 'error',
@@ -2712,6 +2774,7 @@
      dialogBox: true,
      isShowUp: true
    });
    }
  },
  closeDialog() {
    this.setData({