// parents/pages/home/home.js import { routers, viewImage, sharePage, isFn, getGlobalVal, getWxLocationSetting } from '../../../utils/util.js' import { GetLibrary, GetParentHome, GetBorrowBookNum, ScanningBooks, GoodIndex, ScanningBackBooks,IndexBarList} from '../../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData, hasLibraryService, hasVipService } = getApp() const { baseImgUrl, qrcodeInvalidToastText } = globalData Page({ /** * 页面的初始数据 */ data: { baseImgUrl, isFirst: 0, latitude: '', longitude: '', isLoaded: 0, pageNo: 1, pageSize: 10, vipId:'ea4e93ee-8b22-41bd-bb09-ec36e88eab78', carouselList: ['../../../assets/main_banner1.png', '../../../assets/banner1.png'], // 签到签离 sign: [ { icon: '../../../assets/sign_in.png', text: '签到', url: 'president/pages/sign_leave_in/sign_leave_in?isSignin=1', zindex: 3, }, { icon: '../../../assets/sign_leave.png', text: '签离', url: 'president/pages/sign_leave_in/sign_leave_in?isSignin=0', zindex: 3, }, { icon: '../../../assets/data_ansyc.png', text: '数据统计', url: 'president/pages/data_statistics/data_statistics', zindex: 3, }, ], // 图书借阅 library: [ { icon: '../../../assets/replace_record.png', text: '代办借阅', url: 'president/pages/borrow_books/borrow_books', zindex: 3, }, { icon: '../../../assets/returnBook.png', text: '还书', url: 'president/pages/Return_book_car/Return_book_car', zindex: 3, }, { icon: '../../../assets/reding_booksbank.png', text: '馆内阅读排行榜', url: 'president/pages/ranking/ranking', zindex: 3, }, ], // 书籍调配 Books: [ { icon: '../../../assets/library_books.png', text: '在馆书籍', url: 'president/pages/library_books/library_books', zindex: 3, }, { icon: '../../../assets/goodboos_icon.png', text: '好书推荐', url: 'president/pages/good_books_new/good_books_new', zindex: 3, }, { icon: '../../../assets/allot_lists.png', text: '调书清单', url: 'president/pages/book_inventory/book_inventory', zindex: 3, }, ], topList: [], list: [], footerData: { actIndex: 0, 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.userId = getGlobalVal('userId') options.library = getGlobalVal('library') options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : '' const returnbookList = getGlobalVal(`returnBook_${options.userId}_${options.libId}`) || [] console.log(`returnBook_${options.userId}_${options.libId}`) console.log(returnbookList) this.setData({ options, isFirst: 1 }) this.getIndexBarList() }, /** * 生命周期函数--监听页面初次渲染完成 */ 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 () { // this.getList(res => { // wx.stopPullDownRefresh() // }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { if (isFn(sharePage)) return sharePage() }, /** * 获取首页数据 */ getList: function (cb) { const continuousFn = { fn: this.getList, param: { ...arguments } } const libId = this.data.options.library.id || '' // hasLibraryService() if (!libId) { wx.showToast({ title: '请先定位图书馆', icon: 'none' }) return } GoodIndex({ data: { libId }, continuousFn }).then(res => { const { list } = res.data const listTemp = (res => { for (let i in res) { if (res[i].summary.length>30){ res[i].summary = res[i].summary.slice(0, 30) + '...' }else{ res[i].summary = res[i].summary } } return res })(list) // console.log(listTemp,list) this.setData({ list: listTemp }) cb && cb(res) }).catch(res => { cb && cb(res) }) }, /** * 获取定位 */ getLocation: function (cb) { getWxLocationSetting(res => { this.setData({ isShowPosition: false }) wx.showLoading({ title: '定位中' }) wx.getLocation({ type: 'wgs84', success: res => { const { latitude, longitude } = res this.setData({ latitude, longitude }) this.getLibrary(cb) }, fail: res => { wx.showToast({ title: '定位失败', icon: 'none' }) }, complete: res => { wx.hideLoading() } }) }) }, /** * 获取图书馆 */ getLibrary: function (cb) { const continuousFn = { fn: this.getLibrary, param: { ...arguments } } const { options, latitude, longitude, pageNo, pageSize } = this.data const { vipId } = options GetLibrary({ data: { vipId, pageNo, pageSize, leagueLat: latitude, leagueLng: longitude }, continuousFn }).then(res => { const { list } = res.data if (list[0]['id']) { getApp().globalData.library = list[0] wx.setStorageSync('library', list[0]) this.setData({ 'options.library': list[0] }) this.getList(cb) } }) }, /** * 获取首页图片 */ getIndexBarList: function (cb) { const continuousFn = { fn: this.getIndexBarList, param: { ...arguments } } const { options, latitude, longitude, pageNo, pageSize } = this.data const { vipId } = options IndexBarList({ data: { vipId, pageNo, pageSize, leagueLat: latitude, leagueLng: longitude }, continuousFn }).then(res => { const { imgList } = res.data this.setData({ imgList, isLoaded: 1}) }) }, /** * 签到签离选择跳转进入页 */ selectRouteCtl: function (e) { const { index } = e.currentTarget.dataset const { sign } = this.data const { url, zindex } = sign[index] // if(index==0){ // this.scanCtl() // }else{ // if (!hasVipService()) return navigateTo({ url, zindex }) // } }, /** * 图书借阅选择跳转进入页 */ selectRouteCtlBorrow: function (e) { const { index } = e.currentTarget.dataset const { library, options } = this.data const { url, zindex } = library[index] const returnbookList = getGlobalVal(`returnBook_${options.userId}_${options.libId}`) || [] console.log(`returnBook_${options.userId}_${options.libId}`) console.log(returnbookList) if(index==1){ if (returnbookList.length > 0) { navigateTo({ url: 'president/pages/Return_book_car/Return_book_car', paras: { } }) return } if (returnbookList.length == 0) { this.scanFn() } }else{ navigateTo({ url, zindex }) } }, /** * 书籍调配选择跳转进入页 */ selectRouteCtlBooks: function (e) { const { index } = e.currentTarget.dataset const { Books } = this.data const { url, zindex } = Books [index] // if(index==0){ // this.scanCtl() // }else{ // if (!hasVipService()) return navigateTo({ url, zindex }) // } }, /** * 调用微信扫一扫 */ scanFn: function () { wx.scanCode({ success: res => { const url = res.result const detailsId = url.split('_')[1].split('.')[0] if (!detailsId) { wx.showToast({ title: qrcodeInvalidToastText, icon: 'none' }) return } this.scanningBooksFn(detailsId) } }) }, /** * 扫一扫借书 */ scanningBooksFn: function (detailsId) { const continuousFn = { fn: this.scanningBooksFn, param: { ...arguments } } const { libId } = this.data.options const { returnbookList } = this.data ScanningBackBooks({ data: { detailsId, libId }, continuousFn }).then(res => { const { detailsId } = res.data; for (var i in returnbookList) { if (detailsId == returnbookList[i].detailsId) { wx.showToast({ title: '此二维码已经扫过', icon: 'none' }) } } if (detailsId) { navigateTo({ url: 'president/pages/Return_book_car/Return_book_car', paras: { ...res.data } }) } }).catch(res => { wx.showToast({ title: res.msg, icon: 'none' }) }) } })