// parents/pages/apply_bookform/apply_bookform.js import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDate } from '../../../utils/util.js' import { UploadFile, ApplyBook } from '../../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData, hasLibraryService, hasVipService } = getApp() const { baseImgUrl, qrcodeInvalidToastText } = globalData Page({ /** * 页面的初始数据 */ data: { baseImgUrl, isLoaded: 0, Selectdate:'', bookList: [], gradeIndex: 0, startTime: formatDate(new Date()), sexIndex: 0, paiDate: formatDate(new Date()), footerArray: [ { type: 1, text: '取消' }, { type: 2, text: '保存' } ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || '' options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : '' this.setData({ options }) // this.getData(res => { // this.setData({ isLoaded: 1 }) // }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { const obj = { navigateTo, redirectTo, navigateBack, viewImage } for (const i in obj) { this[i] = obj[i] } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { let _this = this wx.getStorage({ key: 'parentsList', success: function (res) { _this.setData({ infofromstorage: res.data, }) } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { if (isFn(sharePage)) return sharePage() }, /** * 上传头像 */ uploadImgCtl: function () { const continuousFn = { fn: this.uploadImgCtl, param: { ...arguments } } wx.chooseImage({ count: 1, success: res => { UploadFile({ file: res.tempFilePaths, continuousFn }).then(res => { this.setData({ bookImg: res[0] }) }) } }) }, /** * 保存输入值 */ inputCtl: function (e) { const { value } = e.detail const { type } = e.currentTarget.dataset const { bookList } = this.data var temp={} // bookList[type] = value temp[`${type}`] = value // console.log(temp) this.setData(temp) }, /** * 提交按钮 */ submitCtl: function (e) { const continuousFn = { fn: this.submitCtl, param: { ...arguments } } const { libId } = this.data.options; const { type } = e.currentTarget.dataset const { bookList, bookImg, title, publisher, author, applyReason, infofromstorage } = this.data if (type == 1) { wx.navigateBack({ delta: 1 }) } else if (type == 2) { if (!title) { wx.showToast({ title: '请输入书名', icon: 'none' }) return } if (!applyReason) { wx.showToast({ title: '请输入申请原因 ', icon: 'none' }) return } // 存储本地 const bookList = infofromstorage || [] bookList.push({ bookImg, title, publisher, author, applyReason }) wx.setStorageSync('parentsList', bookList) wx.showToast({ title: '保存成功', }) setTimeout(() => { navigateBack() }, 2000) } }, /** * 清除图片 */ deleteImg:function(){ this.setData({ bookImg:''}) } })