apply_bookform.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // parents/pages/apply_bookform/apply_bookform.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDate } from '../../../utils/util.js'
  3. import { GetVipInfo, UploadFile, SaveVipInfo, PostApplyBookList } 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: 'infofrominput',
  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. // getData: function (cb) {
  95. // const continuousFn = { fn: this.getData, param: { ...arguments } }
  96. // if (!hasVipService()) {
  97. // cb && cb()
  98. // return
  99. // }
  100. // const { vipId } = this.data.options
  101. // GetVipInfo({ data: { vipId }, continuousFn }).then(res => {
  102. // this.setData({ vip: { ...res.data } })
  103. // cb && cb(res)
  104. // }).catch(res => {
  105. // cb && cb(res)
  106. // })
  107. // },
  108. /**
  109. * 上传头像
  110. */
  111. uploadImgCtl: function () {
  112. const continuousFn = { fn: this.uploadImgCtl, param: { ...arguments } }
  113. wx.chooseImage({
  114. count: 1,
  115. success: res => {
  116. UploadFile({ file: res.tempFilePaths, continuousFn }).then(res => {
  117. this.setData({ bookImg: res[0] })
  118. })
  119. }
  120. })
  121. },
  122. /**
  123. * 保存输入值
  124. */
  125. inputCtl: function (e) {
  126. const { value } = e.detail
  127. const { type } = e.currentTarget.dataset
  128. const { bookList } = this.data
  129. var temp={}
  130. // bookList[type] = value
  131. temp[`${type}`] = value
  132. // console.log(temp)
  133. this.setData(temp)
  134. },
  135. /**
  136. * 提交按钮
  137. */
  138. submitCtl: function (e) {
  139. const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
  140. const { libId } = this.data.options;
  141. const { type } = e.currentTarget.dataset
  142. const { bookList, bookImg, title, publish, paiDate, bookSrc, infofromstorage } = this.data
  143. if (type == 1) {
  144. wx.navigateBack({
  145. delta: 1
  146. })
  147. } else if (type == 2) {
  148. if (!title) {
  149. wx.showToast({
  150. title: '请输入书名',
  151. icon: 'none'
  152. })
  153. return
  154. }
  155. if (!publish) {
  156. wx.showToast({
  157. title: '请输入出版社作者',
  158. icon: 'none'
  159. })
  160. return
  161. }
  162. if (!bookSrc) {
  163. wx.showToast({
  164. title: '请填写书目来源',
  165. icon: 'none'
  166. })
  167. return
  168. }
  169. // 存储本地
  170. const bookList = infofromstorage || []
  171. bookList.push({
  172. bookImg,
  173. title,
  174. publish,
  175. paiDate,
  176. bookSrc
  177. })
  178. wx.setStorageSync('infofrominput', bookList)
  179. wx.showToast({
  180. title: '保存成功',
  181. })
  182. setTimeout(() => {
  183. navigateBack()
  184. }, 2000)
  185. // PostApplyBookList({ data: { ...bookList, libId }, continuousFn }).then(res => {
  186. // // 存储本地
  187. // const localbookList = []
  188. // localbookList.push({
  189. // bookList
  190. // })
  191. // wx.setStorageSync('infofrominput', localbookList)
  192. // wx.showToast({
  193. // title: '保存成功',
  194. // })
  195. // setTimeout(() => {
  196. // navigateBack()
  197. // }, 2000)
  198. // })
  199. }
  200. },
  201. /**
  202. * 清除图片
  203. */
  204. deleteImg:function(){
  205. this.setData({ bookImg:''})
  206. }
  207. })