|
@@ -1,219 +0,0 @@
|
|
|
-const app = getApp()
|
|
|
-import WxValidate from '../../../utils/wxValidate';
|
|
|
-const moment = require("../../../utils/moment.min");
|
|
|
-import QRCode from '../../../utils/weapp-qrcode.js';
|
|
|
-Page({
|
|
|
- data: {
|
|
|
- frameStyle: { useTop: true, name: '信息维护', leftArrow: true, useBar: false },
|
|
|
- form: { img_url: [] },
|
|
|
- // 课程信息
|
|
|
- lesson_id: '',
|
|
|
- // 学校信息
|
|
|
- schoolInfo: {},
|
|
|
- // 学生列表
|
|
|
- studentList: [],
|
|
|
- // 学生信息
|
|
|
- studentInfo: {},
|
|
|
- // 试课申请信息
|
|
|
- elaInfo: {},
|
|
|
- // 二维码信息
|
|
|
- tpnInfo: {},
|
|
|
- // 打折信息
|
|
|
- lstInfo: {},
|
|
|
- // dialog弹框
|
|
|
- dialog: { title: '支付二维码', show: false, type: '1' },
|
|
|
- // 是否支付成功
|
|
|
- pay_status: ''
|
|
|
- },
|
|
|
- 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: async 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 });
|
|
|
- // 查询学生信息
|
|
|
- let studentInfo = {};
|
|
|
- let student = await app.$get(`/student/${data.student_id}`);
|
|
|
- if (student.errcode == '0') {
|
|
|
- let user = await app.$get(`/user/${student.data.user_id}`);
|
|
|
- if (user.errcode == '0') {
|
|
|
- studentInfo = { ...user.data, info: { ...student.data } }
|
|
|
- that.setData({ studentInfo })
|
|
|
- }
|
|
|
- }
|
|
|
- // 查询真实付款金额
|
|
|
- const arr = await app.$post(`/lessonStudent/toComputed`, { lesson_id: that.data.lesson_id, student_id: data.student_id });
|
|
|
- if (arr.errcode == '0') {
|
|
|
- that.setData({ 'form.money': arr.data.real_money });
|
|
|
- that.setData({ lstInfo: arr.data })
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- 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;
|
|
|
- params.img_url = form.img_url;
|
|
|
- const studentInfo = that.data.studentInfo;
|
|
|
- const schoolInfo = that.data.schoolInfo;
|
|
|
- const lstInfo = that.data.lstInfo;
|
|
|
- if (!this.WxValidate.checkForm(params)) {
|
|
|
- const error = this.WxValidate.errorList[0];
|
|
|
- wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
- return false
|
|
|
- } else {
|
|
|
- // 创建试课信息;创建二维码信息;支付信息;查询支付状态;支付成功;
|
|
|
- const arr = await app.$post(`/tempLessonApply`, params);
|
|
|
- if (arr.errcode == '0') {
|
|
|
- that.setData({ elaInfo: arr.data });
|
|
|
- let obj = { school_id: params.school_id, pay_for: 'tempLessonApply', from_id: that.data.elaInfo._id, money: params.money, time: moment().format('YYYY-MM-DD HH:mm:ss'), desc: '临时上课申请', config: lstInfo.config };
|
|
|
- const one = await app.$post(`/payOrder/toPayNative`, obj);
|
|
|
- if (one.errcode == '0') {
|
|
|
- that.setData({ tpnInfo: JSON.parse(one.data) });
|
|
|
- // 生成支付二维码
|
|
|
- that.makeQRCode();
|
|
|
- that.setData({ dialog: { title: '支付二维码', show: true, type: '1' } });
|
|
|
- }
|
|
|
- } else {
|
|
|
- wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- makeQRCode(template = 0) {
|
|
|
- const that = this;
|
|
|
- const url = `${that.data.tpnInfo.code_url}`;
|
|
|
- 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' } })
|
|
|
- },
|
|
|
- // 查询支付状态
|
|
|
- searchS: async function () {
|
|
|
- const that = this;
|
|
|
- const elaInfo = that.data.elaInfo;
|
|
|
- let arr;
|
|
|
- arr = await app.$get(`/tempLessonApply/${elaInfo._id}`);
|
|
|
- if (arr.errcode == '0') {
|
|
|
- arr = await app.$get(`/payOrder/${arr.data.pay_id}`);
|
|
|
- if (arr.errcode == '0') {
|
|
|
- that.setData({ pay_status: arr.data.status })
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- 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 () {
|
|
|
-
|
|
|
- }
|
|
|
-})
|