闫增涛
2025-03-31 04c7b0163caeae4ab1c5da62e301fa993101cfad
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, // 云学习领取查看按钮是否显示
@@ -214,7 +211,8 @@
    protocolShow: false,
    protocolTxt: '',
    learnMenu: null,
    md5List: []
    md5List: [],
    editDialog: false
  },
  resetTree: function (e) {
@@ -222,6 +220,26 @@
      currentCheck: e.detail.checkedItem,
      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()
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
@@ -244,35 +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();
      }
    }
  },
@@ -292,8 +301,9 @@
    }
    this.setData({
      num: Number(this.data.paperBookList.length) + Number(this.data.electronicBookList.length),
      editDialog: false
    });
    if (this.data.bookDetail) {
    if (this.data.bookDetail.id) {
      this.getBookInfo(this.data.bookDetail.id)
    }
  },
@@ -433,11 +443,14 @@
        protectedEpub: [],
        probationPage: [], //pdf试读页数
        freeEpubPage: [], //epub试读百分比
        bookEditor: [], //图书编辑
        contactInformation: [], //联系方式
      },
    };
    app.MG.store.getProductDetail(query).then(async (res) => {
      this.getResourceCode(id, res.datas.rootCmsItemId)
      console.log(res.datas, "res.datas")
      res.datas.bookEditor = res.datas.bookEditor ? res.datas.bookEditor : '-'
      res.datas.contactInformation = res.datas.contactInformation ? res.datas.contactInformation : '-'
      this.setData({
        bookDetail: res.datas,
        buyIdList: res.datas.purchasedSaleMethodIdList,
@@ -471,6 +484,16 @@
          }
          await this.getBookClass(classData);
        }
      }
      // 扫码从题库跳转回图书详情
      const localData = wx.getStorageSync('tabValue')
      if (localData) {
        this.setData({
          tabValue: localData
        })
        wx.removeStorage({
          key: 'tabValue',
        })
      }
      if (this.data.tabValue == 'questionBank' || this.data.tabValue == 'jsek_cloudLearning' || this.data.tabValue == 'jsek_teachingResources') {
        const checkData = this.data.cmsDatas.find(
@@ -515,7 +538,6 @@
        "bookDetail.paperPrice": this.numFormat(
          this.data.bookDetail.paperPrice
        ),
      });
    });
  },
@@ -713,51 +735,64 @@
  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 = {
      this.collectFun()
    }
  },
  collectFun() {
    if (this.data.bookDetail.isFavourite) {
      app.MG.store
        .delProductLink({
          productIds: [this.data.bookDetail.id],
          linkType: "FavoriteBookCity",
        };
        app.MG.store.addProductLink(params).then((res) => {
        })
        .then(() => {
          this.setData({
            "bookDetail.isFavourite": true,
            "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({
      editDialog: true
    })
  },
  closeEditDialog() {
    this.setData({
      editDialog: false
    })
  },
  // 我要建议
  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) {
@@ -791,17 +826,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)
@@ -1009,7 +1033,6 @@
          loading: false,
        });
      }
      let list = []
      // 判断云学习有无销售方式和有效期
      const cloundSaleMethod =
@@ -1025,7 +1048,6 @@
      res.datas.cmsDatas[0].datas.forEach((item) => {
        // 云学习上有销售方式,去掉云学习下所有销售方式
        if (this.data.tabValue == "jsek_teachingResources") {
          if (item.file || item.freeFile) {
            let md5 = item.file ? item.file : item.freeFile
            md5s.push(md5)
@@ -1034,7 +1056,7 @@
            md5List: md5s,
          });
        }
        if (flags) item.saleMethod = []
        if (flags && cloundSaleMethod.Price > 0) item.saleMethod = []
        item.checked = false;
        if (item.sysType == 'CmsItem') {
          // 教学资源 类型名称赋值
@@ -1082,7 +1104,7 @@
          new Date(item.saleMethod.find((citem) => citem.SaleType == 'Normal').BeginDate).getTime() <= new Date().getTime()
        ) || (flags && cloundSaleMethod.Price == 0)
        // 判断云学习全部购买按钮是否显示
        let isShowBuyCloundMenu = flags && cloundSaleMethod.Price >= 0 && !this.data.buyIdList.includes(cloundSaleMethod.Id)
        let isShowBuyCloundMenu = flags && cloundSaleMethod.Price > 0 && !this.data.buyIdList.includes(cloundSaleMethod.Id)
        // 判断资源购买按钮是否显示
        let isShowBuyCloundBtn = !flags && res.datas.cmsDatas[0].datas.some(citem => citem.saleMethod.length != 0)
        // 判断购物车按钮和锁按钮是否显示
@@ -1095,13 +1117,14 @@
          isshowDrawBtn,
          isShowBuyCloundMenu,
          isShowBuyCloundBtn,
          isCloundHaveSaleMethod: flags,
          isCloundHaveSaleMethod: flags && cloundSaleMethod.Price > 0,
          learn: list,
          loading: false,
          openLearnids: result,
          learnPath: type.productLinkPath
        });
      }
      console.log('1', this.data.teach);
    })
  },
  //  获取 云测试
@@ -1175,7 +1198,7 @@
                jslx: false,
              });
            } else {
              data = res.datas.cmsDatas[0].datas.filter((item) => item.type == 'questionBankFolder' && item.refCode != 'jsek_interaction')
              data = res.datas.cmsDatas[0].datas.filter((item) => item.type == 'questionBankFolder')
              // && item.refCode != 'jsek_interaction'
              that.setData({
                jslx: true,
@@ -1253,48 +1276,57 @@
  },
  // 图书添加购物车
  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 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,
      });
    }
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      addFun()
    } else {
      this.logInFun(() => {})
    }
  },
  showSuccessToast() {
@@ -1654,7 +1686,7 @@
        (item) => item == saleData.Id
      );
      // 已经购买
      if (isShow) return false
      if (isShow || saleData.Price == 0) return false
      // 未购买,查看销售方式是否过期
      if (!isShow) {
        const flag = new Date(saleData.EndDate).getTime() >= new Date().getTime() &&
@@ -1769,85 +1801,83 @@
    return flattenedArray;
  },
  // 云学习一键领取
  async getFreeResource() {
  getFreeResource() {
    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,
            });
          }
        });
        query = {
          remarks: "云学习",
          requests,
        };
      }
      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);
      }
    }
    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: "领取成功",
        });
        this.getBookInfo(this.data.bookId);
        this.getResourceDataList({
          refCode: 'jsek_cloudLearning',
          productLinkPath: this.data.learnPath
        })
        this.setData({
          successOrderNumber: confirmOrderRes.orderNumber
        })
      }
    } catch (error) {
      console.log(error);
    }
  },
  // 云学习一键购买
  async allAddShoppiingCar() {
@@ -1900,34 +1930,37 @@
    }
  },
  // 云学习全部购买
  async buyCloudLearnClass() {
    const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning')
    debugger
    let query = {
      remarks: '云学习',
      requests: [{
        saleMethodId: cloundMenu.saleMethod.find((eitem) => eitem.SaleType == 'Normal').Id,
        count: 1
      }]
  buyCloudLearnClass() {
    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: "请重试",
        });
      }
    }
    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}`,
      });
    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')
  },
  // 变为所有check   true
@@ -1947,9 +1980,6 @@
      findAndUpdate(node); // 对每个顶层节点执行查找和更新操作
    }
    return tree; // 返回修改后的完整数组
  },
  handleTrue() {
    // findAndUpdateItemsByIds(this.date.)
  },
  // 题库购买
@@ -2073,53 +2103,62 @@
      });
  },
  // 购买组卷
  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 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);
    }
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      buyMockFun()
    } else {
      this.logInFun(() => {})
    }
  },
  // 记录购买组卷时间
  recordBuyMock() {
@@ -2221,40 +2260,65 @@
  },
  // 底部购买按钮
  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();
    } else {
      console.log(this.data.tabValue);
    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);
      }
    }
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      buyFun()
    } else {
      this.logInFun(() => {})
    }
  },
  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)
      })
    }
    });
  },
  //样书申请
@@ -2367,179 +2431,127 @@
  //申请电子样书
  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) {}
        },
      });
    }
    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,
      });
    }
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      applyFun()
    } else {
      this.logInFun(() => {})
    }
  },
  //申请纸质样书
  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) {}
        },
      });
    }
    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",
@@ -2553,13 +2565,83 @@
          },
        });
      }
    } 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,
        });
      }
    }
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      applyFun()
    } else {
      this.logInFun(() => {})
    }
  },
  //  添加样书
  addBookFun(item, type) {
@@ -2603,9 +2685,14 @@
  //去样书申请单
  goApply() {
    wx.navigateTo({
      url: "/packageDomain/pages/sampleBookList/applicationForm/index",
    });
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      wx.navigateTo({
        url: "/packageDomain/pages/sampleBookList/applicationForm/index",
      });
    } else {
      this.logInFun(() => {})
    }
  },
  handleTree() {
    // const child = this.selectComponent('#teach-tree')
@@ -2686,15 +2773,26 @@
    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 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
      });
    }
    const token = wx.getStorageSync(app.config.tokenKey);
    if (token) {
      uploadFun()
    } else {
      this.logInFun(() => {
        uploadFun()
      })
    }
  },
  closeDialog() {
    this.setData({