|
@@ -1,66 +1,179 @@
|
|
|
-// pages/schAdmin/coach/list.js
|
|
|
-Page({
|
|
|
+const app = getApp()
|
|
|
+import QRCode from '../../../utils/weapp-qrcode.js';
|
|
|
|
|
|
- /**
|
|
|
- * 页面的初始数据
|
|
|
- */
|
|
|
+Page({
|
|
|
data: {
|
|
|
-
|
|
|
+ frameStyle: { useTop: true, name: '学员信息', leftArrow: true, useBar: false },
|
|
|
+ list: [],
|
|
|
+ total: 0,
|
|
|
+ page: 0,
|
|
|
+ skip: 0,
|
|
|
+ limit: 5,
|
|
|
+ // 等级列表
|
|
|
+ levelList: [],
|
|
|
+ // dialog弹框
|
|
|
+ dialog: { title: '账号绑定', show: false, type: '1' },
|
|
|
+ form: {},
|
|
|
+ },
|
|
|
+ // 返回
|
|
|
+ back: function () {
|
|
|
+ wx.navigateBack({ delta: 1 })
|
|
|
+ },
|
|
|
+ // 添加
|
|
|
+ toAdd() {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ skip: 0, page: 0, list: [] })
|
|
|
+ wx.navigateTo({ url: '/pages/schAdmin/student/add' })
|
|
|
+ },
|
|
|
+ // 修改
|
|
|
+ toEdit: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let { item } = e.currentTarget.dataset;
|
|
|
+ that.setData({ skip: 0, page: 0, list: [] })
|
|
|
+ wx.navigateTo({ url: `/pages/schAdmin/student/add?id=${item.student_id}` })
|
|
|
+ },
|
|
|
+ // 删除
|
|
|
+ toDel: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const { item } = e.currentTarget.dataset;
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '是否确认删除该条数据?',
|
|
|
+ async success(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ const arr = await app.$delete(`/rss/${item.id}`);
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
|
|
|
+ that.setData({ skip: 0, page: 0, list: [] })
|
|
|
+ that.watchLogin()
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 绑定账号
|
|
|
+ toBind: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let { item } = e.currentTarget.dataset;
|
|
|
+ const arr = await app.$get(`/student/${item.student_id}`);
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ that.setData({ form: arr.data })
|
|
|
+ // 生成二维码
|
|
|
+ that.makeQRCode();
|
|
|
+ that.setData({ dialog: { title: '账号绑定', show: true, type: '1' } })
|
|
|
+ } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
|
|
|
+ },
|
|
|
+ makeQRCode(template = 0) {
|
|
|
+ const that = this;
|
|
|
+ const url = `${app.globalData.publicUrl}/courtappbind?id=${that.data.form.id}&type='2'`;
|
|
|
+ var qrcode = new QRCode(`myQrcode`, {
|
|
|
+ text: url,
|
|
|
+ width: 110,
|
|
|
+ height: 110,
|
|
|
+ padding: 3,
|
|
|
+ colorDark: "#000000",
|
|
|
+ colorLight: "#ffffff",
|
|
|
+ correctLevel: QRCode.CorrectLevel.L,
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
+ // 关闭弹框
|
|
|
+ toClose: function () {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ form: {} })
|
|
|
+ that.setData({ dialog: { title: '账号绑定', show: false, type: '1' } })
|
|
|
+ },
|
|
|
+ // 分页
|
|
|
+ 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 }) }
|
|
|
+ },
|
|
|
+ // 返回
|
|
|
+ back(e) {
|
|
|
+ wx.navigateBack({ delta: 1 })
|
|
|
+ },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad(options) {
|
|
|
-
|
|
|
+ onLoad: function (options) { },
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin: async function () {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'user',
|
|
|
+ success: async res => {
|
|
|
+ // 学员等级
|
|
|
+ let aee = await app.$get(`/dict`, { code: 'student_grade' });
|
|
|
+ if (aee.errcode == '0' && aee.total > 0) that.setData({ levelList: aee.data[0].list })
|
|
|
+ let info = { skip: that.data.skip, limit: that.data.limit, school_id: res.data.info.id };
|
|
|
+ const arr = await app.$get(`/rss`, { ...info });
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ for (const val of arr.data) {
|
|
|
+ let level = that.data.levelList.find(i => i.value == val.student_id_level)
|
|
|
+ if (level) val.zhLevel = level.label;
|
|
|
+ }
|
|
|
+ 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' })
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
- onReady() {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
+ onReady: function () { },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
- onShow() {
|
|
|
-
|
|
|
+ onShow: function () {
|
|
|
+ const that = this;
|
|
|
+ // 监听用户是否登录
|
|
|
+ that.watchLogin();
|
|
|
},
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
- onHide() {
|
|
|
+ onHide: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
- onUnload() {
|
|
|
+ onUnload: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
- onPullDownRefresh() {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 页面上拉触底事件的处理函数
|
|
|
- */
|
|
|
- onReachBottom() {
|
|
|
+ onPullDownRefresh: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
- onShareAppMessage() {
|
|
|
+ onShareAppMessage: function () {
|
|
|
|
|
|
}
|
|
|
})
|