123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- const app = getApp()
- import WxValidate from '../../../utils/wxValidate'
- import QRCode from '../../../utils/weapp-qrcode.js';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
- user: {},
- lesson_id: '',
- lessonInfo: {},
- id: '',
- form: { file: [] },
- studentlist: [],
- payUrl: '',
- // dialog弹框
- dialog: { title: '二维码支付', show: false, type: '1' },
- payUrl: ''
- },
- initValidate() {
- const rules = { name: { required: true }, phone: { required: true }, file: { required: true } }
- // 验证字段的提示信息,若不传则调用默认的信息
- const messages = { name: { required: '学员姓名', }, phone: { required: '联系方式', }, file: { required: '图片', } };
- this.WxValidate = new WxValidate(rules, messages)
- },
- // 跳转菜单
- back(e) {
- wx.navigateBack({ delta: 1 })
- },
- // 选择学员
- stuChange(e) {
- const that = this;
- let data = that.data.studentlist[e.detail.value];
- if (data) that.setData({ 'form.student_id': data.student_id, 'form.name': data.student_id_name, 'form.phone': data.student_id_phone, })
- },
- // 上传照片
- imgUpl: function (e) {
- const that = this;
- let data = that.data.form.file;
- data.push(e.detail)
- that.setData({ 'form.file': data })
- },
- // 删除图片
- imgDel: function (e) {
- const that = this;
- let list = that.data.form.file;
- let arr = list.filter((i, index) => index != e.detail.index)
- that.setData({ 'form.file': arr })
- },
- // 提交
- onSubmit: async function (e) {
- const that = this;
- const params = e.detail.value;
- const form = that.data.form;
- params.file = form.file;
- if (!this.WxValidate.checkForm(params)) {
- const error = this.WxValidate.errorList[0];
- wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
- return false
- } else {
- let res = await app.$post(`/tempLessonApply`, params);
- if (res.errcode == '0') {
- if (res.data == 'ok') {
- wx.showToast({ title: '临时报名上课成功', icon: 'none' })
- that.back()
- } else {
- let data = JSON.parse(res.data);
- that.createPayUrl(data.code_url);
- that.setData({ dialog: { title: '二维码支付', show: true, type: '1' } })
- }
- } else {
- wx.showToast({ title: res.errmsg, icon: 'none' })
- }
- }
- },
- createPayUrl(e) {
- // 生成二维码
- const that = this;
- const url = `${e}`;
- var qrcode = new QRCode(`myQrcode`, {
- text: url,
- width: 110,
- height: 110,
- padding: 3,
- colorDark: "#000000",
- colorLight: "#ffffff",
- correctLevel: QRCode.CorrectLevel.L,
- });
- },
- // 关闭弹框
- toClose: function () {
- const that = this;
- that.setData({ dialog: { title: '二维码支付', show: false, type: '1' } })
- },
- // 付款成功
- paySuccess() {
- const that = this;
- that.setData({ form: {} })
- that.toClose();
- that.back();
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const that = this;
- that.setData({ lesson_id: options.lesson_id || '63563bbd8018a39220eca774', id: options.id || '' });
- //验证规则函数
- that.initValidate();
- // 监听用户是否登录
- that.watchLogin();
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- wx.getStorage({
- key: 'user',
- success: async res => {
- that.setData({ user: res.data });
- await that.searchLesson();
- await that.search();
- await that.searchStu();
- },
- fail: res => {
- wx.redirectTo({ url: '/pages/index/index', })
- }
- })
- },
- async searchLesson() {
- const that = this;
- let lesson_id = that.data.lesson_id;
- let res = await app.$get(`/lesson/${lesson_id}`);
- if (res.errcode == '0') {
- that.setData({ lessonInfo: res.data });
- }
- else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
- },
- async search() {
- const that = this;
- let lessonInfo = that.data.lessonInfo;
- let user = that.data.user;
- let id = that.data.id;
- let form = { school_id: lessonInfo.school_id, coach_id: user.info.id, lesson_id: lessonInfo.id, money: lessonInfo.money, file: [] };
- let res;
- if (id) {
- res = await app.$get(`/tempLessonApply/${id}`);
- if (res.errcode == '0') form = res.data
- else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
- }
- that.setData({ form })
- },
- async searchStu() {
- const that = this;
- let lessonInfo = that.data.lessonInfo;
- let res = await app.$get(`/rss`, { school_id: lessonInfo.school_id });
- if (res.errcode == '0') {
- that.setData({ studentlist: res.data })
- } else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|