dispatch_go.js 4.3 KB

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