123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- frameStyle: { useTop: true, name: '课程管理', leftArrow: true, useBar: false },
- // 查询
- search: {},
- list: [],
- total: 0,
- skip: 0,
- limit: 10,
- page: 0,
- // 状态列表
- statusList: [],
- },
- // 跳转菜单
- back(e) {
- wx.navigateBack({ delta: 1 })
- },
- // 查询
- toInput(e) {
- const that = this;
- let value = e.detail.value;
- if (value) that.setData({ 'search.title': value })
- else that.setData({ search: {} })
- that.clearPage(); that.watchLogin();
- },
- // 清空列表
- clearPage() {
- const that = this;
- that.setData({ list: [], skip: 0, limit: 10, page: 0 })
- },
- // 添加
- toAdd() {
- const that = this;
- that.clearPage();
- wx.navigateTo({
- url: `/pagesSchool/schAdmin/course/add`,
- })
- },
- // 修改
- toEdit: function (e) {
- const that = this;
- let { item } = e.currentTarget.dataset;
- that.clearPage();
- wx.navigateTo({ url: `/pagesSchool/schAdmin/course/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(`/lesson/${item.id}`);
- if (arr.errcode == '0') {
- wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
- that.clearPage();
- that.watchLogin()
- } else {
- wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
- }
- }
- }
- })
- },
- // 教练管理
- toCoach(e) {
- const that = this;
- let { item } = e.currentTarget.dataset;
- that.clearPage();
- wx.navigateTo({ url: `/pagesSchool/schAdmin/course/coachlist?id=${item.id}` })
- },
- // 学员管理
- toManage(e) {
- const that = this;
- let { item } = e.currentTarget.dataset;
- that.clearPage();
- wx.navigateTo({
- url: `/pagesSchool/common/lessonstudent?id=${item._id}`,
- })
- },
- // 临时上课学员
- toTem(e) {
- const that = this;
- let { item } = e.currentTarget.dataset;
- that.clearPage();
- wx.navigateTo({
- url: `/pagesSchool/coaAdmin/course/tpStudent?lesson_id=${item.id}`,
- })
- },
- // 详细信息
- toView(e) {
- const that = this;
- let { item } = e.currentTarget.dataset;
- that.clearPage();
- wx.navigateTo({ url: `/pagesSchool/common/lessoninfo?id=${item.id}` })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: async function () {
- const that = this;
- // 查询其他信息
- await that.searchOther();
- // 监听用户是否登录
- 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 };
- const arr = await app.$get(`/lesson`, { ...info, ...that.data.search });
- if (arr.errcode == '0') {
- let list = [...that.data.list, ...arr.data];
- for (const val of list) { val.zhStatus = that.searchStatus(val.status) }
- 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' })
- }
- })
- },
- searchStatus(e) {
- const that = this;
- let data = that.data.statusList.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 }) }
- },
- // 查询其他信息
- async searchOther() {
- const that = this;
- let res;
- // 状态
- res = await app.$get(`/dict`, { code: "lesson_status" });
- if (res.errcode == '0' && res.total > 0) that.setData({ statusList: res.data[0].list });
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- const that = this;
- that.clearPage();
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|