Prechádzať zdrojové kódy

Merge branch 'master' of http://git.cc-lotus.info/ball-court/ball-applet

guhongwei 2 rokov pred
rodič
commit
fa4cdd5f1b

+ 101 - 100
pages/school/index.js

@@ -1,111 +1,112 @@
 const app = getApp()
 const moment = require("../../utils/moment.min")
 Page({
-    data: {
-        frameStyle: { useTop: true, name: '羽校', leftArrow: false, useBar: true },
-        user: {},
-        list: [],
-        total: 0,
-        page: 0,
-        skip: 0,
-        limit: 5,
-    },
-    // 跳转菜单
-    tabPath(e) {
-        let { route } = e.detail.detail;
-        if (route) wx.redirectTo({ url: `/${route}` })
-    },
-    // 进入系统
-    toJoin: function () {
-        const that = this;
-        that.setData({ skip: 0, page: 0, list: [] })
-        wx.navigateTo({ url: `/pages/smy/index` })
-    },
-    // 查看详情
-    toView: function (e) {
-        const that = this;
-        const { item } = e.currentTarget.dataset;
-        that.setData({ skip: 0, page: 0, list: [] })
-        wx.navigateTo({ url: `/pages/school/info?id=${item._id}` })
-    },
-    // 分页
-    toPage: function () {
-        const that = this;
-        let list = that.data.list;
-        let limit = that.data.limit;
-        if (that.data.total > list.length) {
-            wx.showLoading({ title: '加载中', mask: true })
-            let page = that.data.page + 1;
-            that.setData({ page: page })
-            let skip = page * limit;
-            that.setData({ skip: skip })
-            that.watchLogin();
-            wx.hideLoading()
-        } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
-    },
-    /**
-     * 生命周期函数--监听页面加载
-     */
-    onLoad: function (options) { },
-    /**
-     * 生命周期函数--监听页面初次渲染完成
-     */
-    onReady: function () { },
-    /**
-     * 生命周期函数--监听页面显示
-     */
-    onShow: function () {
-        const that = this;
-        // 监听用户是否登录
-        that.watchLogin();
-    },
+  data: {
+    frameStyle: { useTop: true, name: '羽校', leftArrow: false, useBar: true },
+    user: {},
+    list: [],
+    total: 0,
+    page: 0,
+    skip: 0,
+    limit: 5,
+  },
+  // 跳转菜单
+  tabPath(e) {
+    let { route } = e.detail.detail;
+    if (route) wx.redirectTo({ url: `/${route}` })
+  },
+  // 进入系统
+  toJoin: function () {
+    const that = this;
+    that.setData({ skip: 0, page: 0, list: [] })
+    wx.navigateTo({ url: `/pages/smy/index` })
+  },
+  // 查看详情
+  toView: function (e) {
+    const that = this;
+    const { item } = e.currentTarget.dataset;
+    that.setData({ skip: 0, page: 0, list: [] })
+    wx.navigateTo({ url: `/pages/school/info?id=${item._id}` })
+  },
+  // 分页
+  toPage: function () {
+    const that = this;
+    let list = that.data.list;
+    let limit = that.data.limit;
+    if (that.data.total > list.length) {
+      wx.showLoading({ title: '加载中', mask: true })
+      let page = that.data.page + 1;
+      that.setData({ page: page })
+      let skip = page * limit;
+      that.setData({ skip: skip })
+      that.watchLogin();
+      wx.hideLoading()
+    } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
+  },
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) { },
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () { },
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+    const that = this;
     // 监听用户是否登录
-    watchLogin: async function () {
-        const that = this;
-        wx.getStorage({
-            key: 'user',
-            success: async res => {
-                that.setData({ user: res.data })
-                let info = { skip: that.data.skip, limit: that.data.limit };
-                const arr = await app.$get(`/school`, { ...info });
-                if (arr.errcode == '0') {
-                    that.setData({ list: [...that.data.list, ...arr.data] });
-                    that.setData({ total: arr.total })
-                } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
-            },
-            fail: async res => {
-                wx.redirectTo({ url: '/pages/index/index' })
-            }
-        })
-    },
-    /**
-     * 页面上拉触底事件的处理函数
-     */
-    /**
-     * 生命周期函数--监听页面隐藏
-     */
-    onHide: function () {
+    that.watchLogin();
+  },
+  // 监听用户是否登录
+  watchLogin: async function () {
+    const that = this;
+    wx.getStorage({
+      key: 'user',
+      success: async res => {
+        that.setData({ user: res.data })
+        let info = { skip: that.data.skip, limit: that.data.limit };
+        const arr = await app.$get(`/school`, { ...info });
+        if (arr.errcode == '0') {
+          that.setData({ list: [...that.data.list, ...arr.data] });
+          that.setData({ total: arr.total })
+        } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
+      },
+      fail: async res => {
+        wx.redirectTo({ url: '/pages/index/index' })
+      }
+    })
+  },
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+    const that = this;
+    that.setData({ skip: 0, page: 0, list: [] })
+  },
 
-    },
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
 
-    /**
-     * 生命周期函数--监听页面卸载
-     */
-    onUnload: function () {
+  },
 
-    },
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
 
-    /**
-     * 页面相关事件处理函数--监听用户下拉动作
-     */
-    onPullDownRefresh: function () {
+  },
 
-    },
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
 
-    /**
-     * 用户点击右上角分享
-     */
-    onShareAppMessage: function () {
-
-    }
+  }
 })

+ 2 - 2
pages/school/info.js

@@ -43,7 +43,7 @@ Page({
         let data = e.detail;
         that.setData({ 'tabs.active': data.active })
     },
-    
+
     // 图片预览
     imgView: function (e) {
         const that = this;
@@ -90,7 +90,7 @@ Page({
         const that = this;
         let list = that.data.list;
         let limit = that.data.limit;
-        if (that.data.total > list.length) {
+        if (that.data.total > list && list.length) {
             wx.showLoading({ title: '加载中', mask: true })
             let page = that.data.page + 1;
             that.setData({ page: page })

+ 14 - 6
pages/stuAdmin/course/list.js

@@ -44,12 +44,20 @@ Page({
         const that = this;
         const user = that.data.user;
         const { item } = e.currentTarget.dataset;
-        let toRefund = await app.$post(`/lessonStudent/toRefund`, { student_id: user.info.id, lesson_id: item._id });
-        if (toRefund.errcode == '0') {
-            wx.showToast({ title: `退课成功 钱返回余额中`, icon: 'success', duration: 2000 });
-            that.setData({ skip: 0, page: 0, list: [] })
-            that.watchLogin();
-        } else wx.showToast({ title: `${toRefund.errmsg}`, icon: 'none', duration: 2000 })
+        wx.showModal({
+            title: '提示',
+            content: '您是否确定退课?',
+            async success(res) {
+                if (res.confirm) {
+                    let toRefund = await app.$post(`/lessonStudent/toRefund`, { student_id: user.info.id, lesson_id: item._id });
+                    if (toRefund.errcode == '0') {
+                        wx.showToast({ title: `退课成功`, icon: 'success', duration: 2000 });
+                        that.setData({ skip: 0, page: 0, list: [] })
+                        that.watchLogin();
+                    } else wx.showToast({ title: `${toRefund.errmsg}`, icon: 'none', duration: 2000 })
+                } else if (res.cancel) { }
+            }
+        });
     },
     // 签到
     toSign: async function (e) {

+ 30 - 21
pages/stuAdmin/course/sign.js

@@ -71,26 +71,36 @@ Page({
                             let obj = { openid: res.data.openid, money: money, school_id: form.school_id, payer_id: user.info.id, payer_role: 'Student', pay_for: 'lessonStudent', time: moment().format('YYYY-MM-DD HH:mm:ss') }
                             const arr = await app.$post(`/payOrder`, obj)
                             if (arr.errcode == '0') {
-                                wx.requestPayment({
-                                    "timeStamp": arr.data.wxSign.timestamp,
-                                    "nonceStr": arr.data.wxSign.nonceStr,
-                                    "package": `prepay_id=${arr.data.wxSign.prepay_id}`,
-                                    "signType": arr.data.wxSign.signType,
-                                    "paySign": arr.data.wxSign.paySign,
-                                    "success": async function (res) {
-                                        let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id, money: money, is_try: that.data.is_try, pay_id: arr.data.data._id, is_pay: '1' }
-                                        let lessonStudent = await app.$post(`/lessonStudent`, params);
-                                        if (lessonStudent.errcode == '0') {
-                                            wx.showToast({ title: `报名申请完成`, icon: 'success', duration: 2000 });
-                                            const pay = await app.$post(`/payOrder/${arr.data.data._id}`, { from_id: lessonStudent.data._id, status: '1' });
-                                            if (pay.errcode == '0') that.watchLogin();
-                                        }
-                                        else wx.showToast({ title: `${lessonStudent.errmsg}`, icon: 'error', duration: 2000 })
-                                    },
-                                    "fail": async function (res) {
-                                        const pay = await app.$delete(`/payOrder/${arr.data.data._id}`);
-                                    },
-                                })
+                                if (arr?.data?.wxSign) {
+                                    wx.requestPayment({
+                                        "timeStamp": arr.data.wxSign.timestamp,
+                                        "nonceStr": arr.data.wxSign.nonceStr,
+                                        "package": `prepay_id=${arr.data.wxSign.prepay_id}`,
+                                        "signType": arr.data.wxSign.signType,
+                                        "paySign": arr.data.wxSign.paySign,
+                                        "success": async function (res) {
+                                            let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id, money: money, is_try: that.data.is_try, pay_id: arr.data.data._id, is_pay: '1' }
+                                            let lessonStudent = await app.$post(`/lessonStudent`, params);
+                                            if (lessonStudent.errcode == '0') {
+                                                wx.showToast({ title: `报名申请完成`, icon: 'success', duration: 2000 });
+                                                const pay = await app.$post(`/payOrder/${arr.data.data._id}`, { from_id: lessonStudent.data._id, status: '1' });
+                                                if (pay.errcode == '0') that.watchLogin();
+                                            }
+                                            else wx.showToast({ title: `${lessonStudent.errmsg}`, icon: 'error', duration: 2000 })
+                                        },
+                                        "fail": async function (res) {
+                                            const pay = await app.$delete(`/payOrder/${arr.data.data._id}`);
+                                        },
+                                    })
+                                } else {
+                                    let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id, money: money, is_try: that.data.is_try, is_pay: '1' }
+                                    let lessonStudent = await app.$post(`/lessonStudent`, params);
+                                    if (lessonStudent.errcode == '0') {
+                                        wx.showToast({ title: `报名申请完成 从余额扣除`, icon: 'none', duration: 2000 });
+                                        that.watchLogin();
+                                    }
+                                    else wx.showToast({ title: `${lessonStudent.errmsg}`, icon: 'error', duration: 2000 })
+                                }
                             }
                         },
                         fail: async (res) => {
@@ -138,7 +148,6 @@ Page({
                                 if (school.errcode == '0') arr.data.zhSchool = school.data.name;
                                 const lesson = await app.$post(`/tryLessonApply/checkCanUse`, { school_id: arr.data.school_id, lesson_id: that.data.id, student_id: res.data.info.id })
                                 if (lesson.errcode == '0') arr.data.type_try = '0';
-                                else wx.showToast({ title: `${lesson.errmsg}`, icon: 'none', duration: 2000 })
                                 const lessonStudent = await app.$post(`/lessonStudent/checkCanUse`, { school_id: arr.data.school_id, student_id: res.data.info.id, lesson_id: that.data.id })
                                 if (lessonStudent.errcode == '0') arr.data.sign = '0';
                                 else arr.data.sign = '1';