// president/pages/book_inventory/book_inventory.js import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js' import { CallInList} from '../../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData } = getApp() const { baseImgUrl, thumbnail } = globalData Page({ /** * 页面的初始数据 */ data: { baseImgUrl, thumbnail, isLoaded: 0, bookList: [ { bookExchangeNum: '', bookInNum: '' } ], isDown:false, navIndex: 0, pageSize: 10, pageNo: 1, 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) wx.showToast({ title: '请耐心等待,工作人员正在火速调配中', icon: 'none', duration: 3000 }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { const obj = { navigateTo, redirectTo, navigateBack, viewImage } for (const i in obj) { this[i] = obj[i] } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { const show = wx.getStorageSync('hiddenGetallModel') this.setData({ hiddenGetallModel: show }) this.getData(() => { this.setData({ pageNo:1}) }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { const temp = {} temp[`navList[${navIndex}].pageNo`] = 1 this.setData(temp) this.getData(() => { wx.stopPullDownRefresh() }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { const { isAll, isDown } = this.data if (isAll) { this.setData({ isDown: true }) return } else { this.setData({ isLoad: true, isDown: false }) this.getData(() => { this.setData({ isLoad: false }) }) } }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { if (isFn(sharePage)) return sharePage() }, /** * 提示框隐藏 */ allShowModel: function () { wx.setStorageSync('hiddenGetallModel', false) this.setData({ hiddenGetallModel: false }) }, /** * 调入与调出 */ getData: function (cb) { const continuousFn = { fn: this.getData, param: { ...arguments } } const { pageNo, pageSize, libId,callType} = this.data CallInList({ data: { libId, pageNo, pageSize, callType: Number(callType) }, continuousFn}).then(res => { const { readNum = 0, bookExchangeNum = 0, booksSize = 0,bookInNum = 0, isSend = false } = res.data const { list } = res.data const correctListTemp = (res => { console.log(res) var d = [] for (let i in res) { res[i].number = res[i].select_size } return res })(list) let listTemp = [] if (pageNo == 1) { listTemp = [].concat(correctListTemp) } else { listTemp = [].concat(this.data.list, correctListTemp) } console.log(listTemp) this.setData({ bookExchangeNum, bookInNum, list: listTemp, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize, isLoaded: true }) if (isFn(cb)) cb() }).catch(res => { this.setData({ isLoaded: true }) if (isFn(cb)) cb() }) } })