|
@@ -1,10 +1,22 @@
|
|
|
const app = getApp()
|
|
|
+const moment = require("../../utils/moment.min")
|
|
|
Page({
|
|
|
data: {
|
|
|
frameStyle: { useTop: true, name: '课程详细信息', leftArrow: true, useBar: false },
|
|
|
id: '',
|
|
|
+ tabs: {
|
|
|
+ active: 'a',
|
|
|
+ menu: [
|
|
|
+ { title: '课程信息', active: 'a' },
|
|
|
+ { title: '教练信息', active: 'b' },
|
|
|
+ { title: '学员信息', active: 'c' },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ // 课程信息
|
|
|
form: {},
|
|
|
- user: {},
|
|
|
+ // 教练信息
|
|
|
+ coachList: [],
|
|
|
+ // 字典表
|
|
|
//状态
|
|
|
statusList: [],
|
|
|
},
|
|
@@ -12,17 +24,119 @@ Page({
|
|
|
back(e) {
|
|
|
wx.navigateBack({ delta: 1 })
|
|
|
},
|
|
|
+ tabsChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let { active } = e.detail;
|
|
|
+ that.setData({ 'tabs.active': active });
|
|
|
+ },
|
|
|
+ // 报名
|
|
|
+ async toSign(e) {
|
|
|
+ const that = this;
|
|
|
+ const { item } = e.currentTarget.dataset;
|
|
|
+ let id = that.data.id;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'user',
|
|
|
+ success: async res => {
|
|
|
+ let user = res.data;
|
|
|
+ if (user && user.type == '3') {
|
|
|
+ let time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ let obj = { openid: user.openid, money: item.money, school_id: item.school_id, student_id: user.info._id, lesson_id: id };
|
|
|
+ // 创建报名
|
|
|
+ await that.createLesson(obj);
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '账号角色不对,不可报名',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index', })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 创建报名信息
|
|
|
+ async createLesson(e) {
|
|
|
+ const that = this;
|
|
|
+ let res = await app.$post(`/lessonStudent`, e);
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ // wxSign有值:余额不够,需手动支付
|
|
|
+ // 无值:余额够,无需支付
|
|
|
+ if (res?.data?.wxSign) {
|
|
|
+ // 调取支付窗口
|
|
|
+ let wxSign = res.data.wxSign;
|
|
|
+ wx.requestPayment({
|
|
|
+ timeStamp: wxSign.timestamp,
|
|
|
+ nonceStr: wxSign.nonceStr,
|
|
|
+ package: `prepay_id=${wxSign.prepay_id}`,
|
|
|
+ signType: wxSign.signType,
|
|
|
+ paySign: wxSign.paySign,
|
|
|
+ async success(payRes) {
|
|
|
+ wx.showToast({ title: '报名成功', icon: 'none' })
|
|
|
+ that.watchLogin();
|
|
|
+ },
|
|
|
+ async fail(payErr) {
|
|
|
+ wx.showToast({ title: '支付不成功', icon: 'none' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: '报名成功', icon: 'none' });
|
|
|
+ that.watchLogin()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: async function (options) {
|
|
|
const that = this;
|
|
|
- await that.setData({ id: options.id || null })
|
|
|
+ await that.setData({ id: options.id || '63563bbd8018a39220eca774' })
|
|
|
// 查询其他信息
|
|
|
await that.searchOther();
|
|
|
// 监听用户是否登录
|
|
|
await that.watchLogin();
|
|
|
},
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin: async function () {
|
|
|
+ const that = this;
|
|
|
+ if (that.data.id) {
|
|
|
+ await that.searchInfo();
|
|
|
+ // 查询教练
|
|
|
+ await that.searchCoach();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async searchInfo() {
|
|
|
+ const that = this;
|
|
|
+ const res = await app.$get(`/lesson/${that.data.id}`);
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ // 课程状态
|
|
|
+ res.data.zhStatus = that.searchStatus(res.data.status);
|
|
|
+ // 课程信息
|
|
|
+ that.setData({ form: res.data })
|
|
|
+ }
|
|
|
+ else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
|
|
|
+ },
|
|
|
+ searchStatus(e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.statusList.find(i => i.value == e);
|
|
|
+ if (data) return data.label
|
|
|
+ },
|
|
|
+ async searchCoach() {
|
|
|
+ const that = this;
|
|
|
+ let id = that.data.id;
|
|
|
+ let res = await app.$get(`/lessonCoach`, { lesson_id: id });
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ that.setData({ coachList: res.data })
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: res.errmsg, icon: 'none' })
|
|
|
+ }
|
|
|
+ },
|
|
|
searchOther: async function () {
|
|
|
const that = this;
|
|
|
let arr;
|
|
@@ -30,31 +144,6 @@ Page({
|
|
|
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) {
|
|
|
- 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;
|
|
|
- // 课程信息
|
|
|
- that.setData({ form: arr.data })
|
|
|
- }
|
|
|
- else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
|
|
|
- }
|
|
|
- },
|
|
|
- fail: async res => {
|
|
|
- wx.redirectTo({ url: '/pages/index/index' })
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
@@ -62,7 +151,7 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
- onShow: function () {},
|
|
|
+ onShow: function () { },
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|