book_month.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // president/pages/book_inventory/book_inventory.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { CallInList} from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. thumbnail,
  14. isLoaded: 0,
  15. bookList: [
  16. {
  17. bookExchangeNum: '',
  18. bookInNum: ''
  19. }
  20. ],
  21. isDown:false,
  22. navIndex: 0,
  23. pageSize: 10,
  24. pageNo: 1,
  25. nodataArray: {
  26. text: "暂无数据"
  27. }
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  34. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  35. this.setData(options)
  36. wx.showToast({
  37. title: '请耐心等待,工作人员正在火速调配中',
  38. icon: 'none',
  39. duration: 3000
  40. })
  41. },
  42. /**
  43. * 生命周期函数--监听页面初次渲染完成
  44. */
  45. onReady: function () {
  46. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  47. for (const i in obj) {
  48. this[i] = obj[i]
  49. }
  50. },
  51. /**
  52. * 生命周期函数--监听页面显示
  53. */
  54. onShow: function () {
  55. const show = wx.getStorageSync('hiddenGetallModel')
  56. this.setData({ hiddenGetallModel: show })
  57. this.getData(() => {
  58. this.setData({ pageNo:1})
  59. })
  60. },
  61. /**
  62. * 生命周期函数--监听页面隐藏
  63. */
  64. onHide: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面卸载
  68. */
  69. onUnload: function () {
  70. },
  71. /**
  72. * 页面相关事件处理函数--监听用户下拉动作
  73. */
  74. onPullDownRefresh: function () {
  75. const temp = {}
  76. temp[`navList[${navIndex}].pageNo`] = 1
  77. this.setData(temp)
  78. this.getData(() => {
  79. wx.stopPullDownRefresh()
  80. })
  81. },
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom: function () {
  86. const { isAll, isDown } = this.data
  87. if (isAll) {
  88. this.setData({ isDown: true })
  89. return
  90. } else {
  91. this.setData({ isLoad: true, isDown: false })
  92. this.getData(() => {
  93. this.setData({ isLoad: false })
  94. })
  95. }
  96. },
  97. /**
  98. * 用户点击右上角分享
  99. */
  100. onShareAppMessage: function () {
  101. if (isFn(sharePage)) return sharePage()
  102. },
  103. /**
  104. * 提示框隐藏
  105. */
  106. allShowModel: function () {
  107. wx.setStorageSync('hiddenGetallModel', false)
  108. this.setData({ hiddenGetallModel: false })
  109. },
  110. /**
  111. * 调入与调出
  112. */
  113. getData: function (cb) {
  114. const continuousFn = { fn: this.getData, param: { ...arguments } }
  115. const { pageNo, pageSize, libId,callType} = this.data
  116. CallInList({ data: { libId, pageNo, pageSize, callType: Number(callType) }, continuousFn}).then(res => {
  117. const { readNum = 0, bookExchangeNum = 0, booksSize = 0,bookInNum = 0, isSend = false } = res.data
  118. const { list } = res.data
  119. const correctListTemp = (res => {
  120. console.log(res)
  121. var d = []
  122. for (let i in res) {
  123. res[i].number = res[i].select_size
  124. }
  125. return res
  126. })(list)
  127. let listTemp = []
  128. if (pageNo == 1) {
  129. listTemp = [].concat(correctListTemp)
  130. } else {
  131. listTemp = [].concat(this.data.list, correctListTemp)
  132. }
  133. console.log(listTemp)
  134. this.setData({
  135. bookExchangeNum,
  136. bookInNum,
  137. list: listTemp,
  138. pageNo: list.length == pageSize ? pageNo + 1 : pageNo,
  139. isAll: list.length < pageSize,
  140. isLoaded: true
  141. })
  142. if (isFn(cb)) cb()
  143. }).catch(res => {
  144. this.setData({ isLoaded: true })
  145. if (isFn(cb)) cb()
  146. })
  147. }
  148. })