|
@@ -6,12 +6,11 @@ Page({
|
|
*/
|
|
*/
|
|
data: {
|
|
data: {
|
|
frameStyle: { useTop: true, name: '教练信息', leftArrow: true, useBar: false },
|
|
frameStyle: { useTop: true, name: '教练信息', leftArrow: true, useBar: false },
|
|
- list: [
|
|
|
|
- { _id: '001', icon: [{ url: '/image/club.png' }], name: '教练1', gender: '女', age: '33', phone: '12345678901', skill: '羽毛球', card: '220220222202022222' },
|
|
|
|
- { _id: '002', icon: [{ url: '/image/club.png' }], name: '教练1', gender: '女', age: '33', phone: '12345678901', skill: '羽毛球', card: '220220222202022222' },
|
|
|
|
- { _id: '001', icon: [{ url: '/image/club.png' }], name: '教练1', gender: '女', age: '33', phone: '12345678901', skill: '羽毛球', card: '220220222202022222' },
|
|
|
|
- { _id: '002', icon: [{ url: '/image/club.png' }], name: '教练1', gender: '女', age: '33', phone: '12345678901', skill: '羽毛球', card: '220220222202022222' },
|
|
|
|
- ],
|
|
|
|
|
|
+ list: [],
|
|
|
|
+ total: 0,
|
|
|
|
+ page: 0,
|
|
|
|
+ skip: 0,
|
|
|
|
+ limit: 5,
|
|
},
|
|
},
|
|
// 返回
|
|
// 返回
|
|
back: function () {
|
|
back: function () {
|
|
@@ -19,10 +18,14 @@ Page({
|
|
},
|
|
},
|
|
// 添加
|
|
// 添加
|
|
toAdd() {
|
|
toAdd() {
|
|
|
|
+ const that = this;
|
|
|
|
+ that.setData({ skip: 0, page: 0, list: [] })
|
|
wx.navigateTo({ url: '/pages/scoach/add' })
|
|
wx.navigateTo({ url: '/pages/scoach/add' })
|
|
},
|
|
},
|
|
// 修改
|
|
// 修改
|
|
toEdit: function (e) {
|
|
toEdit: function (e) {
|
|
|
|
+ const that = this;
|
|
|
|
+ that.setData({ skip: 0, page: 0, list: [] })
|
|
let { id } = e.currentTarget.dataset;
|
|
let { id } = e.currentTarget.dataset;
|
|
wx.navigateTo({ url: `/pages/scoach/add?id=${id}` })
|
|
wx.navigateTo({ url: `/pages/scoach/add?id=${id}` })
|
|
},
|
|
},
|
|
@@ -34,10 +37,33 @@ Page({
|
|
title: '提示',
|
|
title: '提示',
|
|
content: '是否确认删除该条数据?',
|
|
content: '是否确认删除该条数据?',
|
|
async success(res) {
|
|
async success(res) {
|
|
- console.log('删除');
|
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
+ const arr = await app.$delete(`/coach/${id}`);
|
|
|
|
+ if (arr.errcode == '0') {
|
|
|
|
+ wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
|
|
|
|
+ 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 }) }
|
|
|
|
+ },
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
@@ -56,7 +82,28 @@ Page({
|
|
* 生命周期函数--监听页面显示
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
*/
|
|
onShow: function () {
|
|
onShow: function () {
|
|
-
|
|
|
|
|
|
+ const that = this;
|
|
|
|
+ // 监听用户是否登录
|
|
|
|
+ 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 };
|
|
|
|
+ const arr = await app.$get(`/coach`, { ...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' })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|