const app = getApp() import WxValidate from '../../../utils/wxValidate'; Page({ data: { frameStyle: { useTop: true, name: '信息维护', leftArrow: true, useBar: false }, form: { img_url: [] }, // 课程信息 lesson_id: '', // 学校信息 schoolInfo: {}, // 学生列表 studentList: [], }, initValidate() { const rules = { student_id: { required: true }, money: { required: true }, img_url: { required: true } } // 验证字段的提示信息,若不传则调用默认的信息 const messages = { student_id: { required: '请选择学生' }, money: { required: '课程费用' }, img_url: { required: '证据图片' } }; this.WxValidate = new WxValidate(rules, messages) }, // 返回 back: function () { wx.navigateBack({ delta: 1 }) }, // 选择学生 stuChange: function (e) { const that = this; let data = that.data.studentList[e.detail.value]; if (data) { that.setData({ 'form.student_id': data.student_id }) that.setData({ 'form.student_id_name': data.student_id_name }) } }, imgUpl: function (e) { const that = this; let data = that.data.form.img_url; data.push(e.detail) that.setData({ 'form.img_url': data }) }, // 删除图片 imgDel: function (e) { const that = this; let list = that.data.form.img_url; let arr = list.filter((i, index) => index != e.detail.index) that.setData({ 'form.img_url': arr }) }, //提交 onSubmit: async function (e) { const that = this; const params = e.detail.value; const form = that.data.form; form.img_url = form.img_url; if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0]; wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 }) return false } else { console.log(params); //  config: { type: Object, required: false, zh: '设置' }, // 打折方式 discount_type:fixed 固定;subtract 减; discount折 ;number } }, /** * 生命周期函数--监听页面加载 */ onLoad: async function (options) { const that = this; that.setData({ lesson_id: options.id || '' }) //验证规则函数 that.initValidate(); // 监听用户是否登录 await that.watchLogin(); }, // 监听用户是否登录 watchLogin: async function () { const that = this; wx.getStorage({ key: 'user', success: async res => { let data = res.data; let arr; // 学员与学校的关系 arr = await app.$get(`/rss`); if (arr.errcode == '0') that.setData({ studentList: arr.data }); // 教练与学校的关系 arr = await app.$get(`/rcs`, { coach_id: data.info.id }); if (arr.errcode == '0' && arr.total > 0) that.setData({ schoolInfo: arr.data[0] }); let form = { school_id: that.data.schoolInfo.school_id, lesson_id: that.data.lesson_id, coach_id: data.info._id, img_url: [] }; that.setData({ form }) }, fail: async res => { wx.redirectTo({ url: '/pages/index/index' }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })