// pages/teaching/teaching.js import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js' import { BookList} from '../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp() const { baseImgUrl, thumbnail } = globalData const app = getApp() Page({ /** * 页面的初始数据 */ data: { pageNo:1, pageSize:10, isTeaching:false, list:[ { subject:'语文', imgUrl:'../../assets/yuwen.png', bookList:[] }, { subject: '数学', imgUrl: '../../assets/shuxue.png', bookList: [] }, { subject: '英语', imgUrl: '../../assets/yingyu.png', bookList: [] } ], teachList: [ // { // "bookId": "133b94c0-dfdb-3e70-b406-32f80922e4bb", // "bookName": "黄冈作业本1", // "subject": "语文", // "version": 1, // "versionName": "人教版" // }, // { // "bookId": "133b94c0-dfdb-3e70-b406-32f80922e4bb", // "bookName": "黄冈作业本2", // "subject": "语文", // "version": 1, // "versionName": "人教版" // }, // { // "bookId": "133b94c0-dfdb-3e70-b406-32f80922e4bb", // "bookName": "黄冈作业本3", // "subject": "语文", // "version": 1, // "versionName": "人教版" // }, // { // "bookId": "133b94c0-dfdb-3e70-b406-32f80922e4bb", // "bookName": "黄冈作业本4", // "subject": "语文", // "version": 1, // "versionName": "人教版" // } ], bookId:'', subject:'' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData(options) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { const obj = { navigateTo, redirectTo, navigateBack, viewImage } for (const i in obj) { this[i] = obj[i] } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { const { isTeaching } = this.data if (isTeaching) { this.setData({ pageNo: 1 }) this.getTeachingList(res => { wx.stopPullDownRefresh() }) } }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { const { isAll, isTeaching } = this.data if (isAll) { return } if (isTeaching) { this.getTeachingList() } }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /** * 跳转 */ navigateCtl: app.navigateCtl, /** * 底部导航跳转 */ redirectCtl: app.redirectCtl, /** * 查询书名 */ inputCtl: function (e) { const { value } = e.detail this.setData({ bookName: value }) this.getTeachingList() }, /** * 选择教辅 */ selectTeach:function(e){ const { grade, subject } = e.currentTarget.dataset.method this.setData({ isTeaching: true, grade, subject }) this.getTeachingList() }, /** * 获取教辅 */ getTeachingList: function () { const continuousFn = { fn: this.getTeachingList, param: { ...arguments } } let { pageNo, pageSize, grade, subject, list = [], bookName } = this.data BookList({ data: { grade, bookName, subject, pageNo, pageSize }, continuousFn }).then(res => { if (pageNo == 1) { list = res.data.list } else { list = list.concat(res.data.list) } this.setData({ teachList:list, pageNo: list.length == pageSize * pageNo ? pageNo + 1 : pageNo, isAll: list.length < pageSize }) if (isFn(cb)) cb() }).catch(res => { if (isFn(cb)) cb() }) }, /** * 获取教辅 */ getTeaching: function (e) { const { bookId, subject, bookName} = e.currentTarget.dataset.method let { list = [], teachList} = this.data var items = { bookId, subject, bookName }; var temp = {}; for (var i in list) { if (list[i].subject === subject) { list[i].bookList.push(items) } } wx.setStorageSync('list', list) this.setData({ list, isTeaching: false}) }, /** * 本地获取教辅 */ localTeaching:function(){ const { isAdd}=this.data; var that=this; console.log(isAdd) if (isAdd=="true"){ var list =wx.getStorageSync('list'); wx.setStorageSync('list', list) that.setData({ list }) }else{ const { list } = that.data; wx.setStorageSync('list', list) that.setData({ list }) } }, /** * 删除 */ deleteBook:function(e){ const { index, key } = e.currentTarget.dataset; const {list}=this.data; list[index].bookList.splice(key, 1) wx.setStorageSync('list', list) this.setData({list}) } })