list.js 4.7 KB

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