123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- // parents/pages/reservations/reservations.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
- import { ToReservation, AlreadyReservation, AddWishBooks } from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData, hasLibraryService, hasVipService } = getApp()
- const { baseImgUrl, qrcodeInvalidToastText } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- isLoaded: 0,
- content: '',
- navIndex: 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: '去书库看看'
- }
- }
- ]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
- options.libId = getGlobalVal('library').id || ''
- this.setData({ options })
- this.getData(res => {
- this.setData({ isLoaded: 1 })
- })
- this.getDataTwo()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- 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.getData(res => {
- wx.stopPullDownRefresh()
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 获取数据
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getData, param: { ...arguments } }
- if (!hasVipService()) {
- cb && cb()
- return
- }
- if (!hasLibraryService()) {
- cb && cb()
- return
- }
- const { navIndex, navList, options, content } = this.data
- const { vipId, libId } = options
- const Fn = [ToReservation, AlreadyReservation]
- const data = [{ content, libId }, { vipId, libId }]
- Fn[navIndex]({ data: data[navIndex], continuousFn }).then(res => {
- navList[navIndex]['list'] = res.data.list
- if (navIndex == 1) {
- navList[navIndex]['num'] = res.data.list.length
- }
- this.setData({ navList })
- cb && cb()
- }).catch(res => {
- cb && cb()
- })
- },
- /**
- * 获取数据
- */
- getDataTwo: function (cb) {
- const continuousFn = { fn: this.getDataTwo, param: { ...arguments } }
- if (!hasVipService() || !hasLibraryService()) {
- cb && cb()
- return
- }
- const { navList, options } = this.data
- const { vipId, libId } = options
- AlreadyReservation({ data: { vipId, libId }, continuousFn }).then(res => {
- navList[1]['list'] = res.data.list
- this.setData({ navList })
- cb && cb()
- }).catch(res => {
- cb && cb()
- })
- },
- /**
- * 选择导航栏
- */
- selectNavCtl: function (e) {
- const { index } = e.currentTarget.dataset
- const { navIndex, navList } = this.data
- if (navIndex == index) return
- this.setData({ navIndex: index })
- if (index == 0) {
- if (navList[index]['list'].length == 0) {
- this.getData()
- }
- } else if (index == 1) {
- this.getData()
- }
- },
- /**
- * 输入搜索值
- */
- inputSearchCtl: function (e) {
- const { value } = e.detail
- const { content } = this.data
- if (content == value) return
- this.setData({ content: value })
- },
- /**
- * 清除搜索值
- */
- clearSearchCtl: function () {
- this.setData({ content: '' })
- },
- /**
- * 提交搜索值
- */
- submitSearchCtl: function () {
- this.getData()
- },
- /**
- * 预约书籍
- */
- reservationsCtl: function (e) {
- const continuousFn = { fn: this.reservationsCtl, param: { ...arguments } }
- if (!hasVipService() || !hasLibraryService()) return
- const { index } = e.currentTarget.dataset
- const { navIndex, navList, options } = this.data
- const { vipId, libId } = options
- const { isbn13 } = navList[navIndex]['list'][index]
- AddWishBooks({ data: { isbn13, libId, type: 3, vipId }, continuousFn }).then(res => {
- wx.showToast({
- title: '预约成功'
- })
- this.getData()
- })
- },
- /**
- * 没有数据模板按钮触发事件
- */
- nodataBtnCtl: function () {
- redirectTo({ url: 'parents/pages/home/home', zindex: 3 })
- }
- })
|