// parents/pages/reservations/reservations.js import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js' import { LibVipList, ManagerList } from '../../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData, hasLibraryService, hasVipService } = getApp() const { baseImgUrl, thumbnail,qrcodeInvalidToastText } = globalData Page({ /** * 页面的初始数据 */ data: { baseImgUrl, thumbnail, isLoaded: 1, content: '', navIndex: 0, pageNo:1, pageSize:10, isAll:0, index: 0, isDown: false, list:[], managerList:[], isreturn:0, navList: [ { text: '会员管理', list: [], nodataArray: { text: '暂没有预约书单', image: '../../../assets/nodata_3.png', hasNodataBtn: 1, btnText: '去书库看看' } }, { text: '馆内人员管理', list: [], nodataArray: { text: '暂没有已预约书单', image: '../../../assets/nodata_2.png', hasNodataBtn: 1, btnText: '去书库看看' } } ], footerData: { actIndex: 1, list: [ { text: '日常事务', icon: '../../../assets/lock_gary.png', actIcon: '../../../assets/lock_blue.png', url: 'president/pages/home/home', zindex: 3, }, { text: '人员管理', icon: '../../../assets/people_manager_gary.png', actIcon: '../../../assets/people_manager_blue.png', url: 'president/pages/Personnel_management/Personnel_management', zindex: 3, }, { text: '我的', icon: '../../../assets/me_gray.png', actIcon: '../../../assets/me_blue.png', url: 'president/pages/me/me', zindex: 3, } ] } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : '' wx.setNavigationBarTitle({ title: `人员管理`, }) 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 { isAll, options } = this.data const { type = 1 } = options if (type == 1) return this.setData({ pageNo: 1 }) this.getData(res => { 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() }, pickChange: function (e) { this.setData({ index: e.detail.value }); }, /** * 会员管理获取数据 */ getData: function (cb) { const continuousFn = { fn: this.getData, param: { ...arguments } } // if (!hasVipService()) { // cb && cb() // return // } // if (!hasLibraryService()) { // cb && cb() // return // } const { navIndex, navList, options, pageSize, pageNo, libId } = this.data LibVipList({ data: { pageSize, pageNo, libId,}, continuousFn }).then(res => { const { list, pages, todayAdd } = res.data const oneTemp = (res => { for (let i in res) { for (let j in res[i].valueList){ if (res[i].valueList[j].summary.length > 30) { res[i].valueList[j].summary = res[i].valueList[j].summary.slice(0, 30) + '...' } else { res[i].valueList[j].summary = res[i].valueList[j].summary } } } return res })(list) let listTemp = [] if (pageNo == 1) { listTemp = [].concat(oneTemp) } else { listTemp = [].concat(that.data.list, oneTemp) } this.setData({ list: listTemp, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize , pages: pages, todayAdd: todayAdd }) cb && cb() }).catch(res => { cb && cb() }) }, /** * 馆内人员管理获取数据 */ getLibraryData: function (cb) { const continuousFn = { fn: this.getData, param: { ...arguments } } // if (!hasVipService()) { // cb && cb() // return // } // if (!hasLibraryService()) { // cb && cb() // return // } const { navIndex, navList, options, pageSize, pageNo, libId } = this.data ManagerList({ data: { pageSize, pageNo, libId, }, continuousFn }).then(res => { const { managerList, pages } = res.data // debugger const oneTemp = (res => { for (let i in res) { for (let j in res[i].valueList) { if (res[i].valueList[j].summary.length > 30) { res[i].valueList[j].summary = res[i].valueList[j].summary.slice(0, 30) + '...' } else { res[i].valueList[j].summary = res[i].valueList[j].summary } } } return res })(managerList) let listTemp = [] if (pageNo == 1) { listTemp = [].concat(oneTemp) } else { listTemp = [].concat(that.data.managerList, oneTemp) } this.setData({ managerList: listTemp, pageNo: managerList.length == pageSize ? pageNo + 1 : pageNo, isAll: managerList.length < pageSize, managerpages: pages, }) cb && cb() }).catch(res => { cb && cb() }) }, /** * 选择导航栏 */ selectNavCtl: function (e) { const { index } = e.currentTarget.dataset const { navIndex, navList, isreturn } = this.data if (navIndex == index) return this.setData({ navIndex: index }) if (index == 0) { this.setData({ isreturn: 0 }) if (navList[index]['list'].length == 0) { this.getData() } } else if (index == 1) { this.setData({ isreturn: 1 }) this.getLibraryData() } }, })