const app = getApp() Page({ data: { frameStyle: { useTop: true, name: '公开课信息', leftArrow: true, useBar: false }, id: '', form: {}, //状态 statusList: [] }, // 跳转菜单 back(e) { wx.navigateBack({ delta: 1 }) }, //提交 onSubmit: async function (e) { const that = this; const form = that.data.form; const params = e.detail.value; params.icon = form.icon; params.school_id = that.data.school_id; if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0]; wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 }) return false } else { let arr; if (form._id) arr = await app.$post(`/student/${form._id}`, params); else arr = await app.$post(`/student`, params) if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); } else wx.showToast({ title: `${errmsg}`, icon: 'error', duration: 2000 }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: async function (options) { const that = this; await that.setData({ id: options.id || null }) // 查询其他信息 await that.searchOther(); // 监听用户是否登录 await that.watchLogin(); }, searchOther: async function () { const that = this; let arr; // 状态 arr = await app.$get(`/dict`, { code: 'lesson_status' }); if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list }); }, // 监听用户是否登录 watchLogin: async function () { const that = this; let statusList = that.data.statusList; wx.getStorage({ key: 'user', success: async res => { if (that.data.id) { const arr = await app.$get(`/lessonPublic/${that.data.id}`); if (arr.errcode == '0') { let status = statusList.find(i => i.value == arr.data.status) if (status) arr.data.zhStatus = status.label; that.setData({ form: arr.data }) } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } } }, fail: async res => { wx.redirectTo({ url: '/pages/index/index' }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 页面上拉触底事件的处理函数 */ /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })