dispatch_leave.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // dispatcher/pages/dispatch_leave/dispatch_leave.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { DispatcherScanning } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. type: 1,
  14. footerData: {
  15. actIndex: 1,
  16. list: [
  17. {
  18. text: '送书到馆',
  19. icon: '../../../assets/song_shu_dao_guan_gray.png',
  20. actIcon: '../../../assets/song_shu_dao_guan_blue.png',
  21. url: 'dispatcher/pages/dispatch_go/dispatch_go',
  22. zindex: 3
  23. },
  24. {
  25. text: '带书离馆',
  26. icon: '../../../assets/dai_shu_li_guan_gray.png',
  27. actIcon: '../../../assets/dai_shu_li_guan_blue.png',
  28. url: 'dispatcher/pages/dispatch_leave/dispatch_leave',
  29. zindex: 3
  30. },
  31. {
  32. text: '我的',
  33. icon: '../../../assets/me_gray.png',
  34. actIcon: '../../../assets/me_blue.png',
  35. url: 'dispatcher/pages/me/me',
  36. zindex: 3
  37. }
  38. ]
  39. }
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. options.userId = getGlobalVal('userId')
  46. options.libId = (options.libId ? options.libId : getGlobalVal(`dispatchLibId_${options.userId}`) ? getGlobalVal(`dispatchLibId_${options.userId}`) : '')
  47. this.setData({ options })
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady: function () {
  53. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  54. for (const i in obj) {
  55. this[i] = obj[i]
  56. }
  57. },
  58. /**
  59. * 生命周期函数--监听页面显示
  60. */
  61. onShow: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function () {
  72. },
  73. /**
  74. * 页面相关事件处理函数--监听用户下拉动作
  75. */
  76. onPullDownRefresh: function () {
  77. },
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom: function () {
  82. },
  83. /**
  84. * 用户点击右上角分享
  85. */
  86. onShareAppMessage: function () {
  87. if (isFn(sharePage)) return sharePage()
  88. },
  89. /**
  90. * 扫书
  91. */
  92. scanCtl: function () {
  93. wx.scanCode({
  94. success: res => {
  95. const url = res.result
  96. const detailsId = url.split('_')[1].split('.')[0]
  97. if (!detailsId) {
  98. wx.showToast({
  99. title: qrcodeInvalidToastText,
  100. icon: 'none'
  101. })
  102. return
  103. }
  104. this.dispatcherScanningFn(detailsId)
  105. }
  106. })
  107. },
  108. /**
  109. * 送书离馆
  110. */
  111. dispatcherScanningFn: function (detailsId) {
  112. const continuousFn = { fn: this.dispatcherScanningFn, param: { ...arguments } }
  113. const { options = {}, type = 0 } = this.data
  114. const { libId = '' } = options
  115. DispatcherScanning({ data: { detailsId, libId, type }, continuousFn }).then(res => {
  116. wx.showToast({
  117. title: '扫书成功',
  118. icon: 'success'
  119. })
  120. setTimeout(() => {
  121. this.scanCtl()
  122. }, 2000)
  123. }).catch(res => {
  124. wx.showToast({
  125. title: res.msg,
  126. icon: 'none'
  127. })
  128. })
  129. }
  130. })