123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- const app = getApp();
- import { is_pay } from '../../utils/dict';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- frameStyle: { useTop: true, name: '学员信息', leftArrow: true, useBar: false },
- id: '',
- // 查询
- search: {},
- list: [],
- total: 0,
- skip: 0,
- limit: 10,
- page: 0,
- is_payList: is_pay,
- },
- // 跳转菜单
- back(e) {
- wx.navigateBack({ delta: 1 })
- },
- // 查询
- toInput(e) {
- const that = this;
- let value = e.detail.value;
- if (value) that.setData({ 'search.student_id_name': value })
- else that.setData({ search: {} })
- that.clearPage(); that.watchLogin();
- },
- // 清空列表
- clearPage() {
- const that = this;
- that.setData({ list: [], skip: 0, limit: 10, page: 0 })
- },
- // 签到
- toSign(e) {
- const that = this;
- let { item } = e.currentTarget.dataset;
- wx.showModal({
- title: '提示',
- content: '是否确认签到?',
- async success(res) {
- if (res.confirm) {
- let res = await app.$post(`/lessonStudent/${item._id}`, { is_sign: '1' });
- if (res.errcode == '0') {
- wx.showToast({ title: '签到成功', icon: 'none' })
- that.clearPage();
- that.watchLogin();
- } else wx.showToast({ title: res.errmsg, icon: 'none' })
- }
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- const that = this;
- await that.setData({ id: options.id || '' })
- // 监听用户是否登录
- await that.watchLogin();
- },
- watchLogin: async function () {
- const that = this;
- wx.getStorage({
- key: 'user',
- success: async res => {
- let info = { skip: that.data.skip, limit: that.data.limit, lesson_id: that.data.id };
- const arr = await app.$get(`/lessonStudent`, { ...info, ...that.data.search });
- if (arr.errcode == '0') {
- let list = [...that.data.list, ...arr.data];
- for (const val of list) {
- val.zhis_pay = that.searchPay(val.is_pay)
- }
- that.setData({ list });
- that.setData({ total: arr.total })
- }
- else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
- },
- fail: async res => {
- wx.redirectTo({ url: '/pages/index/index' })
- }
- })
- },
- searchPay(e) {
- const that = this;
- let data = that.data.is_payList.find((i => i.value == e))
- if (data) return data.label
- },
- // 分页
- 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 }) }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: async function () { },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|