| | |
| | | ebookCount: 0, |
| | | paperBookCount: 0, |
| | | bookList: [], |
| | | isIos: wx.getSystemInfoSync().platform === 'ios', |
| | | keyboardHeight: 0 |
| | | }, |
| | | |
| | | /** |
| | |
| | | * 生命周期函数--监听页面显示 |
| | | */ |
| | | onShow() { |
| | | let that = this; |
| | | that.setData({ |
| | | bookList: [] |
| | | }) |
| | | if (wx.getStorageSync(app.config.userInfoKey)) { |
| | | this.setData({ |
| | | that.setData({ |
| | | userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey)) |
| | | }) |
| | | if (this.data.userInfo.role == 'Teacher') { |
| | | this.setData({ |
| | | 'teacherInfo.schoolName': JSON.parse(this.data.userInfo.data).schoolName, |
| | | 'teacherInfo.courseName': JSON.parse(this.data.userInfo.data).courseName, |
| | | 'contactInfo.fullName': JSON.parse(this.data.userInfo.data).fullName, |
| | | 'contactInfo.phone': JSON.parse(this.data.userInfo.data).phone, |
| | | 'contactInfo.detailedAddress': JSON.parse(this.data.userInfo.data).detailedAddress, |
| | | if (that.data.userInfo.role == 'Teacher') { |
| | | that.setData({ |
| | | 'teacherInfo.schoolName': JSON.parse(that.data.userInfo.data).schoolName, |
| | | 'teacherInfo.courseName': JSON.parse(that.data.userInfo.data).courseName, |
| | | 'contactInfo.fullName': JSON.parse(that.data.userInfo.data).fullName, |
| | | 'contactInfo.phone': JSON.parse(that.data.userInfo.data).phone, |
| | | 'contactInfo.detailedAddress': JSON.parse(that.data.userInfo.data).detailedAddress, |
| | | }) |
| | | } else { |
| | | wx.showModal({ |
| | | title: '尊敬的用户,您好!', //提示的标题 |
| | | content: '请先进行教师认证?', //提示的内容 |
| | | success: function (res) { |
| | | if (res.confirm) { |
| | | wx.navigateTo({ |
| | | url: "/packageDomain/pages/teacherCertification/index", |
| | | }); |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | if (wx.getStorageSync("paperBookList")) { |
| | | this.setData({ |
| | | paperBookList: wx.getStorageSync("paperBookList"), |
| | | bookList: wx.getStorageSync("paperBookList") |
| | | that.setData({ |
| | | paperBookList: JSON.parse(wx.getStorageSync("paperBookList")), |
| | | bookList: JSON.parse(wx.getStorageSync("paperBookList")) |
| | | }) |
| | | } |
| | | if (wx.getStorageSync("electronicBookList")) { |
| | | this.setData({ |
| | | electronicBookList: wx.getStorageSync("electronicBookList") |
| | | that.setData({ |
| | | electronicBookList: JSON.parse(wx.getStorageSync("electronicBookList")) |
| | | }) |
| | | } |
| | | this.getSelectBookCount(); |
| | | this.getSelectPaperBookCount(); |
| | | this.getPaperType(); |
| | | that.getSelectBookCount(); |
| | | that.getSelectPaperBookCount(); |
| | | that.getPaperType(); |
| | | } |
| | | }, |
| | | |
| | |
| | | }) |
| | | }, |
| | | |
| | | // 监听页面软键盘弹起手动推动页面 |
| | | bindkeyboardheightchange(e) { |
| | | // 只对ios 处理 |
| | | if (!this.data.isIos === 'ios') { |
| | | return |
| | | } |
| | | // 键盘高度 |
| | | const height = e.detail.height; |
| | | const className = e.target.dataset.class; |
| | | console.log(height, className) |
| | | if (height === 0) { |
| | | this.scrollToInput(0); |
| | | return; |
| | | } |
| | | try { |
| | | this.createSelectorQuery() |
| | | .select(`.${className}`) |
| | | .boundingClientRect((res) => { |
| | | // 可使用窗口高度 |
| | | const windowHeight = wx.getSystemInfoSync().windowHeight; |
| | | // 除去键盘的剩余高度 |
| | | let restHeight = windowHeight - height; |
| | | // 元素左下角坐标 |
| | | let bottom = res.bottom; |
| | | // 只有当元素被软键盘覆盖的时候才上推页面 |
| | | if (bottom <= restHeight) return; |
| | | // 现阶段需要滚动的大小 |
| | | let scrollTop = bottom - restHeight; |
| | | console.log(scrollTop, 1) |
| | | this.scrollToInput(height, scrollTop); |
| | | }) |
| | | .exec(); |
| | | } catch (error) {} |
| | | }, |
| | | |
| | | // 获取页面滚动条位置 |
| | | getScrollOffset() { |
| | | return new Promise((resolve) => { |
| | | try { |
| | | wx.createSelectorQuery() |
| | | .selectViewport() |
| | | .scrollOffset((res) => { |
| | | resolve(res.scrollTop); |
| | | }) |
| | | .exec(); |
| | | } catch (error) { |
| | | resolve(0); |
| | | } |
| | | }); |
| | | }, |
| | | |
| | | // 监听页面软键盘弹起手动推动页面 |
| | | scrollToInput(keyboardHeight, scrollTop) { |
| | | this.setData({ |
| | | keyboardHeight, |
| | | }); |
| | | if (scrollTop) { |
| | | try { |
| | | this.getScrollOffset().then((lastScrollTop) => { |
| | | wx.pageScrollTo({ |
| | | // 如果已经存在滚动,在此基础上继续滚 |
| | | scrollTop: lastScrollTop ? lastScrollTop + scrollTop : scrollTop, |
| | | duration: 300, |
| | | }); |
| | | }); |
| | | } catch (error) {} |
| | | } |
| | | }, |
| | | changeParam(e) { |
| | | this.scrollToInput(0); |
| | | }, |
| | | /** |
| | | * 页面相关事件处理函数--监听用户下拉动作 |
| | | */ |