123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- // dispatcher/pages/dispatch_go/dispatch_go.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
- import { DispatcherScanning, DeleteSweepedBooks } from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData } = getApp()
- const { baseImgUrl, thumbnail, qrcodeInvalidToastText } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- thumbnail,
- type: 2,
- isShowToast: false,
- toastImage: '',
- toastTitle: '',
- footerData: {
- actIndex: 0,
- list: [
- {
- text: '送书到馆',
- icon: '../../../assets/song_shu_dao_guan_gray.png',
- actIcon: '../../../assets/song_shu_dao_guan_blue.png',
- url: 'dispatcher/pages/dispatch_go/dispatch_go',
- zindex: 3
- },
- {
- text: '带书离馆',
- icon: '../../../assets/dai_shu_li_guan_gray.png',
- actIcon: '../../../assets/dai_shu_li_guan_blue.png',
- url: 'dispatcher/pages/dispatch_leave/dispatch_leave',
- zindex: 3
- },
- {
- text: '我的',
- icon: '../../../assets/me_gray.png',
- actIcon: '../../../assets/me_blue.png',
- url: 'dispatcher/pages/me/me',
- zindex: 3
- }
- ]
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- options.userId = getGlobalVal('userId')
- options.libId = (options.libId ? options.libId : getGlobalVal(`dispatchLibId_${options.userId}`) ? getGlobalVal(`dispatchLibId_${options.userId}`) : '')
- this.setData({ options })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- 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 () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 扫书
- */
- scanCtl: 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.dispatcherScanningFn(detailsId)
- }
- })
- },
- /**
- * 再次调用扫一扫
- */
- scanAgain: function () {
- this.setTimeoutFn = setTimeout(() => {
- this.setData({ isShowToast: false })
- this.scanCtl()
- }, 2000)
- },
- /**
- * 再次调用扫一扫
- */
- cancelScanAgain: function () {
- if (this.setTimeoutFn) clearTimeout(this.setTimeoutFn)
- },
- /**
- * 送书离馆
- */
- dispatcherScanningFn: function (detailsId) {
- const continuousFn = { fn: this.dispatcherScanningFn, param: { ...arguments } }
- const { options = {}, type = 0 } = this.data
- const { libId = '' } = options
- DispatcherScanning({ data: { detailsId, libId, type }, continuousFn }).then(res => {
- const { bookImg = '', title = '', id = '' } = res.data
- this.setData({ toastImage: bookImg, toastTitle: title, ids: [id], isShowToast: true })
- this.scanAgain()
- }).catch(res => {
- wx.showToast({
- title: res.msg,
- icon: 'none'
- })
- })
- },
- /**
- * 删除
- */
- delCtl: function () {
- const continuousFn = { fn: this.delCtl, param: { ...arguments } }
- const { options = {}, type = 0, ids = [] } = this.data
- const { libId = '' } = options
- this.cancelScanAgain()
- if (!ids.length) {
- wx.showToast({
- title: '请先选中要删除的图书',
- icon: 'none'
- })
- return
- }
- DeleteSweepedBooks({ data: { ids, libId, type }, continuousFn }).then(res => {
- this.setData({ isShowToast: false })
- wx.showToast({
- title: '取消成功',
- })
- })
- },
- })
|