闫增涛
2025-03-31 04c7b0163caeae4ab1c5da62e301fa993101cfad
packageDomain/pages/sampleBookList/index.js
@@ -84,6 +84,7 @@
    num: 0,
    x: 280,
    y: 300,
    scrollTop: 0
  },
  /**
@@ -141,26 +142,17 @@
    // 检查登录状态
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {
          that.setData({
            userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
          })
          that.getAlreadyPBookList()
          that.getAlreadyEBookList()
          // 获取申请次数
          that.getSelectPaperBookCount()
          that.getSelectBookCount()
        }
      })
    } else {
    if (token) {
      that.setData({
        userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
      })
      const paperBookList = wx.getStorageSync('paperBookList') ? JSON.parse(wx.getStorageSync('paperBookList')).length : 0
      const electronicBookList = wx.getStorageSync('electronicBookList') ? JSON.parse(wx.getStorageSync('electronicBookList')).length : 0
      this.setData({
        num: paperBookList + electronicBookList
      })
    }
    that.getBookList(false)
  },
  /**
@@ -175,16 +167,24 @@
   */
  onShow() {
    let that = this;
    that.setData({
      page: 1,
      paperBookList: [],
      electronicBookList: []
    })
    that.getAlreadyPBookList()
    that.getAlreadyEBookList()
    // 获取申请次数
    that.getSelectPaperBookCount()
    that.getSelectBookCount()
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {
          that.setData({
            userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
          })
          that.getAlreadyPBookList()
          that.getAlreadyEBookList()
          that.getSelectPaperBookCount()
          that.getSelectBookCount()
        } else {
          wx.switchTab({
            url: '/pages/home/home',
          })
        }
      })
    }
    if (wx.getStorageSync("paperBookList") || wx.getStorageSync("electronicBookList")) {
      if (wx.getStorageSync("paperBookList")) {
        that.setData({
@@ -200,7 +200,19 @@
        num: Number(that.data.paperBookList.length) + Number(that.data.electronicBookList.length)
      })
    }
    that.getBookList(false);
    // that.getBookList(false);
    that.dataRebuild(that.data.bookList)
  },
  onHide() {
    const query = wx.createSelectorQuery()
    query.select('#scrollView').scrollOffset(res => {
      console.log(1, res);
      this.setData({
        scrollTop: res.scrollTop
      })
      console.log('隐藏', this.data.scrollTop);
    }).exec()
  },
  goBack() {
    wx.navigateBack();
@@ -432,59 +444,7 @@
    app.MG.store.getProductList(query).then((res) => {
      try {
        if (res.datas.length > 0) {
          res.datas.forEach((item) => {
            item.paperDisabled = false
            item.paperChecked = false
            item.electronDisabled = false
            item.electronChecked = false
            if (item.purchasedSaleMethodIdList.indexOf(item.defaultSaleMethodId) > -1) {
              item.electronDisabled = true
              item.electronChecked = true
            }
            if (that.data.alreadyPaperBookList.length > 0) {
              that.data.alreadyPaperBookList.forEach((pBook) => {
                if (pBook.content.length > 0) {
                  pBook.content.forEach((pBookItem) => {
                    if (pBookItem.id === item.id && pBook.state == 'WaitAudit') {
                      item.paperDisabled = true
                      item.paperChecked = true
                    }
                    if (pBookItem.id === item.id && pBook.state == 'Normal') {
                      item.paperDisabled = false
                    }
                  })
                }
              })
            }
            if (that.data.alreadyElectronicBookList.length > 0) {
              that.data.alreadyElectronicBookList.forEach((eBook) => {
                if (eBook.content.length > 0) {
                  eBook.content.forEach((eBookItem) => {
                    if (eBookItem.id === item.id && !eBook.isExpiry && eBook.state != 'Reject') {
                      item.electronDisabled = true
                      item.electronChecked = true
                    }
                  })
                }
              })
            }
            if (that.data.paperBookList.length > 0) {
              for (let i = 0; i < that.data.paperBookList.length; i++) {
                if (that.data.paperBookList[i].id == item.id) {
                  item.paperChecked = true
                }
              }
            }
            if (that.data.electronicBookList.length > 0) {
              for (let i = 0; i < that.data.electronicBookList.length; i++) {
                if (that.data.electronicBookList[i].id == item.id) {
                  item.electronChecked = true
                }
              }
            }
          });
          let list = res.datas;
          let list = this.dataRebuild(res.datas);
          //触底加载新数据并保留老数据
          if (isReachBottom) {
            list = [...this.data.bookList, ...list] //将新数据加入老数据中
@@ -506,6 +466,65 @@
      }
    });
  },
  dataRebuild(list) {
    let that = this;
    console.log(list, 123)
    list.forEach((item) => {
      item.paperDisabled = false
      item.paperChecked = false
      item.electronDisabled = false
      item.electronChecked = false
      if (item.purchasedSaleMethodIdList.indexOf(item.defaultSaleMethodId) > -1) {
        item.electronDisabled = true
        item.electronChecked = true
      }
      if (that.data.alreadyPaperBookList.length > 0) {
        that.data.alreadyPaperBookList.forEach((pBook) => {
          if (pBook.content.length > 0) {
            pBook.content.forEach((pBookItem) => {
              if (pBookItem.id === item.id && pBook.state == 'WaitAudit') {
                item.paperDisabled = true
                item.paperChecked = true
              }
              if (pBookItem.id === item.id && pBook.state == 'Normal') {
                item.paperDisabled = false
              }
            })
          }
        })
      }
      if (that.data.alreadyElectronicBookList.length > 0) {
        that.data.alreadyElectronicBookList.forEach((eBook) => {
          if (eBook.content.length > 0) {
            eBook.content.forEach((eBookItem) => {
              if (eBookItem.id === item.id && !eBook.isExpiry && eBook.state != 'Reject') {
                item.electronDisabled = true
                item.electronChecked = true
              }
            })
          }
        })
      }
      if (that.data.paperBookList.length > 0) {
        for (let i = 0; i < that.data.paperBookList.length; i++) {
          if (that.data.paperBookList[i].id == item.id) {
            item.paperChecked = true
          }
        }
      }
      if (that.data.electronicBookList.length > 0) {
        for (let i = 0; i < that.data.electronicBookList.length; i++) {
          if (that.data.electronicBookList[i].id == item.id) {
            item.electronChecked = true
          }
        }
      }
    });
    return list
  },
  //高级分类选择
  onChangeIcon(e) {
    this.setData({
@@ -540,8 +559,8 @@
    this.getBookList(false);
    this.getSecondList(path);
  },
  // 二级分类切换
  onChangeSecond(e) {
  // 二级分类切换
  onConfirmSecond(e) {
    const pathList = [];
    for (let index = 0; index < e.detail.value.length; index++) {
      const element = e.detail.value[index];
@@ -556,14 +575,12 @@
      pathList: pathList,
      'secondList.value': e.detail.value,
    });
  },
  //
  onConfirmSecond() {
    this.getBookList(false);
  },
  onResetSecond() {
    this.setData({
      skeletonLoding: true,
      pathList: [],
      'secondList.value': [],
    });
    this.getBookList(false);
@@ -666,9 +683,6 @@
        this.setData({
          alreadyElectronicBookList: list,
        });
        if (wx.getStorageSync(app.config.tokenKey)) {
          this.getBookList(false);
        }
      }
    })
  },
@@ -952,7 +966,6 @@
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  }
  onShareAppMessage() {},
  onShareTimeline() {},
})