lessoninfo.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. const school = await app.$get(`/school/${arr.data.school_id}`)
  49. if (school.errcode == '0') arr.data.zhSchool = school.data.name;
  50. // 课程信息
  51. that.setData({ form: arr.data })
  52. }
  53. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  54. }
  55. },
  56. fail: async res => {
  57. wx.redirectTo({ url: '/pages/index/index' })
  58. }
  59. })
  60. },
  61. /**
  62. * 生命周期函数--监听页面初次渲染完成
  63. */
  64. onReady: function () { },
  65. /**
  66. * 生命周期函数--监听页面显示
  67. */
  68. onShow: function () {},
  69. /**
  70. * 页面上拉触底事件的处理函数
  71. */
  72. /**
  73. * 生命周期函数--监听页面隐藏
  74. */
  75. onHide: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload: function () {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh: function () {
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage: function () {
  91. }
  92. })