lessoninfo.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '课程详细信息', leftArrow: true, useBar: false },
  5. id: '',
  6. form: {},
  7. user: {},
  8. //状态
  9. statusList: [],
  10. },
  11. // 跳转菜单
  12. back(e) {
  13. wx.navigateBack({ delta: 1 })
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: async function (options) {
  19. const that = this;
  20. await that.setData({ id: options.id || null })
  21. // 查询其他信息
  22. await that.searchOther();
  23. // 监听用户是否登录
  24. await that.watchLogin();
  25. },
  26. searchOther: async function () {
  27. const that = this;
  28. let arr;
  29. // 状态
  30. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  31. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  32. },
  33. // 监听用户是否登录
  34. watchLogin: async function () {
  35. const that = this;
  36. let statusList = that.data.statusList;
  37. wx.getStorage({
  38. key: 'user',
  39. success: async res => {
  40. that.setData({ user: res.data })
  41. if (that.data.id) {
  42. const arr = await app.$get(`/lesson/${that.data.id}`);
  43. if (arr.errcode == '0') {
  44. // 课程状态
  45. let status = statusList.find(i => i.value == arr.data.status)
  46. if (status) arr.data.zhStatus = status.label;
  47. // 课程信息
  48. that.setData({ form: arr.data })
  49. }
  50. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  51. }
  52. },
  53. fail: async res => {
  54. wx.redirectTo({ url: '/pages/index/index' })
  55. }
  56. })
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady: function () { },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow: function () {},
  66. /**
  67. * 页面上拉触底事件的处理函数
  68. */
  69. /**
  70. * 生命周期函数--监听页面隐藏
  71. */
  72. onHide: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面卸载
  76. */
  77. onUnload: function () {
  78. },
  79. /**
  80. * 页面相关事件处理函数--监听用户下拉动作
  81. */
  82. onPullDownRefresh: function () {
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {
  88. }
  89. })