list.js 4.1 KB

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