闫增涛
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,33 +262,26 @@
    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 (token) {
      this.getShoppingCartProductGet();
      this.getApplyInfo(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();
    }
    if (options.tabValue) {
      this.setData({
        tabValue: options.tabValue,
      });
    }
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      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();
      }
    }
  },
@@ -724,42 +734,37 @@
  setCollect() {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (!token) {
      // 检查登录状态
      loginInfo(app, (data) => {
        // 如果不是第一次登录,会执行回调
        if (data) {
          // 登录成功,自动记录token和用户信息,并返回true
          this.getBookInfo(this.data.bookId);
        } else {
          // 出现错误,返回false
        }
      });
      this.logInFun(() => {
        this.getBookInfo(this.data.bookId);
      })
    } else {
      if (this.data.bookDetail.isFavourite) {
        app.MG.store
          .delProductLink({
            productIds: [this.data.bookDetail.id],
            linkType: "FavoriteBookCity",
          })
          .then(() => {
            this.setData({
              "bookDetail.isFavourite": false,
            });
          });
      } else {
        const params = {
          productIds: [this.data.bookDetail.id],
          linkType: "FavoriteBookCity",
        };
        app.MG.store.addProductLink(params).then((res) => {
          this.setData({
            "bookDetail.isFavourite": true,
          });
        });
      }
      this.collectFun()
    }
  },
  collectFun() {
    if (this.data.bookDetail.isFavourite) {
      app.MG.store
        .delProductLink({
          productIds: [this.data.bookDetail.id],
          linkType: "FavoriteBookCity",
        })
        .then(() => {
          this.setData({
            "bookDetail.isFavourite": false,
          });
        });
    } else {
      const params = {
        productIds: [this.data.bookDetail.id],
        linkType: "FavoriteBookCity",
      };
      app.MG.store.addProductLink(params).then((res) => {
        this.setData({
          "bookDetail.isFavourite": true,
        });
      });
    }
  },
  // 联系
  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,47 +1271,55 @@
  },
  // 图书添加购物车
  async addBookShopcCar() {
    if (!this.data.expire) {
      const shoppingCartGetId = [];
      let query = {
        start: 0,
        size: 9999,
        filterList: [],
        searchList: [],
      };
      const res = await app.MG.store.getShoppingCartProductList(query);
      res.datas.forEach((item) => {
        shoppingCartGetId.push(item.saleMethod.id);
      });
      const determine = shoppingCartGetId.some(
        (item) => item == this.data.selectedIds
      );
      if (!determine) {
  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 = {
          requests: [{
            saleMethodId: this.data.selectedIds,
            storeEventId: null,
            agentCode: "电子书",
          }, ],
          start: 0,
          size: 9999,
          filterList: [],
          searchList: [],
        };
        const addRes = app.MG.store.addShoppingCart(query);
        this.showSuccessToast();
        const res = await app.MG.store.getShoppingCartProductList(query);
        res.datas.forEach((item) => {
          shoppingCartGetId.push(item.saleMethod.id);
        });
        const determine = shoppingCartGetId.some(
          (item) => item == this.data.selectedIds
        );
        if (!determine) {
          let query = {
            requests: [{
              saleMethodId: this.data.selectedIds,
              storeEventId: null,
              agentCode: "电子书",
            }, ],
          };
          const addRes = app.MG.store.addShoppingCart(query);
          this.showSuccessToast();
        } else {
          Toast({
            context: this,
            selector: "#t-toast",
            message: "该书已在购物车,请勿重复添加",
            theme: "warning",
            direction: "column",
          });
        }
      } else {
        Toast({
          context: this,
          selector: "#t-toast",
          message: "该书已在购物车,请勿重复添加",
          theme: "warning",
          direction: "column",
        wx.showToast({
          title: "商品不在有效期",
          icon: "none",
          duration: 1000,
        });
      }
    } else {
      wx.showToast({
        title: "商品不在有效期",
        icon: "none",
        duration: 1000,
      });
    }
  },
@@ -1787,84 +1795,81 @@
    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
        } else {
          // 出现错误,返回false
        }
      });
    }
    // 领取查看 ,先看云学习上的  再看资源上的
    const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning')
    const cloundMenuSaleMethod =
      cloundMenu.saleMethod && cloundMenu.saleMethod.length ?
      cloundMenu.saleMethod.find((ditem) => ditem.SaleType == 'Normal') :
      undefined
    let query = {}
    if (this.data.isCloundHaveSaleMethod && !cloundMenuSaleMethod.Price) {
      // 云学习上有销售方式,且为0元,直接领取云学习
      query = {
        remarks: '云学习',
        requests: [{
          saleMethodId: cloundMenuSaleMethod.Id,
          count: 1
        }]
      }
      this.logInFun(() => {});
    } else {
      // 领取资源
      let arr = this.handleTreeData(this.data.learn).filter(item => this.resourceIsBuy(item))
      let freeIds = arr.filter((item) => {
        return item.saleMethod.find((citem) => citem.SaleType == 'Normal').Price == 0
      })
      if (!freeIds.length)
        return wx.showToast({
          icon: "error",
          title: "暂无免费资源",
        });
      let requests = [];
      freeIds.forEach((item, index) => {
        if (this.resourceIsBuy(item)) {
          requests.push({
            saleMethodId: item.saleMethod[0].Id,
            count: 1,
          });
        }
      });
      query = {
        remarks: "云学习",
        requests,
      };
      getFreeFun()
    }
    child.changeReceive(true);
    try {
      const initOrderRes = await app.MG.store.initOrder(query);
      let parameter = {
        orderNum: initOrderRes.orderNumber,
      };
      // 确认订单
      const confirmOrderRes = await app.MG.store.confirmOrder(parameter);
      if (confirmOrderRes.orderNumber) {
        child.changeReceive(false);
        wx.showToast({
          title: "领取成功",
    const getFreeFun = async () => {
      // 领取查看 ,先看云学习上的  再看资源上的
      const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning')
      const cloundMenuSaleMethod =
        cloundMenu.saleMethod && cloundMenu.saleMethod.length ?
        cloundMenu.saleMethod.find((ditem) => ditem.SaleType == 'Normal') :
        undefined
      let query = {}
      if (this.data.isCloundHaveSaleMethod && !cloundMenuSaleMethod.Price) {
        // 云学习上有销售方式,且为0元,直接领取云学习
        query = {
          remarks: '云学习',
          requests: [{
            saleMethodId: cloundMenuSaleMethod.Id,
            count: 1
          }]
        }
      } else {
        // 领取资源
        let arr = this.handleTreeData(this.data.learn).filter(item => this.resourceIsBuy(item))
        let freeIds = arr.filter((item) => {
          return item.saleMethod.find((citem) => citem.SaleType == 'Normal').Price == 0
        })
        if (!freeIds.length)
          return wx.showToast({
            icon: "error",
            title: "暂无免费资源",
          });
        let requests = [];
        freeIds.forEach((item, index) => {
          if (this.resourceIsBuy(item)) {
            requests.push({
              saleMethodId: item.saleMethod[0].Id,
              count: 1,
            });
          }
        });
        this.getBookInfo(this.data.bookId);
        this.getResourceDataList({
          refCode: 'jsek_cloudLearning',
          productLinkPath: this.data.learnPath
        })
        this.setData({
          successOrderNumber: confirmOrderRes.orderNumber
        })
        query = {
          remarks: "云学习",
          requests,
        };
      }
    } catch (error) {
      console.log(error);
      child.changeReceive(true);
      try {
        const initOrderRes = await app.MG.store.initOrder(query);
        let parameter = {
          orderNum: initOrderRes.orderNumber,
        };
        // 确认订单
        const confirmOrderRes = await app.MG.store.confirmOrder(parameter);
        if (confirmOrderRes.orderNumber) {
          child.changeReceive(false);
          wx.showToast({
            title: "领取成功",
          });
          this.getBookInfo(this.data.bookId);
          this.getResourceDataList({
            refCode: 'jsek_cloudLearning',
            productLinkPath: this.data.learnPath
          })
          this.setData({
            successOrderNumber: confirmOrderRes.orderNumber
          })
        }
      } catch (error) {
        console.log(error);
      }
    }
  },
  // 云学习一键购买
@@ -1918,34 +1923,37 @@
    }
  },
  // 云学习全部购买
  async buyCloudLearnClass() {
    const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning')
    let query = {
      remarks: '云学习',
      requests: [{
        saleMethodId: cloundMenu.saleMethod.find((eitem) => eitem.SaleType == 'Normal').Id,
        count: 1
      }]
    }
    const initOrderRes = await app.MG.store.initOrder(query)
    // 检查订单号是否存在
    if (initOrderRes.orderNumber) {
      // bookService: orderNumber.value,  少传这个 ,暂时不知道有什么用
      wx.navigateTo({
        url: `/pages/cart/paymentPage/index?&bookId=${this.data.bookDetail.id}&bookName=${this.data.bookDetail.name}&orderNumber=${initOrderRes.orderNumber}`,
      });
  buyCloudLearnClass() {
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      buyClass()
    } else {
      // 订单号不存在,显示警告消息
      wx.showToast({
        icon: "error",
        title: "请重试",
      });
      this.logInFun(() => {})
    }
  },
  // 云学习字段购买
  async buyCloundMenu() {
    const cloundData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning')
    const buyClass = async () => {
      const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning')
      let query = {
        remarks: '云学习',
        requests: [{
          saleMethodId: cloundMenu.saleMethod.find((eitem) => eitem.SaleType == 'Normal').Id,
          count: 1
        }]
      }
      const initOrderRes = await app.MG.store.initOrder(query)
      // 检查订单号是否存在
      if (initOrderRes.orderNumber) {
        // bookService: orderNumber.value,  少传这个 ,暂时不知道有什么用
        wx.navigateTo({
          url: `/pages/cart/paymentPage/index?&bookId=${this.data.bookDetail.id}&bookName=${this.data.bookDetail.name}&orderNumber=${initOrderRes.orderNumber}`,
        });
      } else {
        // 订单号不存在,显示警告消息
        wx.showToast({
          icon: "error",
          title: "请重试",
        });
      }
    }
  },
  // 变为所有check   true
  findAndUpdateItemsByIds(tree, ids) {
@@ -1964,9 +1972,6 @@
      findAndUpdate(node); // 对每个顶层节点执行查找和更新操作
    }
    return tree; // 返回修改后的完整数组
  },
  handleTrue() {
    // findAndUpdateItemsByIds(this.date.)
  },
  // 题库购买
@@ -2090,52 +2095,60 @@
      });
  },
  // 购买组卷
  async buyMock() {
    let res;
    if (!this.data.mockData.id)
      return wx.showToast({
        icon: "error",
        title: "暂无组卷",
        mask: true,
      });
    // 构建订单查询对象
    try {
      let query = {
        remarks: "组卷",
        requests: [{
          saleMethodId: this.data.mockData.id,
          count: 1,
        }, ],
      };
      if (this.data.flag) {
        this.setData({
          flag: false,
  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({
          icon: "error",
          title: "暂无组卷",
          mask: true,
        });
        res = await app.MG.store.initOrder(query);
      }
      if (res.orderNumber && this.data.mockData.price) {
        wx.navigateTo({
          url: `/pages/cart/paymentPage/index?orderNumber=${res.orderNumber}`,
        });
      } else {
        // 0元直接领取
        // 确认订单
        const confirmOrderRes = await app.MG.store.confirmOrder({
          orderNum: res.orderNumber,
        });
        if (confirmOrderRes) {
          wx.showToast({
            icon: "success",
            title: "领取成功",
          });
      // 构建订单查询对象
      try {
        let query = {
          remarks: "组卷",
          requests: [{
            saleMethodId: this.data.mockData.id,
            count: 1,
          }, ],
        };
        if (this.data.flag) {
          this.setData({
            flag: true,
            flag: false,
          });
          await this.recordBuyMock(); // 记录购买时间
          res = await app.MG.store.initOrder(query);
        }
        if (res.orderNumber && this.data.mockData.price) {
          wx.navigateTo({
            url: `/pages/cart/paymentPage/index?orderNumber=${res.orderNumber}`,
          });
        } else {
          // 0元直接领取
          // 确认订单
          const confirmOrderRes = await app.MG.store.confirmOrder({
            orderNum: res.orderNumber,
          });
          if (confirmOrderRes) {
            wx.showToast({
              icon: "success",
              title: "领取成功",
            });
            this.setData({
              flag: true,
            });
            await this.recordBuyMock(); // 记录购买时间
          }
        }
      } catch (error) {
        console.log(error);
      }
    } catch (error) {
      console.log(error);
    }
  },
  // 记录购买组卷时间
@@ -2238,40 +2251,64 @@
  },
  // 底部购买按钮
  buyBtn() {
    if (this.data.tabValue == "brief" && !this.data.bookBuy) {
      this.buyBook();
    } else if (this.data.tabValue == "jsek_cloudLearning") {
      const tree = this.selectComponent("#tree");
      tree.onCloudShoppingCart();
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      buyFun()
    } else {
      console.log(this.data.tabValue);
      this.logInFun(() => {})
    }
    const buyFun = () => {
      if (this.data.tabValue == "brief" && !this.data.bookBuy) {
        this.buyBook();
      } else if (this.data.tabValue == "jsek_cloudLearning") {
        const tree = this.selectComponent("#tree");
        tree.onCloudShoppingCart();
      } else {
        console.log(this.data.tabValue);
      }
    }
  },
  goRead() {
    if (!this.data.noFile) {
      wx.showToast({
        title: "暂无阅读文件",
        icon: "none",
        duration: 2000,
  goRead(e) {
    const readFun = (bookBuy) => {
      if (!this.data.noFile) {
        wx.showToast({
          title: "暂无阅读文件",
          icon: "none",
          duration: 2000,
        });
        return false;
      }
      wx.navigateTo({
        url: "/packageBookService/pages/components/webView/index?md5=" +
          this.data.fileInfo.md5 +
          "&fileName=" +
          this.data.fileInfo.bookName +
          "&fileType=" +
          this.data.fileInfo.fileType +
          "&freePage=" +
          this.data.fileInfo.freePage +
          "&bookBuy=" +
          bookBuy +
          "&bookId=" +
          this.data.bookDetail.id,
      });
      return false;
    }
    wx.navigateTo({
      url: "/packageBookService/pages/components/webView/index?md5=" +
        this.data.fileInfo.md5 +
        "&fileName=" +
        this.data.fileInfo.bookName +
        "&fileType=" +
        this.data.fileInfo.fileType +
        "&freePage=" +
        this.data.fileInfo.freePage +
        "&bookBuy=" +
        this.data.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,179 +2421,132 @@
  //申请电子样书
  appplyElectronicBook() {
    // 先判断下教师认证,未对原有逻辑修改
    let role = this.data.userInfo != null ? this.data.userInfo.role : null;
    if (role && role == "Teacher") {} else {
      return wx.showModal({
        title: "尊敬的用户,您好!", //提示的标题
        content: "请先进行教师认证?", //提示的内容
        confirmColor: "#ff6c00",
        cancelColor: "#949494",
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: "/packageDomain/pages/teacherCertification/index",
            });
          } else if (res.cancel) {}
        },
      });
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      applyFun()
    } else {
      this.logInFun(() => {})
    }
    if (
      this.data.bookDetail.isApplyBook == 2 ||
      this.data.bookDetail.isApplyBook == 4
    ) {
    const applyFun = () => {
      // 先判断下教师认证,未对原有逻辑修改
      let role = this.data.userInfo != null ? this.data.userInfo.role : null;
      if (role && role == "Teacher") {
        if (!this.data.noFile) {
          wx.showToast({
            title: "暂无电子书文件,请联系管理员!",
            icon: "none",
            duration: 1000,
          });
          return;
        }
        if (this.data.ebookCount == 0) {
          wx.showToast({
            title: "您的电子样书申请次数已用尽,若要继续,请联系管理员!",
            icon: "none",
            duration: 1000,
          });
          return false;
        }
        let isHas = this.data.electronicBookList.find(
          (eitem) => eitem.id == this.data.bookDetail.id
        );
        if (isHas) {
          wx.showToast({
            title: "该书已在清单列表中",
            icon: "none",
            duration: 1000,
          });
          return false;
        }
        let isApply = this.data.alreadyElectronicBookList.find(
          (eitem) => eitem.content[0].id == this.data.bookDetail.id
        );
        if (isApply) {
          if (isApply.state == 'WaitAudit') {
      if (role && role == "Teacher") {} else {
        return wx.showModal({
          title: "尊敬的用户,您好!", //提示的标题
          content: "请先进行教师认证?", //提示的内容
          confirmColor: "#ff6c00",
          cancelColor: "#949494",
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: "/packageDomain/pages/teacherCertification/index",
              });
            } else if (res.cancel) {}
          },
        });
      }
      if (
        this.data.bookDetail.isApplyBook == 2 ||
        this.data.bookDetail.isApplyBook == 4
      ) {
        let role = this.data.userInfo != null ? this.data.userInfo.role : null;
        if (role && role == "Teacher") {
          if (!this.data.noFile) {
            wx.showToast({
              title: "该书已申请!",
              title: "暂无电子书文件,请联系管理员!",
              icon: "none",
              duration: 1000,
            });
            return;
          }
          if (this.data.ebookCount == 0) {
            wx.showToast({
              title: "您的电子样书申请次数已用尽,若要继续,请联系管理员!",
              icon: "none",
              duration: 1000,
            });
            return false;
          } else if (isApply.state == 'Normal') {
            const flag = new Date(isApply.feedBack.endDate + ' 23:59:59').getTime() > new Date().getTime()
            if (flag) {
          }
          let isHas = this.data.electronicBookList.find(
            (eitem) => eitem.id == this.data.bookDetail.id
          );
          if (isHas) {
            wx.showToast({
              title: "该书已在清单列表中",
              icon: "none",
              duration: 1000,
            });
            return false;
          }
          let isApply = this.data.alreadyElectronicBookList.find(
            (eitem) => eitem.content[0].id == this.data.bookDetail.id
          );
          if (isApply) {
            if (isApply.state == 'WaitAudit') {
              wx.showToast({
                title: "该书已申请!",
                icon: "none",
                duration: 1000,
              });
              return false;
            } else if (isApply.state == 'Normal') {
              const flag = new Date(isApply.feedBack.endDate + ' 23:59:59').getTime() > new Date().getTime()
              if (flag) {
                wx.showToast({
                  title: "该书已申请!",
                  icon: "none",
                  duration: 1000,
                });
                return false;
              }
            }
          }
        }
        if (this.data.electronicBookList.length >= 2) {
          wx.showToast({
            title: "每次最多只可申请2本样书",
            icon: "none",
            duration: 1000,
          if (this.data.electronicBookList.length >= 2) {
            wx.showToast({
              title: "每次最多只可申请2本样书",
              icon: "none",
              duration: 1000,
            });
            return false;
          }
          this.addBookFun(this.data.bookDetail, "eBook");
        } else {
          wx.showModal({
            title: "尊敬的用户,您好!", //提示的标题
            content: "请先进行教师认证?", //提示的内容
            confirmColor: "#ff6c00",
            cancelColor: "#949494",
            success: function (res) {
              if (res.confirm) {
                wx.navigateTo({
                  url: "/packageDomain/pages/teacherCertification/index",
                });
              } else if (res.cancel) {}
            },
          });
          return false;
        }
        this.addBookFun(this.data.bookDetail, "eBook");
      } else {
        wx.showModal({
          title: "尊敬的用户,您好!", //提示的标题
          content: "请先进行教师认证?", //提示的内容
          confirmColor: "#ff6c00",
          cancelColor: "#949494",
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: "/packageDomain/pages/teacherCertification/index",
              });
            } else if (res.cancel) {}
          },
        wx.showToast({
          title: "该书不能申请电子样书",
          icon: "none",
          duration: 1000,
        });
      }
    } else {
      wx.showToast({
        title: "该书不能申请电子样书",
        icon: "none",
        duration: 1000,
      });
    }
  },
  //申请纸质样书
  appplyPaperBook() {
    let role = this.data.userInfo != null ? this.data.userInfo.role : null;
    if (role && role == "Teacher") {} else {
      return wx.showModal({
        title: "尊敬的用户,您好!", //提示的标题
        content: "请先进行教师认证?", //提示的内容
        confirmColor: "#ff6c00",
        cancelColor: "#949494",
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: "/packageDomain/pages/teacherCertification/index",
            });
          } else if (res.cancel) {}
        },
      });
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      applyFun()
    } else {
      this.logInFun(() => {})
    }
    if (
      this.data.bookDetail.isApplyBook == 3 ||
      this.data.bookDetail.isApplyBook == 4
    ) {
    const applyFun = () => {
      let role = this.data.userInfo != null ? this.data.userInfo.role : null;
      if (role && role == "Teacher") {
        // 点击选中
        if (this.data.paperBookCount == 0) {
          wx.showToast({
            title: "您的纸质样书申请次数已用尽,若要继续,请联系管理员!",
            icon: "none",
            duration: 1000,
          });
          return false;
        }
        let isApply = this.data.alreadyPaperBookList.find(
          (pitem) => pitem.content[0].id == this.data.bookDetail.id
        );
        if (isApply) {
          wx.showToast({
            title: "该书已申请!",
            icon: "none",
            duration: 1000,
          });
          return false;
        }
        let isHas = this.data.paperBookList.find(
          (pitem) => pitem.id == this.data.bookDetail.id
        );
        if (isHas) {
          wx.showToast({
            title: "该书已在清单列表中",
            icon: "none",
            duration: 1000,
          });
          return false;
        }
        if (this.data.paperBookList.length >= 2) {
          wx.showToast({
            title: "每次最多只可申请2本样书",
            icon: "none",
            duration: 1000,
          });
          return false;
        }
        this.addBookFun(this.data.bookDetail, "pBook");
      } else {
        wx.showModal({
      if (role && role == "Teacher") {} else {
        return wx.showModal({
          title: "尊敬的用户,您好!", //提示的标题
          content: "请先进行教师认证?", //提示的内容
          confirmColor: "#ff6c00",
@@ -2570,12 +2560,75 @@
          },
        });
      }
    } else {
      wx.showToast({
        title: "该书不能申请纸质样书",
        icon: "none",
        duration: 1000,
      });
      if (
        this.data.bookDetail.isApplyBook == 3 ||
        this.data.bookDetail.isApplyBook == 4
      ) {
        let role = this.data.userInfo != null ? this.data.userInfo.role : null;
        if (role && role == "Teacher") {
          // 点击选中
          if (this.data.paperBookCount == 0) {
            wx.showToast({
              title: "您的纸质样书申请次数已用尽,若要继续,请联系管理员!",
              icon: "none",
              duration: 1000,
            });
            return false;
          }
          let isApply = this.data.alreadyPaperBookList.find(
            (pitem) => pitem.content[0].id == this.data.bookDetail.id
          );
          if (isApply) {
            wx.showToast({
              title: "该书已申请!",
              icon: "none",
              duration: 1000,
            });
            return false;
          }
          let isHas = this.data.paperBookList.find(
            (pitem) => pitem.id == this.data.bookDetail.id
          );
          if (isHas) {
            wx.showToast({
              title: "该书已在清单列表中",
              icon: "none",
              duration: 1000,
            });
            return false;
          }
          if (this.data.paperBookList.length >= 2) {
            wx.showToast({
              title: "每次最多只可申请2本样书",
              icon: "none",
              duration: 1000,
            });
            return false;
          }
          this.addBookFun(this.data.bookDetail, "pBook");
        } else {
          wx.showModal({
            title: "尊敬的用户,您好!", //提示的标题
            content: "请先进行教师认证?", //提示的内容
            confirmColor: "#ff6c00",
            cancelColor: "#949494",
            success: function (res) {
              if (res.confirm) {
                wx.navigateTo({
                  url: "/packageDomain/pages/teacherCertification/index",
                });
              } else if (res.cancel) {}
            },
          });
        }
      } else {
        wx.showToast({
          title: "该书不能申请纸质样书",
          icon: "none",
          duration: 1000,
        });
      }
    }
  },
  //  添加样书
@@ -2703,15 +2756,25 @@
    return childrenList
  },
  uploadFile(e) {
    const userInfo = JSON.parse(wx.getStorageSync(app.config.userInfoKey))
    if (userInfo.role != 'Teacher') return wx.showToast({
      icon: 'error',
      title: '请先进行教师认证',
    })
    this.setData({
      dialogBox: true,
      isShowUp: true
    });
    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',
        title: '请先进行教师认证',
      })
      this.setData({
        dialogBox: true,
        isShowUp: true
      });
    }
  },
  closeDialog() {
    this.setData({