list.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/soneprivate/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/soneprivate/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(`/lessonPrivate/${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. toPage: function () {
  52. const that = this;
  53. let list = that.data.list;
  54. let limit = that.data.limit;
  55. if (that.data.total > list.length) {
  56. wx.showLoading({ title: '加载中', mask: true })
  57. let page = that.data.page + 1;
  58. that.setData({ page: page })
  59. let skip = page * limit;
  60. that.setData({ skip: skip })
  61. that.watchLogin();
  62. wx.hideLoading()
  63. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  64. },
  65. /**
  66. * 生命周期函数--监听页面加载
  67. */
  68. onLoad: function (options) { },
  69. // 监听用户是否登录
  70. watchLogin: async function () {
  71. const that = this;
  72. wx.getStorage({
  73. key: 'user',
  74. success: async res => {
  75. const aee = await app.$get(`/dict`, { code: "lesson_status" });
  76. if (aee.errcode == '0' && aee.total > 0) that.setData({ statusList: aee.data[0].list });
  77. let info = { skip: that.data.skip, limit: that.data.limit, school_id: res.data.info.id };
  78. const arr = await app.$get(`/lessonPrivate`, { ...info });
  79. if (arr.errcode == '0') {
  80. for (const val of arr.data) {
  81. let level = that.data.statusList.find(i => i.value == val.status)
  82. if (level) val.zhstatus = level.label;
  83. }
  84. that.setData({ list: [...that.data.list, ...arr.data] });
  85. that.setData({ total: arr.total });
  86. }
  87. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  88. },
  89. fail: async res => {
  90. wx.redirectTo({ url: '/pages/index/index' })
  91. }
  92. })
  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. })