book_entry.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // parents/pages/information/information.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { CheckBookCard, AddBook, UploadFile,RemoveBookLib,BackBookLib} from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService } = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isLoaded: 1,
  14. hiddenModel: false,
  15. deleteModel: false,
  16. bookInfo: {
  17. author: "",
  18. themeName:'',
  19. isbn13: "",
  20. localImage: "",
  21. libName:'',
  22. borrowName:'',
  23. price: "",
  24. grade: "",
  25. summary: "",
  26. title: ""
  27. },
  28. haveReturn:false,
  29. value:[2,1],
  30. isDetail:false,
  31. user_vipId:"",
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function (options) {
  37. options.userId = getGlobalVal('userId')
  38. options.libId = (options.libId ? options.libId : getGlobalVal(`dispatchLibId_${options.userId}`) ? getGlobalVal(`dispatchLibId_${options.userId}`) : '')
  39. this.setData({ options })
  40. const bookInfo = wx.getStorageSync("bookInfo")
  41. const detailsId = wx.getStorageSync("detailsId")
  42. this.setData({
  43. bookInfo: bookInfo,
  44. detailsId: detailsId
  45. });
  46. // options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
  47. // this.setData({ options })
  48. // this.getData(res => {
  49. // this.setData({ isLoaded: 1 })
  50. // })
  51. },
  52. /**
  53. * 生命周期函数--监听页面初次渲染完成
  54. */
  55. onReady: function () {
  56. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  57. for (const i in obj) {
  58. this[i] = obj[i]
  59. }
  60. },
  61. /**
  62. * 生命周期函数--监听页面显示
  63. */
  64. onShow: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面隐藏
  68. */
  69. onHide: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面卸载
  73. */
  74. onUnload: function () {
  75. },
  76. /**
  77. * 页面相关事件处理函数--监听用户下拉动作
  78. */
  79. onPullDownRefresh: function () {
  80. },
  81. /**
  82. * 页面上拉触底事件的处理函数
  83. */
  84. onReachBottom: function () {
  85. },
  86. /**
  87. * 提示框隐藏
  88. */
  89. allShowModel: function () {
  90. this.setData({ hiddenModel: false, deleteModel: false })
  91. },
  92. /**
  93. * 确认归还提示框打开
  94. */
  95. showModel: function () {
  96. const { haveReturn } = this.data
  97. if(haveReturn){
  98. wx.showToast({
  99. title: '本书已经归还',
  100. })
  101. }
  102. else{
  103. this.setData({ hiddenModel: true })
  104. }
  105. },
  106. /**
  107. * 解绑框打开
  108. */
  109. sureDelete: function () {
  110. this.setData({ deleteModel: true })
  111. },
  112. /**
  113. * 用户点击右上角分享
  114. */
  115. onShareAppMessage: function () {
  116. if (isFn(sharePage)) return sharePage()
  117. },
  118. /**
  119. * 获取个人资料
  120. */
  121. getData: function (cb) {
  122. const continuousFn = { fn: this.getData, param: { ...arguments } }
  123. const { user_vipId } = this.data
  124. VipInfo({ data: { vipId: user_vipId }, continuousFn }).then(res => {
  125. this.setData({ signList: { ...res.data } })
  126. cb && cb(res)
  127. }).catch(res => {
  128. cb && cb(res)
  129. })
  130. },
  131. /**
  132. * 提交按钮
  133. */
  134. operationCtl: function (e) {
  135. const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
  136. const { type } = e.currentTarget.dataset
  137. const { detailsId } = this.data
  138. if (type == 1) {
  139. RemoveBookLib({ data: {detailId:detailsId}, continuousFn }).then(res => {
  140. wx.showToast({
  141. title: '解绑成功',
  142. })
  143. this.allShowModel()
  144. setTimeout(() => {
  145. navigateBack()
  146. }, 2000)
  147. })
  148. } else if (type == 2) {
  149. BackBookLib({ data: {detailId:detailsId}, continuousFn }).then(res => {
  150. wx.showToast({
  151. title: '归还成功',
  152. })
  153. this.setData({
  154. haveReturn: true,
  155. });
  156. this.allShowModel()
  157. })
  158. }
  159. },
  160. })