statuslist.js 3.9 KB

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