123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- const app = getApp()
- Page({
- data: {
- frameStyle: { useTop: true, name: '系统', leftArrow: false, useBar: false },
- },
- toCommon: function (e) {
- const { route } = e.currentTarget.dataset;
- if (route) wx.navigateTo({ url: `/pages/${route}` });
- },
- async toRefund() {
- let obj = {
- lesson_id: '63563bbd8018a39220eca774',
- student_id: '635629fecb0f85380e8354e5'
- }
- let res = await app.$post(`/lessonStudent/toRefund`, obj);
- if (res.errcode == '0') {
- wx.showToast({
- title: '退课成功',
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- },
- async toPay() {
- let obj = {
- id: '6357ad3bb78abf276d3ae74e'
- }
- let res = await app.$post(`/lessonStudent/toRePay`, obj);
- 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' })
- },
- async fail(payErr) {
- wx.showToast({ title: '支付不成功', icon: 'none' })
- }
- })
- } else {
- wx.showToast({ title: '报名成功', icon: 'none' });
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) { },
- // 监听用户是否登录
- watchLogin: async function () {
- // 监听用户是否登录,
- wx.getStorage({
- key: 'user',
- success: async res => {
- if (res.data) wx.redirectTo({ url: '/pages/school/index' })
- // /pages/school/index
- // /pagesSchool/common/lessoninfo
- // /pagesSchool/schAdmin/course/coachlist
- // /pagesSchool/stuAdmin/money/list
- // /pagesSchool/stuAdmin/course/list
- },
- fail: async res => {
- wx.login({
- success: async (arr) => {
- if (app.globalData?.wxInfo?.openid) { await this.toLogin(app.globalData?.wxInfo?.openid); return; }
- const { code: js_code } = arr;
- const aee = await app.$get('/wechat/api/login/app', { js_code: js_code, config: 'newCourtApp' });
- if (aee.errcode === 0 && aee.data?.openid) {
- const openid = aee.data.openid;
- app.globalData.wxInfo = { openid };
- await this.toLogin(openid);
- } else {
- wx.showToast({ title: `${aee.errmsg}`, icon: 'fail', duration: 2000 });
- wx.redirectTo({ url: '/pages/register/index' });
- }
- },
- });
- }
- })
- },
- async toLogin(openid) {
- const res = await app.$post('/user/wxAppLogin', { openid });
- if (app.$checkRes(res)) {
- const { data } = res;
- // 没有用户,去注册
- if (!data) wx.redirectTo({ url: '/pages/register/index' });
- // 有用户,存起来,跳转
- else {
- wx.setStorageSync('user', data);
- wx.redirectTo({ url: '/pages/school/index' });
- }
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- const that = this;
- // 监听用户是否登录
- that.watchLogin();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|