list.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '课程管理', leftArrow: true, useBar: false },
  8. // 查询
  9. search: {},
  10. list: [],
  11. total: 0,
  12. skip: 0,
  13. limit: 10,
  14. page: 0,
  15. // 状态列表
  16. statusList: [],
  17. },
  18. // 跳转菜单
  19. back(e) {
  20. wx.navigateBack({ delta: 1 })
  21. },
  22. // 查询
  23. toInput(e) {
  24. const that = this;
  25. let value = e.detail.value;
  26. if (value) that.setData({ 'search.title': value })
  27. else that.setData({ search: {} })
  28. that.clearPage(); that.watchLogin();
  29. },
  30. // 清空列表
  31. clearPage() {
  32. const that = this;
  33. that.setData({ list: [], skip: 0, limit: 10, page: 0 })
  34. },
  35. // 添加
  36. toAdd() {
  37. const that = this;
  38. that.clearPage();
  39. wx.navigateTo({
  40. url: `/pagesSchool/schAdmin/course/add`,
  41. })
  42. },
  43. // 修改
  44. toEdit: function (e) {
  45. const that = this;
  46. let { item } = e.currentTarget.dataset;
  47. that.clearPage();
  48. wx.navigateTo({ url: `/pagesSchool/schAdmin/course/add?id=${item.id}` })
  49. },
  50. // 删除
  51. toDel: async function (e) {
  52. const that = this;
  53. const { item } = e.currentTarget.dataset;
  54. wx.showModal({
  55. title: '提示',
  56. content: '是否确认删除该条数据?',
  57. async success(res) {
  58. if (res.confirm) {
  59. const arr = await app.$delete(`/lesson/${item.id}`);
  60. if (arr.errcode == '0') {
  61. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  62. that.clearPage();
  63. that.watchLogin()
  64. } else {
  65. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  66. }
  67. }
  68. }
  69. })
  70. },
  71. // 教练管理
  72. toCoach(e) {
  73. const that = this;
  74. let { item } = e.currentTarget.dataset;
  75. that.clearPage();
  76. wx.navigateTo({ url: `/pagesSchool/schAdmin/course/coachlist?id=${item.id}` })
  77. },
  78. // 学员管理
  79. toManage(e) {
  80. const that = this;
  81. let { item } = e.currentTarget.dataset;
  82. that.clearPage();
  83. wx.navigateTo({
  84. url: `/pagesSchool/common/lessonstudent?id=${item._id}`,
  85. })
  86. },
  87. // 临时上课学员
  88. toTem(e) {
  89. const that = this;
  90. let { item } = e.currentTarget.dataset;
  91. that.clearPage();
  92. wx.navigateTo({
  93. url: `/pagesSchool/coaAdmin/course/tpStudent?lesson_id=${item.id}`,
  94. })
  95. },
  96. // 详细信息
  97. toView(e) {
  98. const that = this;
  99. let { item } = e.currentTarget.dataset;
  100. that.clearPage();
  101. wx.navigateTo({ url: `/pagesSchool/common/lessoninfo?id=${item.id}` })
  102. },
  103. /**
  104. * 生命周期函数--监听页面加载
  105. */
  106. onLoad: function (options) {
  107. },
  108. /**
  109. * 生命周期函数--监听页面初次渲染完成
  110. */
  111. onReady: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面显示
  115. */
  116. onShow: async function () {
  117. const that = this;
  118. // 查询其他信息
  119. await that.searchOther();
  120. // 监听用户是否登录
  121. await that.watchLogin();
  122. },
  123. watchLogin: async function () {
  124. const that = this;
  125. wx.getStorage({
  126. key: 'user',
  127. success: async res => {
  128. let info = { skip: that.data.skip, limit: that.data.limit };
  129. const arr = await app.$get(`/lesson`, { ...info, ...that.data.search });
  130. if (arr.errcode == '0') {
  131. let list = [...that.data.list, ...arr.data];
  132. for (const val of list) { val.zhStatus = that.searchStatus(val.status) }
  133. that.setData({ list });
  134. that.setData({ total: arr.total })
  135. }
  136. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
  137. },
  138. fail: async res => {
  139. wx.redirectTo({ url: '/pages/index/index' })
  140. }
  141. })
  142. },
  143. searchStatus(e) {
  144. const that = this;
  145. let data = that.data.statusList.find(i => i.value == e);
  146. if (data) return data.label
  147. },
  148. // 分页
  149. toPage: function () {
  150. const that = this;
  151. let list = that.data.list;
  152. let limit = that.data.limit;
  153. if (that.data.total > list.length) {
  154. wx.showLoading({ title: '加载中', mask: true })
  155. let page = that.data.page + 1;
  156. that.setData({ page: page })
  157. let skip = page * limit;
  158. that.setData({ skip: skip })
  159. that.watchLogin();
  160. wx.hideLoading()
  161. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  162. },
  163. // 查询其他信息
  164. async searchOther() {
  165. const that = this;
  166. let res;
  167. // 状态
  168. res = await app.$get(`/dict`, { code: "lesson_status" });
  169. if (res.errcode == '0' && res.total > 0) that.setData({ statusList: res.data[0].list });
  170. },
  171. /**
  172. * 生命周期函数--监听页面隐藏
  173. */
  174. onHide: function () {
  175. const that = this;
  176. that.clearPage();
  177. },
  178. /**
  179. * 生命周期函数--监听页面卸载
  180. */
  181. onUnload: function () {
  182. },
  183. /**
  184. * 页面相关事件处理函数--监听用户下拉动作
  185. */
  186. onPullDownRefresh: function () {
  187. },
  188. /**
  189. * 页面上拉触底事件的处理函数
  190. */
  191. onReachBottom: function () {
  192. },
  193. /**
  194. * 用户点击右上角分享
  195. */
  196. onShareAppMessage: function () {
  197. }
  198. })