apply_bookform.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // parents/pages/apply_bookform/apply_bookform.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDate } from '../../../utils/util.js'
  3. import { UploadFile, ApplyBook } 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. Selectdate:'',
  15. bookList: [],
  16. gradeIndex: 0,
  17. startTime: formatDate(new Date()),
  18. sexIndex: 0,
  19. paiDate: formatDate(new Date()),
  20. footerArray: [
  21. {
  22. type: 1,
  23. text: '取消'
  24. },
  25. {
  26. type: 2,
  27. text: '保存'
  28. }
  29. ]
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
  36. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  37. this.setData({ options })
  38. // this.getData(res => {
  39. // this.setData({ isLoaded: 1 })
  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. let _this = this
  56. wx.getStorage({
  57. key: 'parentsList',
  58. success: function (res) {
  59. _this.setData({
  60. infofromstorage: res.data,
  61. })
  62. }
  63. })
  64. },
  65. /**
  66. * 生命周期函数--监听页面隐藏
  67. */
  68. onHide: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面卸载
  72. */
  73. onUnload: function () {
  74. },
  75. /**
  76. * 页面相关事件处理函数--监听用户下拉动作
  77. */
  78. onPullDownRefresh: function () {
  79. },
  80. /**
  81. * 页面上拉触底事件的处理函数
  82. */
  83. onReachBottom: function () {
  84. },
  85. /**
  86. * 用户点击右上角分享
  87. */
  88. onShareAppMessage: function () {
  89. if (isFn(sharePage)) return sharePage()
  90. },
  91. /**
  92. * 上传头像
  93. */
  94. uploadImgCtl: function () {
  95. const continuousFn = { fn: this.uploadImgCtl, param: { ...arguments } }
  96. wx.chooseImage({
  97. count: 1,
  98. success: res => {
  99. UploadFile({ file: res.tempFilePaths, continuousFn }).then(res => {
  100. this.setData({ bookImg: res[0] })
  101. })
  102. }
  103. })
  104. },
  105. /**
  106. * 保存输入值
  107. */
  108. inputCtl: function (e) {
  109. const { value } = e.detail
  110. const { type } = e.currentTarget.dataset
  111. const { bookList } = this.data
  112. var temp={}
  113. // bookList[type] = value
  114. temp[`${type}`] = value
  115. // console.log(temp)
  116. this.setData(temp)
  117. },
  118. /**
  119. * 提交按钮
  120. */
  121. submitCtl: function (e) {
  122. const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
  123. const { libId } = this.data.options;
  124. const { type } = e.currentTarget.dataset
  125. const { bookList, bookImg, title, publisher, author, applyReason, infofromstorage } = this.data
  126. if (type == 1) {
  127. wx.navigateBack({
  128. delta: 1
  129. })
  130. } else if (type == 2) {
  131. if (!title) {
  132. wx.showToast({
  133. title: '请输入书名',
  134. icon: 'none'
  135. })
  136. return
  137. }
  138. if (!applyReason) {
  139. wx.showToast({
  140. title: '请输入申请原因 ',
  141. icon: 'none'
  142. })
  143. return
  144. }
  145. // 存储本地
  146. const bookList = infofromstorage || []
  147. bookList.push({
  148. bookImg,
  149. title,
  150. publisher,
  151. author,
  152. applyReason
  153. })
  154. wx.setStorageSync('parentsList', bookList)
  155. wx.showToast({
  156. title: '保存成功',
  157. })
  158. setTimeout(() => {
  159. navigateBack()
  160. }, 2000)
  161. }
  162. },
  163. /**
  164. * 清除图片
  165. */
  166. deleteImg:function(){
  167. this.setData({ bookImg:''})
  168. }
  169. })