|
@@ -1,5 +1,7 @@
|
|
|
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 },
|
|
@@ -10,7 +12,18 @@ Page({
|
|
|
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 } }
|
|
@@ -23,12 +36,28 @@ Page({
|
|
|
wx.navigateBack({ delta: 1 })
|
|
|
},
|
|
|
// 选择学生
|
|
|
- stuChange: function (e) {
|
|
|
+ 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 })
|
|
|
+ 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) {
|
|
@@ -49,14 +78,61 @@ Page({
|
|
|
const that = this;
|
|
|
const params = e.detail.value;
|
|
|
const form = that.data.form;
|
|
|
- form.img_url = form.img_url;
|
|
|
+ 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 {
|
|
|
- console.log(params);
|
|
|
- // config: { type: Object, required: false, zh: '设置' }, // 打折方式 discount_type:fixed 固定;subtract 减; discount折 ;number
|
|
|
+ // 创建试课信息;创建二维码信息;支付信息;查询支付状态;支付成功;
|
|
|
+ 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 })
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
@@ -85,7 +161,7 @@ Page({
|
|
|
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 })
|
|
|
+ that.setData({ form });
|
|
|
},
|
|
|
fail: async res => {
|
|
|
wx.redirectTo({ url: '/pages/index/index' })
|