info.js 3.1 KB

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