wish_detail.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // parents/pages/wish_detail/wish_detail.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { WishBookDetail, WishHelp } 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: 0,
  14. userlist: [],
  15. book: {
  16. summary: '',
  17. local_image: '',
  18. author: '',
  19. title: '',
  20. cishu: ''
  21. },
  22. ishelp: 0,
  23. vipInfo: {
  24. photo: '',
  25. childName: '',
  26. wishWords: ''
  27. }
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. this.setData({ options })
  34. this.getData(res => {
  35. this.setData({ isLoaded: 1 })
  36. })
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload: function () {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh: function () {
  62. },
  63. /**
  64. * 页面上拉触底事件的处理函数
  65. */
  66. onReachBottom: function () {
  67. },
  68. /**
  69. * 用户点击右上角分享
  70. */
  71. onShareAppMessage: function () {
  72. const { vipInfo, options } = this.data
  73. const { vipId, isbn13, libId } = options
  74. const { childName } = vipInfo
  75. return {
  76. title: `${childName}的心愿书单详情`,
  77. path: `parents/pages/wish_detail/wish_detail?type=10&vipId=${vipId}&isbn13=${isbn13}&libId=${libId}`,
  78. success: res => {
  79. wx.showToast({
  80. title: '转发成功',
  81. icon: 'success'
  82. })
  83. }
  84. }
  85. },
  86. /**
  87. * 获取心愿详情
  88. */
  89. getData: function (cb) {
  90. const continuousFn = { fn: this.getData, param: { ...arguments } }
  91. const { isbn13, libId, vipId } = this.data.options
  92. WishBookDetail({ data: { isbn13, libId, vipId }, continuousFn }).then(res => {
  93. const { userlist, book, vipInfo, ishelp } = res.data
  94. const { cishu, isbn13 } = book
  95. if (cishu == 0) {
  96. wx.showToast({
  97. title: '此本书籍已助力成功,私塾家正在为您所在的图书馆配置入书单,书到馆后您可进行借阅或预约',
  98. icon: 'none'
  99. })
  100. setTimeout(() => {
  101. redirectTo({ url: 'parents/pages/book_detail/book_detail', paras: { isbn13 }, zindex: 3 })
  102. }, 1200)
  103. }
  104. this.setData({ userlist, book: { ...book }, vipInfo: { ...vipInfo }, ishelp })
  105. cb && cb(res)
  106. }).catch(res => {
  107. cb && cb(res)
  108. })
  109. },
  110. /**
  111. * 助力
  112. */
  113. helpWishCtl: function (e) {
  114. const continuousFn = { fn: this.helpWishCtl, param: { ...arguments } }
  115. const { book, options } = this.data
  116. const { vipId, isbn13, libId } = options
  117. WishHelp({ data: { vipId, isbn13, libId }, continuousFn }).then(res => {
  118. wx.showToast({
  119. title: '助力成功'
  120. })
  121. this.setData({ ishelp: 1 })
  122. })
  123. }
  124. })