// president/pages/good_books/good_books.js import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js' import { GoodBooksToRead, CallOutBooks, CallInBooks } from '../../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData } = getApp() const { baseImgUrl, thumbnail } = globalData Page({ /** * 页面的初始数据 */ data: { baseImgUrl, thumbnail, isLoaded: 0, navIndex: 0, navList: [ { text: '主题系列', title: '', list: [], stat: 1, pageSize: 5, pageNo: 1, isAll: 0, isShow: 0, itemIndex: 0, items: ['根据入馆时间排序', '根据主题总体借阅量排序'], nodataArray: { text: '暂没有本次借阅书单', image: '../../../assets/nodata_1.png', hasNodataBtn: 1, btnText: '扫码借书' } }, { text: '好书推荐', title: '', list: [], stat: 2, pageSize: 5, pageNo: 1, isAll: 0, isShow: 0, itemIndex: 0, items: ['根据入馆时间排序', '根据主题总体借阅量排序'], nodataArray: { text: '暂没有正在借阅书单', image: '../../../assets/nodata_2.png', hasNodataBtn: 1, btnText: '扫码借书' } } ], footerData: { actIndex: 1, list: [ { text: '在馆书籍', icon: '../../../assets/zai_guan_shu_ji_gray.png', actIcon: '../../../assets/zai_guan_shu_ji_blue.png', url: 'president/pages/home/home', zindex: 3 }, { text: '好书推荐', icon: '../../../assets/wish_gray.png', actIcon: '../../../assets/wish_blue.png', url: 'president/pages/good_books_new/good_books_new', zindex: 3 }, { text: '调书清单', icon: '../../../assets/diao_shu_qing_dan_gray.png', actIcon: '../../../assets/diao_shu_qing_dan_blue.png', url: 'president/pages/book_inventory/book_inventory', zindex: 3 } ] }, nodataArray: { text: "暂无数据" } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : '' this.setData({ options }) this.getData(res => { this.setData({ isLoaded: 1 }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ 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 temp = {} temp[`navList[${navIndex}].pageNo`] = 1 this.setData(temp) this.getData(() => { wx.stopPullDownRefresh() }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { const { navIndex, navList } = this.data const { isAll } = navList[navIndex] if (isAll) return this.getData() }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { if (isFn(sharePage)) return sharePage() }, /** * 选择导航栏 */ selectNavCtl: function (e) { const { index } = e.currentTarget.dataset const { navIndex, navList } = this.data if (navIndex == index) return this.setData({ navIndex: index }) const { list } = navList[index] if (list.length > 0) return this.getData() }, /** * 输入搜索值 */ inputSearchCtl: function (e) { const { value } = e.detail const { navIndex, navList } = this.data const { title } = navList[navIndex] if (title == value) return const temp = {} temp[`navList[${navIndex}].title`] = value this.setData(temp) }, /** * 清除搜索值 */ clearSearchCtl: function () { const { navIndex, navList } = this.data const temp = {} temp[`navList[${navIndex}].title`] = '' this.setData(temp) }, /** * 提交搜索值 */ submitSearchCtl: function () { const { navIndex, navList } = this.data const temp = {} temp[`navList[${navIndex}].pageNo`] = 1 this.setData(temp) this.getData() }, /** * 展示选择框 */ toggleItemCtl: function () { const { navIndex, navList } = this.data const { isShow } = navList[navIndex] const temp = {} temp[`navList[${navIndex}].isShow`] = !isShow this.setData(temp) }, /** * 展示选择框 */ selectItemCtl: function (e) { const { index } = e.currentTarget.dataset const { navIndex, navList } = this.data const { itemIndex, items } = navList[navIndex] const temp = {} temp[`navList[${navIndex}].itemIndex`] = index temp[`navList[${navIndex}].isShow`] = 0 temp[`navList[${navIndex}].pageNo`] = 1 this.setData(temp) this.getData() }, /** * 主题系列的书籍 */ getData: function (cb) { const continuousFn = { fn: this.getData, param: { ...arguments } } const { navIndex, navList } = this.data const { pageNo, pageSize, itemIndex, stat, title, list } = navList[navIndex] GoodBooksToRead({ data: { pageNo, pageSize, type: ~~itemIndex + 1, stat, title }, continuousFn }).then(res => { const newList = res.data.list let tempList = [] if (pageNo == 1) { tempList = [].concat(newList) } else { tempList = [].concat(list, newList) } const temp = {} temp[`navList[${navIndex}].list`] = tempList temp[`navList[${navIndex}].pageNo`] = newList.length == pageSize ? ~~pageNo + 1 : pageNo temp[`navList[${navIndex}].isAll`] = newList.length < pageSize this.setData(temp) cb && cb(res) }).catch(res => { cb && cb(res) }) }, /** * 调出书籍 */ getBooksCtl: function (e) { const continuousFn = { fn: this.getBooksCtl, param: { ...arguments } } const { index } = e.currentTarget.dataset const { options, navIndex, navList } = this.data const { libId } = options const { list } = navList[navIndex] const { book_detail_id, book_info_id, isbn13 } = list[index] CallInBooks({ data: { libId, bookInfoId: book_info_id, bookDetailId: book_detail_id, isbn13 }, continuousFn}).then(res => { wx.showToast({ title: `已加入调入列表` }) this.getData() }) } })