123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- frameStyle: { useTop: true, name: '账号管理', leftArrow: true, useBar: false },
- list: [],
- total: 0,
- page: 0,
- skip: 0,
- limit: 5,
- typeList: [
- { label: '超级管理员', value: '-1' },
- { label: '普通用户', value: '0' },
- { label: '管理员', value: '1' },
- { label: '教练', value: '2' },
- { label: '学员', value: '3' },
- { label: '游客', value: '10' },
- ]
- },
- // 返回
- back: function () {
- wx.navigateBack({ delta: 1 })
- },
- // 信息添加
- toAdd: function () {
- that.setData({ skip: 0, page: 0, list: [] })
- wx.navigateTo({ url: `/pages/suser/add` })
- },
- // 信息维护
- toEdit: function (e) {
- const that = this;
- const { item } = e.currentTarget.dataset;
- that.setData({ skip: 0, page: 0, list: [] })
- wx.navigateTo({ url: `/pages/suser/add?id=${item.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(`/user/${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 })
- }
- }
- }
- })
- },
- // 分页
- 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) {
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- wx.getStorage({
- key: 'user',
- success: async res => {
- let info = { skip: that.data.skip, limit: that.data.limit };
- const arr = await app.$get(`/user`, { ...info });
- if (arr.errcode == '0') {
- for (const val of arr.data) { val.zHtype = this.searchType(val.type) }
- 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' })
- }
- })
- },
- // 用户类型
- searchType: function (e) {
- const that = this;
- let data = that.data.typeList.find(i => i.value == e);
- if (data) return data.label;
- else return '暂无';
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- const that = this;
- // 监听用户是否登录
- that.watchLogin();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|