const app = getApp() const moment = require("../../../utils/moment.min") Page({ data: { frameStyle: { useTop: true, name: '详细信息', leftArrow: true, useBar: false }, id: '', form: {}, user: {}, //是否试课 is_try: '0', //状态 statusList: [], //学员 student: {}, // 教练 coach: {}, // 选中 tabs: { active: '0', menu: [ { title: '课程信息', active: '0' }, { title: '教练人员', active: '1' }, { title: '学生人员', active: '2' }, ] }, }, // 跳转菜单 back(e) { wx.navigateBack({ delta: 1 }) }, // 选项卡选择 tabsChange: function (e) { const that = this; let data = e.detail; that.setData({ 'tabs.active': data.active }) }, //试课 toClass: function () { const that = this; const form = that.data.form; const user = that.data.user; wx.showModal({ title: '提示', content: '您是否确定试课?', async success(res) { if (res.confirm) { let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id } let arr = await app.$post(`/tryLessonApply`, params); if (arr.errcode == '0') { wx.showToast({ title: `试课申请完成`, icon: 'success', duration: 2000 }); that.watchLogin(); } else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } else if (res.cancel) { } } }); }, //提交 onSubmit: async function (e) { const that = this; const form = that.data.form; const user = that.data.user; var money = ''; if (form.type == '0') money = form.real_money; else if (form.type == '1') money = form.money; wx.showModal({ title: '提示', content: '您是否确定报名?', async success(res) { if (res.confirm) { wx.getStorage({ key: 'user', success: async (res) => { let obj = { openid: res.data.openid, money: money, school_id: form.school_id, payer_id: user.info.id, payer_role: 'Student', pay_for: 'lessonStudent', time: moment().format('YYYY-MM-DD HH:mm:ss') } const arr = await app.$post(`/payOrder`, obj) if (arr.errcode == '0') { wx.requestPayment({ "timeStamp": arr.data.wxSign.timestamp, "nonceStr": arr.data.wxSign.nonceStr, "package": `prepay_id=${arr.data.wxSign.prepay_id}`, "signType": arr.data.wxSign.signType, "paySign": arr.data.wxSign.paySign, "success": async function (res) { let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id, money: money, is_try: that.data.is_try, pay_id: arr.data.data._id, is_pay: '1' } let lessonStudent = await app.$post(`/lessonStudent`, params); if (lessonStudent.errcode == '0') { wx.showToast({ title: `报名申请完成`, icon: 'success', duration: 2000 }); const pay = await app.$post(`/payOrder/${arr.data.data._id}`, { from_id: lessonStudent.data._id }); if (pay.errcode == '0') that.watchLogin(); } else wx.showToast({ title: `${lessonStudent.errmsg}`, icon: 'error', duration: 2000 }) }, "fail": async function (res) { const pay = await app.$delete(`/payOrder/${arr.data.data._id}`); }, }) } }, fail: async (res) => { wx.redirectTo({ url: '/pages/index/index' }); }, }); } else if (res.cancel) { } } }); }, /** * 生命周期函数--监听页面加载 */ 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 => { that.setData({ user: res.data }) if (that.data.id) { if (res.data.type == '3') { const arr = await app.$post(`/lessonStudent/toComputed`, { lesson_id: that.data.id, student_id: res.data.info.id }); if (arr.errcode == '0') { let status = statusList.find(i => i.value == arr.data.status) if (status) arr.data.zhStatus = status.label; if (arr.data.school_id) { const school = await app.$get(`/school/${arr.data.school_id}`) if (school.errcode == '0') arr.data.zhSchool = school.data.name; const lesson = await app.$post(`/tryLessonApply/checkCanUse`, { school_id: arr.data.school_id, lesson_id: that.data.id, student_id: res.data.info.id }) if (lesson.errcode == '0') arr.data.type_try = '0'; else wx.showToast({ title: `${lesson.errmsg}`, icon: 'none', duration: 2000 }) const lessonStudent = await app.$post(`/lessonStudent/checkCanUse`, { school_id: arr.data.school_id, student_id: res.data.info.id, lesson_id: that.data.id }) if (lessonStudent.errcode == '0') arr.data.sign = '0'; else arr.data.sign = '1'; } that.setData({ form: arr.data }) } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } } else { const arr = await app.$get(`/lesson/${that.data.id}`); if (arr.errcode == '0') { let status = statusList.find(i => i.value == arr.data.status) if (status) arr.data.zhStatus = status.label; if (arr.data.school_id) { const school = await app.$get(`/school/${arr.data.school_id}`) if (school.errcode == '0') arr.data.zhSchool = school.data.name; } that.setData({ form: arr.data }) } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } } const coach = await app.$get(`/lessonCoach`, { lesson_id: that.data.id }) if (coach.errcode == '0') that.setData({ coach: coach.data }) const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id, is_pay: '1' }) if (student.errcode == '0') that.setData({ student: student.data }) } }, fail: async res => { wx.redirectTo({ url: '/pages/index/index' }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 页面上拉触底事件的处理函数 */ /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })