|
@@ -11,7 +11,7 @@ Page({
|
|
|
total: 0,
|
|
|
page: 0,
|
|
|
skip: 0,
|
|
|
- limit: 5,
|
|
|
+ limit: 6,
|
|
|
// 支付状态
|
|
|
is_payList: is_pay,
|
|
|
// 课程状态
|
|
@@ -19,61 +19,63 @@ Page({
|
|
|
},
|
|
|
// 返回
|
|
|
back: function () { wx.navigateBack({ delta: 1 }) },
|
|
|
- //详细信息
|
|
|
- toCommon: function (e) {
|
|
|
+ // 清空列表
|
|
|
+ clearPage() {
|
|
|
const that = this;
|
|
|
- const { item, route } = e.currentTarget.dataset;
|
|
|
- that.setData({ skip: 0, page: 0, list: [] });
|
|
|
- wx.navigateTo({ url: `${route}?id=${item && item.lesson_id ? item.lesson_id : ''}` })
|
|
|
+ that.setData({ list: [], skip: 0, limit: 6, page: 0 })
|
|
|
},
|
|
|
- // 支付
|
|
|
- toPay: async function (e) {
|
|
|
+ //详细信息
|
|
|
+ toView: function (e) {
|
|
|
const that = this;
|
|
|
const { item } = e.currentTarget.dataset;
|
|
|
- wx.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '是否确认支付?',
|
|
|
- async success(res) {
|
|
|
- if (res.confirm) {
|
|
|
- console.log('支付');
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
+ that.clearPage();
|
|
|
+ wx.navigateTo({ url: `/pagesSchool/common/lessoninfo?id=${item.lesson_id}` })
|
|
|
},
|
|
|
- // 退款
|
|
|
- toRefund: async function (e) {
|
|
|
+ // 支付
|
|
|
+ async toPay(e) {
|
|
|
const that = this;
|
|
|
const { item } = e.currentTarget.dataset;
|
|
|
- let time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
- let data = moment(time).isBefore(item.lesson_id_refund_hour);
|
|
|
- if (data == true) {
|
|
|
- wx.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '是否确认退款?',
|
|
|
- async success(res) {
|
|
|
- if (res.confirm) {
|
|
|
- console.log('退款');
|
|
|
- }
|
|
|
+ that.clearPage();
|
|
|
+ let res = await app.$post(`/lessonStudent/toRePay`, { id: item.lesson_id });
|
|
|
+ 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.search()
|
|
|
+ },
|
|
|
+ async fail(payErr) {
|
|
|
+ wx.showToast({ title: '支付不成功', icon: 'none' })
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
- wx.showToast({ title: '超过退款期限无法退款', icon: 'none', duration: 2000 })
|
|
|
+ wx.showToast({ title: '报名成功', icon: 'none' });
|
|
|
}
|
|
|
},
|
|
|
- // 分页
|
|
|
- toPage: function () {
|
|
|
+ // 退课
|
|
|
+ async toRefund(e) {
|
|
|
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 }) }
|
|
|
+ const { item } = e.currentTarget.dataset;
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '是否确认退款?',
|
|
|
+ async success(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ let res = await app.$post(`/lessonStudent/toRefund`, { lesson_id: item.lesson_id, student_id: item.student_id });
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ wx.showToast({ title: '退课成功', icon: 'none' })
|
|
|
+ that.clearPage();
|
|
|
+ that.search();
|
|
|
+ } else wx.showToast({ title: res.errmsg, icon: 'none' })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
@@ -93,40 +95,71 @@ Page({
|
|
|
// 监听用户是否登录
|
|
|
await that.watchLogin();
|
|
|
},
|
|
|
- searchOther: async function () {
|
|
|
- const that = this;
|
|
|
- let arr;
|
|
|
- // 状态
|
|
|
- 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;
|
|
|
wx.getStorage({
|
|
|
key: 'user',
|
|
|
success: async res => {
|
|
|
- let info = { skip: that.data.skip, limit: that.data.limit, student_id: res.data.info._id };
|
|
|
- let arr = await app.$get(`/lessonStudent`, { ...info });
|
|
|
- if (arr.errcode == '0') {
|
|
|
- let list = [...that.data.list, ...arr.data];
|
|
|
- for (const val of list) {
|
|
|
- // 课程状态
|
|
|
- let status = that.data.statusList.find(i => i.value == val.lesson_id_status)
|
|
|
- if (status) val.zhStatus = status.label;
|
|
|
- // 支付状态
|
|
|
- let pay = is_pay.find(i => i.value == val.is_pay)
|
|
|
- if (pay) val.zhPay = pay.label;
|
|
|
- }
|
|
|
- that.setData({ list })
|
|
|
- that.setData({ total: arr.total })
|
|
|
- } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
|
|
|
+ that.setData({ user: res.data });
|
|
|
+ that.search();
|
|
|
},
|
|
|
fail: async res => {
|
|
|
wx.redirectTo({ url: '/pages/index/index' })
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ async search() {
|
|
|
+ const that = this;
|
|
|
+ let user = that.data.user;
|
|
|
+ let info = { skip: that.data.skip, limit: that.data.limit, student_id: user.info._id };
|
|
|
+ let res = await app.$get(`/lessonStudent`, { ...info });
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ let list = [...that.data.list, ...res.data];
|
|
|
+ for (const val of list) {
|
|
|
+ val.zhStatus = that.searchStatus(val.lesson_id_status);
|
|
|
+ val.zhPay = that.searchPay(val.is_pay);
|
|
|
+ }
|
|
|
+ that.setData({ list })
|
|
|
+ that.setData({ total: res.total })
|
|
|
+ } else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
|
|
|
+ },
|
|
|
+ // 查询状态
|
|
|
+ searchStatus: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.statusList.find(i => i.value == e);
|
|
|
+ if (data) return data.label;
|
|
|
+ else return '暂无';
|
|
|
+ },
|
|
|
+ // 查询支付状态
|
|
|
+ searchPay: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.is_payList.find(i => i.value == e);
|
|
|
+ if (data) return data.label;
|
|
|
+ else return '暂无';
|
|
|
+ },
|
|
|
+ searchOther: async function () {
|
|
|
+ const that = this;
|
|
|
+ let arr;
|
|
|
+ // 状态
|
|
|
+ arr = await app.$get(`/dict`, { code: 'lesson_status' });
|
|
|
+ if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
|
|
|
+ },
|
|
|
+ // 分页
|
|
|
+ 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.search();
|
|
|
+ wx.hideLoading()
|
|
|
+ } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
|
|
|
+ },
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|