coachlist.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '课程信息', leftArrow: true, useBar: false },
  5. // 课程id
  6. id: '',
  7. list: [],
  8. // 类型
  9. type:'',
  10. total: 0,
  11. page: 0,
  12. skip: 0,
  13. limit: 5,
  14. statusList: [],
  15. typeList: [],
  16. },
  17. // 返回
  18. back(e) {
  19. wx.navigateBack({ delta: 1 })
  20. },
  21. // 添加
  22. toAdd() {
  23. const that = this;
  24. that.setData({ skip: 0, page: 0, list: [] })
  25. wx.navigateTo({ url: `/pages/schAdmin/course/coachadd?lesson_id=${that.data.id}` })
  26. },
  27. // 修改
  28. toEdit: function (e) {
  29. const that = this;
  30. let { item } = e.currentTarget.dataset;
  31. that.setData({ skip: 0, page: 0, list: [] })
  32. wx.navigateTo({ url: `/pages/schAdmin/course/coachadd?id=${item._id}` })
  33. },
  34. // 删除
  35. toDel: async function (e) {
  36. const that = this;
  37. const { item } = e.currentTarget.dataset;
  38. wx.showModal({
  39. title: '提示',
  40. content: '是否确认删除该条数据?',
  41. async success(res) {
  42. if (res.confirm) {
  43. const arr = await app.$delete(`/lessonCoach/${item.id}`);
  44. if (arr.errcode == '0') {
  45. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  46. that.setData({ skip: 0, page: 0, list: [] })
  47. that.watchLogin()
  48. } else {
  49. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  50. }
  51. }
  52. }
  53. })
  54. },
  55. /**
  56. * 生命周期函数--监听页面加载
  57. */
  58. onLoad: function (options) {
  59. const that = this;
  60. that.setData({ id: options.id || '' })
  61. },
  62. // 监听用户是否登录
  63. watchLogin: async function () {
  64. const that = this;
  65. wx.getStorage({
  66. key: 'user',
  67. success: async res => {
  68. let info = { skip: that.data.skip, limit: that.data.limit, lesson_id: that.data.id, shchool_id: res.data.info.id };
  69. const aee = await app.$get(`/lesson/${that.data.id}`);
  70. if (aee.errcode == '0') {
  71. that.setData({ type: aee.data.type})
  72. }
  73. const arr = await app.$get(`/lessonCoach`, { ...info });
  74. if (arr.errcode == '0') {
  75. that.setData({ list: [...that.data.list, ...arr.data] });
  76. that.setData({ total: arr.total });
  77. }
  78. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  79. },
  80. fail: async res => {
  81. wx.redirectTo({ url: '/pages/index/index' })
  82. }
  83. })
  84. },
  85. // 分页
  86. toPage: function () {
  87. const that = this;
  88. let list = that.data.list;
  89. let limit = that.data.limit;
  90. if (that.data.total > list.length) {
  91. wx.showLoading({ title: '加载中', mask: true })
  92. let page = that.data.page + 1;
  93. that.setData({ page: page })
  94. let skip = page * limit;
  95. that.setData({ skip: skip })
  96. that.watchLogin();
  97. wx.hideLoading()
  98. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  99. },
  100. /**
  101. * 生命周期函数--监听页面初次渲染完成
  102. */
  103. onReady: function () { },
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow: function () {
  108. const that = this;
  109. // 监听用户是否登录
  110. that.watchLogin();
  111. },
  112. /**
  113. * 页面上拉触底事件的处理函数
  114. */
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage: function () {
  134. }
  135. })